As much as I like .net magazine, I was recently outraged by their “Texturizing Web Type” article. It features a way to apply a texture to text with -webkit-mask-image, presenting it as an experimental CSS property and misleading readers. There are even -moz-, -o- and -ms- prefixes for something that is not present in any specification, and is therefore unlikely to ever be supported by any non-WebKit browser, which further contributes to the misdirection. A while back, I wrote about how detrimental to our work and industry such proprietary features can be.
A common response to such complaints is that they are merely philosophical and who cares if the feature works right now and degrades gracefully. This argument could be valid for some cases, when the style is just a minor, gracefully degrading enhancement and no standards compliant alternative is present (for example, I’ve used ::-webkit-scrollbar styles myself). However, this is not the case here. We have had a standards compliant alternative for this for the past 11 years and it’s called SVG. It can also do much more than masking, if you give it a chance.
Here’s an example of texturized text with SVG:
Edit: Thanks to @devongovett’s improvements, the code is now simpler & shorter.
Yes, the syntax might be more unwieldy but it works in a much wider range of browsers: Chrome, Safari, Firefox, IE9, Opera. Also, it’s trivial to make a script that generates the SVG markup from headings and applies the correct measurements for each one. When WebKit fixes this bug, we can even move the pattern to a separate SVG file and reference it from there.
In case you’re wondering about semantics, the <svg> element is considered “flow content” and is therefore allowed in heading elements. Also, even if search engines don’t understand inline SVG, they will just ignore the tags and still see the content inside the <text> element. Based on that, you could even make it degrade gracefully in IE8, as long as you include the HTML5 fix for the <svg> element. Then the CSS rules for the typography will still apply. You’ll just need to conditionally hide the <image>, since IE8 displays a broken image there (a little known fact is that, in HTML, <image> is basically equivalent to <img>, so IE8 treats it as such) .
Credits to David Storey’s original example that inspired this.
Pingback: Bruce Lawson’s personal site : Reading List
Pingback: Маскирование текста по стандарту
Pingback: Tweet-Parade (no.20 May 2012) | gonzoblog.nl
Pingback: Some links for light reading (25/5/12) | Max Design
Pingback: Texturizzazione di un font con css | Laboratorio CSS
Pingback: Tweet Heat - The hottest Tweets of the Month [May 2012] | Inspired Magazine
Pingback: Tweet Heat – The hottest Tweets of the Month [May 2012] | Web Dezining
Pingback: Text masking — The standards way | Lea Verou » Web Design
Pingback: Powerful New CSS- and JavaScript Techniques | t1u
Pingback: Powerful New CSS- and JavaScript Techniques@smashing | seo博客大全
Pingback: Powerful New CSS- and JavaScript Techniques | Buypappa blog
Pingback: Powerful New CSS- and JavaScript Techniques | MyOfflineTheme.com Skyrocket Your Offline Business Just Now
Pingback: Powerful New CSS- and JavaScript Techniques | Web Design Kingston
Pingback: Powerful New CSS- and JavaScript Techniques | DigitalMofo
Pingback: Steve deGuzmanPowerful New CSS- and JavaScript Techniques » Steve deGuzman
Pingback: Powerful New CSS- and JavaScript Techniques « Web Development Website
Pingback: Powerful New CSS- and JavaScript Techniques » E BLADE
Pingback: Powerful New CSSand JavaScript Techniques - rehavaPress
Pingback: Rutweb Technology : Powerful New CSS- and JavaScript Techniques
Pingback: Powerful New CSS- and JavaScript Techniques | TuTsRUS - All Adobe Tutorials - Photoshop | Illustrator | Encore | Premeire | After Effects
Pingback: Powerful New CSS- and JavaScript Techniques — Заметки по дизайну
Pingback: Powerful New CSS- and JavaScript-Techniques (2012 Edition) | Smashing Coding
Pingback: Powerful New CSS- and JavaScript Techniques | Sedation Dentist Wayne
Pingback: Type News: Embooked | Uber Patrol
Pingback: Powerful New CSS – and JavaScript Techniques
Pingback: Powerful New CSS- and JavaScript Techniques
Pingback: Bergstrom Productions Powerful New CSS- and JavaScript Techniques | Bergstrom Productions
Pingback: CSS3 text with textured drop shadow effect - Tristan Denyer
Pingback: Powerful New CSS- and JavaScript Techniques « OhMyDev
Pingback: Nuevas técnicas CSS3, HTML5 y JavaScript. – Sweety Web Designs
Pingback: Powerful New CSS- and JavaScript-Techniques (2012 Edition)
Pingback: Creating Image Galleries with Clipped Images Using CSS Pointer Events and SVG | Flippin' Awesome
Pingback: Küçük bir ipucu #4 « Ayhan Kuru & Blog