Pure CSS GUI icons (experimental)

An experiment that uses pseudo-elements to create 84 simple GUI icons using CSS and semantic HTML. Shared as an exercise in creative problem solving and working within constraints. This is not a “production ready” CSS icon set.

Demo: Pure CSS GUI icons

Known support: Firefox 3.5+, Safari 5+, Chrome 5+, Opera 10.6+.

An exercise in constraint

Several months ago I was experimenting with the creation of common GUI icons with CSS. The HTML is very simple and it relies on CSS pseudo-elements rather than extraneous HTML elements. The technical aspects of this exercise might be of interest to others, so I’ve decided to share it.

Pseudo-elements provide many possibilities to developers interested in writing semantic HTML. If you’re looking for practical uses of pseudo-elements, this experiment gave me the idea for the technique used to create Multiple Backgrounds and Borders with CSS 2.1. But these GUI icons were a technical exercise.

Example code

The technique behind this experiment is an expansion of the basic shape-creation that was used to make Pure CSS speech bubbles. Some of these GUI icons can only be created in browsers that support CSS3 transforms.

The HTML is a basic unordered list of links.

<ul>
   <li class="power"><a href="#non">Power</a></li>
   <li class="play"><a href="#non">Play</a></li>
   <li class="stop"><a href="#non">Stop</a></li>
   <li class="pause"><a href="#non">Pause</a></li>
</ul>

Each icon uses its own set of styles. For example, the key parts of the CSS responsible for the “expand” icon are as follows:

.expand a:before {
   content:"";
   position:absolute;
   top:50%;
   left:1px;
   width:5px;
   height:0;
   border-width:7px 7px 0;
   border-style:solid;
   border-color:transparent #c55500;
   margin-top:-4px;
   /* css3 */
   -webkit-transform:rotate(-45deg);
   -moz-transform:rotate(-45deg);
   -o-transform:rotate(-45deg);
   transform:rotate(-45deg);
}

.expand a:after {
   content:"";
   position:absolute;
   top:50%;
   left:5px;
   width:8px;
   height:8px;
   border-width:3px 0 0 3px;
   border-style:solid;
   border-color:#c55500;
   margin-top:-6px;
}

.expand a:hover:before,
.expand a:focus:before,
.expand a:active:before {
   border-color:transparent #730800;
}

.expand a:hover:after,
.expand a:focus:after,
.expand a:active:after {
   border-color:#730800;
}

The demo page contains a full set of user interaction and media player control icons, as well as other common icons. For now, several icons actually require more than one element as CSS 2.1 only specifies 2 pseudo-elements per element that can contain generated content. The CSS3 Generated and Replaced Content Module allows for an unlimited number of pseudo-elements but has yet to be fully implemented in any modern browser.

Reply on Twitter Retweet on Twitter Favorite on Twitter

44 comments

#

Jordan Andree says…

This is awesome and well done!

#

Luca Degasperi says…

That’s unbelivable, thanks for sharing!

#

David says…

Very neat my friend. CSS3 is opening so many doors for pure text designs. Gradients, Icons, Special effects, and so many other neat ideas. It’s also inspiring to see people taking these elements and pushing them to the limits.

I love your simple design that draws me into reading text.

#

Angel Grablev says…

Very nice job sir! They even have partial support in ie8! This is great!

#

Gaurav M says…

Nice moves with :before and :after
Will puzzle initially curious mind if they just look on the demo icons page!

#

Rob says…

You just don’t stop do you :) This is great work. I would love it if they scaled better as zooming breaks a few of them. eg the mic and email http://cl.ly/3Jge but none the less a great exercise.

#

Sunny says…

Great job. Wish that Firebug could show :before and :after elements.

#

clyfe says…

This should live on github so the community can contribute, maybe have it in SASS

#

Nicolas says…

@Sunny: The web developer tools in Chrome/Safari and Opera allow you to inspect pseudo-elements.

@Hélio Correia: I’m aware of using Data URIs. This is a separate exercise that in and of itself is not a production-ready technique. It isn’t attempting to replace the use of image sprites. It was just about abusing CSS and learning something in the process.

@clyfe: I’d rather it wasn’t on Github because it isn’t something that I want to encourage to be deployed on websites. I don’t think this is practical and I hope people are aware of the limitations. Images and SVG are better tools for the job.

#

tony says…

it works just fine in Safari too (no surprise, really), for your information.

#

Terrence says…

Kudos. Great work.

#

shadr says…

The semantic nature of this is truly impressive. Good job.

#

Dave Kingsnorth says…

Hi Nicolas,

Really impressive use of css3. I’ve set myself the task of creating my personal blog without using a single image.

I would love to use several of these icons (I’m developing primarily for modern browsers).

Would you mind?

#

Yanik says…

They work on the Midori web browser too

#

Rio says…

We’re getting ever closer to breaking down any creative barrier we can envisage using CSS. Thank you for the inspiration.

#

Ilia says…

Great stuff. Really creative use of CSS.

#

Prélude says…

Très impressionnant, mais le code reste quand même très lourd.
Beau travail en tout cas !

#

Ethan Turkeltaub says…

Wow, these are amazing! As Hélio said above, you can use Data URIs, but I like this better, more for the novelty of it. What is the license on these, I would love to use them!

#

Yudiacro says…

Great job! You bring CSS to high level.

#

Nicolas says…

Like I said in the text above: these are not icons intended to be production-ready; they were a technical exercise. Using CSS in this way is no replacement for image sprites, SVG, or the use of Data URIs.

#

Sean says…

Unbelievable stuff. Amazing. Who needs graphics?

#

Ivo De Blasi says…

Thanks. It’s very very usefull.

#

Oliver says…

Really awesome! Thanks for sharing it. I really love the pie chart icon.

#

Oliver Sumpton says…

Some of the best icons I’ve ever seen!

#

mee says…

Wow, that was hard work! Great idea.
Thanks for sharing.

#

Xah Lee says…

hi, very high quality hack!

i think it’d be also interesting to find the corresponding unicode char when they exist. I did some work in this: http://xahlee.org/comp/unicode_computing_symbols.html

hopefully sometime i’ll organize them the way you have it. (perhaps half of the icons you have here are actually not in unicode) It’ll be great if someone work on this too.

PS i blogged about your work here http://xahlee.blogspot.com/2010/11/css-hack-multiple-background-and.html

#

Mr. JCRP says…

This is awesome man. Totally appreciate it. Very cool.

#

carsten says…

Thank you very much, for this idea!
After some research on, how you did it, I tried to create a creativecommons icon, in opposite to the often used ©.

It’s working with a single HTML-Element preferably an a-tag with rel=”license”.
Have a look at it and I’ll be happy about your feedback.
http://www.pixelfans.de/creativecommons-icon-mit-css/

#

Mike says…

This is very, VERY cool! I can see a ton of uses for this and will be looking at doing some testing to see how well different browsers handle the CSS.

#

max says…

Can’t believe it, this is pure CSS! Realy good job, Nicolas!

#

Romain says…

I wish fonts include a set of these standards icons. Lighter than images, neat on the screen, less code.
Is this question on the table of font-forges?

#

Bill says…

Lots of them look okay in IE8 too

#

Gary says…

This is really amazing! Thank you for sharing this CSS and HTML – I look forward to trying the various ‘icons’.

#

Paul M. Watson says…

They look great and good job with the semantics. Couple of questions if you don’t mind.

What is the overhead on the browser with all the after and before pseudo-selectors as well as the content property? The browser is creating these in the DOM, or somewhere, so I imagine the more complex they are, and the more you use on a page, the more processing, memory etc. is required? Be good to benchmark them.

How do you build them? Are you writing CSS, refreshing and then tweaking 100 times for each icon? You must have got better and faster with each one but for the rest of us it seems like a time consuming method of building icons?

#

Michael Raffaele says…

Really really awesome idea. Love the execution too, very nice and clean. Cheers

#

Mark says…

This is the most incredible thing I’ve ever seen! I can’t wait to use them in projects!

#

EllisGL says…

@Romain: I did a quick test of making a image sprite – not fully optimized – and was able to come up with an image sprite of 2.25K.
The full css is 34KB compressed (non gziped).

While yes – this is neat, I don’t think it ends up being lighter weight in the terms of file size.

#

Sean says…

It is over seven months after publication, more than 1000 retweets, but it looks like this post is becoming more instructive and stimulating, especially after launches of Firefox 4, 5 and IE 9, 10. What it is a great job :)!

#

Will says…

Great work! Simply brilliant!
PS: It also has IE9+ support :)

#

Joe says…

You really *are* the master of pseudo-classes!
This is so awesome and inspiring (the fact that the markup is semantic is really the icing on the cake!), I’ll be sure to link to this when I create a few tutorials on CSS3 rotations in the near future!

#

Brian FitzGerald says…

Nicolas, you mention there are “limitations” preventing you from recommending the use these icons in a production system. What limitations come to mind exactly (assuming we only support IE8+)?

Comments are now closed.