Puttin' the eek back in geek

Super semantic multicolor font icons in pure CSS

February 6, 2014

Font icons rule. They’re easy to implement, well supported, and infinitely scalable without loss of quality. Even ol’ IE supports them! But there’s a downside: a font icon — like the letter A in a normal font — can only be one color.

Just one single color. Boring!

But what if I told you we can have colorful font icons like these?

The lion asked the whale “Where did owl and parrot fly off to?”

These four critters are drawn by the talented Eva Galesloot and are recreated with good old font icons and some straightforward CSS. 1

The basic technique is simple: we overlap multiple glyphs and give each “layer” a different color. You can have two-color icons this way in pure CSS (using :before and :after), or more colors if you don’t mind creating extra elements through unsemantic HTML or by using JavaScript. It’s been done before.

But two colors ain’t enough, and polluted HTML just rustles my jimmies. So let’s try to come up with a cleaner method.

Four-color icons with basic CSS and webfonts

We’re going to use four different colors by transferring all the work to CSS and the font file. All we need on the HTML side is a span with the icon’s character set to the data-icon attribute:

<span data-icon="p"></span>

After we’re done with the CSS and the font file, this turns into a colorful parrot:

Easy peasy! Let’s take a look at how this is done.

Step one: prepping the font file

The first step is to create the four glyphs we’re going to use in the font. For this we need an SVG for each color in the original design:

pppp

We need to assign these glyphs to four different characters in our font — for instance A, B, C and D. But this would result in an unwieldy data attribute, especially since we need to weasel a newline in there (the \a bit — more on that later):

<span data-icon="AB\a CD"></span>

So to keep the HTML tidy, we map each glyph to the same character in four different font files. This allows us to assign each one of them to a different font-weight. The parrot, for instance, is mapped to the letter p. The first font holds the first shape (the parrot’s body) and will be assigned to font-weight: 100. The next two fonts will be assigned to font-weight: 200 and font-weight: 300, and the last one to font-weight: 400.

The end result is four different font files, each file containing one layer for every icon. Loading four external files isn’t ideal, so I chose to base64 ‘em and combine them in one stylesheet. 2

I turned these into fonts by using Font Custom, but you could use a tool like Icomoon as well.3

Step two: putting CSS to work

We’ve created the font files, now it’s time to make those critters show up on our page and give them their appropriate position and color.

Remember, we’re working with just a single element. The drawback of not using extra HTML elements is that we can’t use selectors like :nth-child() to address individual characters with CSS. But there are a couple of CSS pseudo selectors we can use if we arrange our characters like this:

pp
pp

This allows us to use:

  1. span:first-letter { weight: 100; color: greenyellow; }
  2. span:first-line { weight: 200; color: darkgreen; }
  3. span { weight: 300; color: orange; }
  4. span:after { weight: 400; color: orangered; }

With all four layers properly styled, the last step is to overlap them. Since we’re not using real elements, we can’t use absolute positioning, so we summon the powers of negative letter-spacing and zero line-height to get the job done. And there we have it: four differently styled glyphs on top of each other!

This is the full CSS for the Skwirrol icon set:

[data-icon] {
  font-family: "Skwirrol-Icons"; /* See @font-face declarations at bottom */
  speak: none;
  font-style: normal;
  font-variant: normal;
  text-transform: none;
  text-align: left;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  display: inline-block; /* So we can set its width */
  white-space: pre;      /* Turn newlines into actual newlines */
  letter-spacing: -1em;  /* Overlap icons horizontally */
  line-height: 0;        /* Overlap icons vertically */
  padding: 0.5em 0;      /* Compensate for zero line height */
  width: 1em;            /* Compensate for negative letter spacing */

  font-weight: 300;      /* Weight for third layer */
}
[data-icon]:before {
  /* Insert the three first layers */
  content: attr(data-icon)
           attr(data-icon) "\a"
           attr(data-icon);
}
[data-icon]:first-letter {
  font-weight: 100;      /* Weight for the first layer */
}
[data-icon]:first-line {
  font-weight: 200;      /* Weight for the second layer */
}
[data-icon]:after {
  /* Insert the last layer */
  content: attr(data-icon);
  font-weight: 400;      /* Weight for the fourth layer */
}

/* Colors for Skwirrol's lion */
[data-icon="l"] {
  color: #ffef9f;
}
[data-icon="l"]:first-line {
  color: #ffde3f;
}
[data-icon="l"]:first-letter {
  color: #de6d36;
}
[data-icon="l"]:after {
  color: #000;
}

/* Colors for Skwirrol's owl */
[data-icon="o"] {
  color: #7a6155;
}
[data-icon="o"]:first-line {
  color: #3c2313;
}
[data-icon="o"]:first-letter {
  color: #593a2a;
}
[data-icon="o"]:after {
  color: #fcb040;
}

/* Colors for Skwirrol's whale */
[data-icon="v"] {
  color: #41a1c1;
}
[data-icon="v"]:first-line {
  color: #c5deeb;
}
[data-icon="v"]:first-letter {
  color: #4ebfe5;
}
[data-icon="v"]:after {
  color: #c1417e;
}

/* Colors for Skwirrol's parrot */
[data-icon="p"] {
  color: #fcb040;
}
[data-icon="p"]:first-line {
  color: #4d7125;
}
[data-icon="p"]:first-letter {
  color: #8ebf48;
}
[data-icon="p"]:after {
  color: #f7953d;
}

@font-face {
  /* Skwirrol Solid */
  font-family: 'Skwirrol-Icons';
  src:url(data:application/x-font-woff;base64,d09GRgABAAAAABH8AA8AAAAAJmwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABWAAAABoAAAAcZ5yvik9TLzIAAAF0AAAATAAAAGBQpmAMY21hcAAAAcAAAABbAAABWuggHEBjdnQgAAAMQAAAACEAAAAwA+AHAWZwZ20AAAxkAAAE/QAACZYz+6KVZ2FzcAAADDgAAAAIAAAACAAAABBnbHlmAAACHAAAB+0AABWeKojYCmhlYWQAAAoMAAAALgAAADb/MoDVaGhlYQAACjwAAAAcAAAAJAPwAcVobXR4AAAKWAAAABUAAAAYBiIAEWxvY2EAAApwAAAAEgAAABIUPROQbWF4cAAACoQAAAAgAAAAIAHpDsZuYW1lAAAKpAAAAWcAAAKse4casXBvc3QAAAwMAAAALAAAADqgCE5tcHJlcAAAEWQAAACVAAAAlbLDxnB42mNgYGBkAIKTnfmGIPo85wIdGA0AO8kFPAAAeNpjYGFiYPzCwMrAwOjDmMbAwOAOpb8ySDK0MDAwMbBxMsAAowADAgSkuaYwHGDI+cjAeOD/AQY9xgMMDiA1YIXLwEoUGBgBKoYMWHjaY2BgYGaAYBkGRgYQCAHyGMF8FgYLIM3FwMHABIQ5DAUMZR8Z/v8HiuUw5EPY/6f/n/p/Aj87VC8UMLIxwAUYmYAEEwMqYGSgKgA6n4UVzGJjGCwAADIfDlsAeNrVWAtsHEcZ/v6Z3Znb3Xuts3tOLrbT3sV3qW2o73xnNzTE5zxoSELebpISkkaYo2opBNo0LpVCiUmhoSmgilblJQQCQUFVUSVeQigIIUCoIKQKIYSKAFUVFapQQUKl4PDP7p2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lyFTbH2QNrVQrg60rp9uqMbQhJd4WbV9Jymna3otfFVRRea8Ka8WLSRiip2dxTWjL1p1UShEaNeUcD++qQpQeaylG/WN0fiHqe8ApZxe0PhzjTtQdVFvDToefbzaytmBiaErbOwFKytKVMRZlnsU5Rle31vHGLeHpWnJqEZ9ik/korJTXRvnoFtK8apdlFo2qVEd3aZ/FvmbTL7KDhtVxDuKGauGuHrbVqCLlM+WrQ3toZ9VtH+lhxUcdNKqqZhtdH3mMxmVN+Y8BWYwrf8No1WD6HdxSraSRr7rLaO6bk+Xe2eWtN9lv5dwy0vDfarRp5IqfwTG/LQL8OwfFbsgqqLcnDTEuIHsBw6Ua6NyhuTsYRFxn/6Nzuv+tWRgkZ7WlMZtnPlwtGUVylymPs2wxy5oepTmKdpLYp0hsZTgxuKkxHEsN2cCA3PuH9fu4B9zlJfGBt40EEA9Ymzaqpzq4u8fVCA37Sh4ARubEce4A7AC4BG1z4tqVDoBd6ZJzF+AzcggekkPwiByCXXJuAXxODsEX5BB8SQ7BV+TcBuiRQ7BHDsFjcgj2yWkBHJBD8IQcgq/JIfiGnCZATA5BQg7BU3IInhnZnJT5WypyA+g7i24CfW+7BsoWlB+MXJ2wUyqW3beI7EOLSD0ycm1CPaZiqQOLSH1uEak/Grk+of5ExVJ/tojUXywi9YXxZWYgxdXeS97RwZ+PsKyJAAAAS7gAyFJYsQEBjlm5CAAIAGMgsAEjRCCwAyNwsBNFICBLuAAOUUuwBlNaWLA0G7AoWWBmIIpVWLACJWGwAUVjI2KwAiNEsw0NBQQrsw4QBQQrsxMVBQQrWbIEKAlFUkSzDhIGBCuxBgFEsSQBiFFYsECIWLEGA0SxJgGIUVi4BACIWLEGAURZWVlZuAH/hbAEjbEFAEQAAAA=) format('woff');
  font-weight: 100;
  font-style: normal;
}
@font-face {
  /* Skwirrol Color 1 */
  font-family: 'Skwirrol-Icons';
  src:url(data:application/x-font-woff;base64,d09GRgABAAAAAA08AA8AAAAAFaAAAAAAAAAAAAAAAAAA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A5RS7AGU1pYsDQbsChZYGYgilVYsAIlYbABRWMjYrACI0SzCwsFBCuzDA4FBCuzERMFBCtZsgQoCUVSRLMMEAYEK7EGAUSxJAGIUViwQIhYsQYDRLEmAYhRWLgEAIhYsQYBRFlZWVm4Af+FsASNsQUARAAAAA==) format('woff');
  font-weight: 200;
  font-style: normal;
}
@font-face {
  /* Skwirrol Color 2 */
  font-family: 'Skwirrol-Icons';
  src:url(data:application/x-font-woff;base64,d09GRgABAAAAAAaUAAsAAAAACGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABPUy8yAAABeAAAAEwAAABgUKZftWNtYXAAAAHUAAAAQgAAAFQBAfIPZ2FzcAAABowAAAAIAAAACAAAABBnbHlmAAACKAAAAuwAAAO8YmX5gGhlYWQAAAEIAAAAMwAAADb/PsiNaGhlYQAAATwAAAAcAAAAJAPwAcJobXR4AAABxAAAAA4AAAAOAm4BmWxvY2EAAAIYAAAADgAAAA4FPAR8bWF4cAAAAVgAAAAgAAAAIAHICp1uYW1lAAAFFAAAAUwAAAJY49ICGHBvc3QAAAZgAAAAKwAAADafD09keNpjYGRgYADi7aIKT+P5bb4ycDIxgMB5zgWiYFr8+W8Ghv8HmBgYDwC5HAxgaQAcrApfAHjaY2BkYGA88P8Agx4TAwgASUYGVMAIAFCRArYAAQAAAAYAvQATAAAAAAACADoASABsAAABCAmWAAAAAHjaY2BhYmD8wsDKwMDow5jGwMDgDqW/MkgytDAwMDGwcTLAAKMAAwIEpLmmMBxgyPnIwHjg/wEGPcYDDA4gNWCF/mAlCgyMACd3DAECAAAAADABmQA+AAAAAAAAeNpjYGBgYmBgYAZiESDJCKZZGByANA8DB1COhUGBIYehgKHsI8P//0BREC8fwvv/9P+U/5P+9/KzgPXBAQDfaA/5AAAAAAECAZYBpAHIAdYB3gAAeNotUs+rHEUQruqZ7XaHebPbbvc0L7s77s7sm1kTedvT84uFIPHgKUFFQiI8kDyQxAeJhOQWBM8evORkgkIu8SDowYN48PDOnvTkRfBP8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m6xOfRQcd84XepiaLcs/z+FGblM+L3MyLcqt4ICTvp8bswtEoIZrUVFSJyJUZ1GCzr0yRLVWs99nvWMh/9jQEk6E/DKQ/Xqmy0kXOpfSFlBJTlFCIYOiOwbHGie4ZkQO0JQvqW6TkyIjm8OzhOBI3xDnmKIgb20vyKmIBBCT1vk0a7BBiRCdx3uTsFahoEkQV8cHZscGeNoamDEv7d5pI9u9rIdVf+WYTYIIhfKqA3D7GWFG6JJe2GU605sJ2+Q2Tk2V3eNpjYGIAg/8HGCSBFCMDOmBj8GcIYghmiGRkYmBmL83LdDM0MAAAdD8FXwAAAQAB//8ADw==) format('woff');
  font-weight: 300;
  font-style: normal;
}
@font-face {
  /* Skwirrol Color 3 */
  font-family: 'Skwirrol-Icons';
  src:url(data:application/x-font-woff;base64,d09GRgABAAAAAAwkAA8AAAAAE5gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABWAAAABoAAAAcZ5yvcE9TLzIAAAF0AAAATAAAAGBQpl+MY21hcAAAAcAAAABbAAABWuggHEBjdnQgAAAGbAAAAB0AAAAwA+8DtWZwZ20AAAaMAAAE/wAACZYx+aKVZ2FzcAAABmQAAAAIAAAACAAAABBnbHlmAAACHAAAAhsAAALKGvcgZmhlYWQAAAQ4AAAALgAAADb/MoC7aGhlYQAABGgAAAAcAAAAJAPwAcVobXR4AAAEhAAAABgAAAAYBz8CT2xvY2EAAAScAAAAEgAAABIDNQKubWF4cAAABLAAAAAgAAAAIAD9Ce9uYW1lAAAE0AAAAWcAAAKse4casXBvc3QAAAY4AAAALAAAADqgCE5tcHJlcAAAC4wAAACVAAAAlbLDxHB42mNgYGBkAIKTnfmGIPo85wJ5GA0AO0cFIgAAeNpjYGFiYPzCwMrAwOjDmMbAwOAOpb8ySDK0MDAwMbBxMsAAowADAgSkuaYwHGDI+cjAeOD/AQY9xgMMDiA1YIVqYCUKDIwAJgYL2HjaY2BgYGaAYBkGRgYQCAHyGMF8FgYLIM3FwMHABIQ5DA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f5sEam/WETqC+PLzECKq72XvKODPwFqQqyFAEu4AMhSWLEBAY5ZuQgACABjILABI0QgsAMjcLATRSAgS7gADlFLsAZTWliwNBuwKFlgZiCKVViwAiVhsAFFYyNisAIjRLMLDQUEK7MOEAUEK7MTFQUEK1myBCgJRVJEsw4SBgQrsQYBRLEkAYhRWLBAiFixBgNEsSYBiFFYuAQAiFixBgFEWVlZWbgB/4WwBI2xBQBEAAAA) format('woff');
  font-weight: 400;
  font-style: normal;
}

Browser support, caveats and heads ups

This little trick works on all modern browsers I tested (Chrome, Firefox, IE11, Opera). I was surprised that it even works on all versions of IE upward from 8 (if you create an EOT file — for this demo I just stuck with WOFF).

Opera 12 and several mobile browsers have trouble showing these icons correctly. This seems to be caused by two main reasons: no font-face support at all, or more obscure differences in implementation of things like letter-spacing. Opera 12, for instance, doesn’t like letter-spacing: -1em (-0.99em is fine, though). A solution to this would be to create zero-width glyphs in your font, which is entirely possible and supported but outside the scope of this little hack.

Some other things to keep in mind:

Souping up the semanticism

I’ve taken a bit of a poetic license with the title of this post, and some of you have rightly pointed out an empty span isn’t all that super semantic. So, here’s a variation of the hack, which’ll work with the following HTML:

<span data-icon="p">parrot</span>

You can now inject just two p values into the :before, and use the content of the span for the third p. The rest of the word will be chopped off by a simple overflow: hidden. The end result is the same, but now the HTML is truely semantic.

You can see this variation in this Codepen:

See the Pen zuwLe by Roel N (@RoelN) on CodePen.

(Screen readers would read “ppparrotp” though, and when @font-face isn’t supported you’d have to undo this hack — otherwise visitors would see four overlapping ps instead of the parrot or the word “parrot”. Web crawlers and Lynx users will properly read your site now, though!)

Edit: This solution doesn’t work in IE11. Looks like overflow:hidden is the culprit. Anybody know what’s going on here?

And that’s that

And there you have it — a sweet little trick to get multicolor font icons. Is it a hack? Are you probably better off with SVG? Did I have a lot of fun squeezing extra colors out of a limited technology? Why yes, probably and yes!

Feel free to dig into the code on Github or Codepen! Let’s bring some color to font icons!

  1. Fun fact: when I contacted Eva Galesloot if I could use her colorful icons, she pointed me to front-end hacker Rafal Bromirski who recreated these exact same icons in pure CSS3!

  2. You can reduce the number of files to two if you also use lowercase and uppercase letters.

  3. Be sure to include a control character that represents the widest width and the highest height of all the designs combined, so each font will have the same bounding box. If they don’t, your glyphs will vary in width and height and won’t align properly. Font Custom needs some extra work because otherwise a line feed will show up as missing glyph. Drop me a message if you need help !