Icon Fonts: Showing Icons without their Associated Text

August 20, 2014 12:44pm

Say you’re using icon fonts, and you have something that looks like this:

The icons to the left of each link are created via an icon font.

That’s all good and well, but what if you don’t want to show the actual “list” and “calendar” text, though you still want it to exist in your HTML. Essentially, you want to replace the text with just the icon itself. Like so:

The text is gone, and we’re left with just the icons, which still work as links.

It’s not all that easy to do, particularly if you’re used to replacing text with background images. Here’s how you can achieve that:

Basically, we’re using text-indent to bump our block level anchor tag text out of view, and then positioning and negation of that indent on the icon itself to bring it back into view.

Now, to be absolutely clear, that doesn’t actually add any icons. I use the code provided by Icomoon, along with their app, to generate icons and display them on my sites. Here’s the full CSS and some example HTML one might use: