Pure CSS social media icons (experimental)

This is an experiment that creates social media icons using CSS and semantic HTML. It uses progressive enhancement to turn an unordered list of text links into a set of icons without the use of images or JavaScript.

Demo: Pure CSS social media icons

Support: Firefox 3.5+, Safari 4+, Chrome 4+, Opera 10+, IE8+.

CSS social media icons

The image below shows you the final appearance in modern browsers.

A preview of the social media icons created using CSS

This experiment starts with a simple list of links, with each link using meaningful text, and then progressively styles each link to take on the appearance of the relevant social media icon. As a result, there should be support for screenreaders or users with CSS disabled.

I’ve also included basic text in the title attribute of each link to provide information for users who may not be familiar with what service a specific icon represents.

This is an experiment that uses CSS 2.1 and CSS3 that is not supported by Internet Explorer 6 and 7, therefore, you shouldn’t expect it to work in those browsers. CSS is not necessarily the most appropriate tool for this kind of thing either.

Example code

The technique I’ve used is much the same as the one used for the Pure CSS speech bubbles.

The HTML is just a basic unordered list of links to various social networking websites or services.

<ul>
   <li class="facebook"><a href="#non" title="Share on Facebook">Facebook</a></li>
   <li class="twitter"><a href="#non" title="Share on Twitter">Twitter</a></li>
   <li class="rss"><a href="#non" title="Subscribe to the RSS feed">RSS</a></li>
   <li class="flickr"><a href="#non" title="Share on Flickr">Flickr</a></li>
   <li class="delicious"><a href="#non" title="Bookmark on Delicious">Delicious</a></li>
   <li class="linkedin"><a href="#non" title="Share on LinkedIn">LinkedIn</a></li>
   <li class="google"><a href="#non" title="Bookmark with Google">Google</a></li>
   <li class="orkut"><a href="#non" title="Share on Orkut">Orkut</a></li>
   <li class="technorati"><a href="#non" title="Add to Technorati">Technorati</a></li>
   <li class="netvibes"><a href="#non" title="Add to NetVibes">NetVibes</a></li>
</ul>

I’ve applied some general styles to the elements that make up this list.

ul {
   list-style:none;
   padding:0;
   margin:0;
   overflow:hidden;
   font:0.875em/1 Arial, sans-serif;
}

ul li {
   float:left;
   width:66px;
   height:66px;
   margin:20px 20px 0 0;
}

ul li a {
   display:block;
   width:64px;
   height:64px;
   overflow:hidden;
   border:1px solid transparent;
   line-height:64px;
   text-decoration:none;
   /* css3 */
   text-shadow:0 -1px 0 rgba(0,0,0,0.5);
   -moz-border-radius:5px;
   -webkit-border-radius:5px;
   border-radius:5px; /* standards version last */
}

ul li a:hover,
ul li a:focus,
ul li a:active {
   opacity:0.8;
   border-color:#000;
}

Each icon uses it’s own set of styles. This is the CSS that created the RSS icon.

.rss a {
   position:relative;
   width:60px;
   padding:0 2px;
   border-color:#ea6635;
   text-transform:lowercase;
   text-indent:-186px;
   font-size:64px;
   font-weight:bold;
   color:#fff;
   background:#e36443;

   /* css3 */
   -moz-box-shadow:0 0 4px rgba(0,0,0,0.4);
   -webkit-box-shadow:0 0 4px rgba(0,0,0,0.4);
   box-shadow:0 0 4px rgba(0,0,0,0.4);
   background:-webkit-gradient(linear, left top, left bottom, from(#f19242), to(#e36443));
   background:-moz-linear-gradient(top, #f19242, #e36443);
   background:linear-gradient(top, #f19242, #e36443);
}

.rss a:before,
.rss a:after {
   content:"";
   position:absolute;
   bottom:10px;
   left:10px;
}

/* create circle */
.rss a:before {
   width:12px;
   height:12px;
   background:#fff;
   /* css3 */
   -moz-border-radius:12px;
   -webkit-border-radius:12px;
   border-radius:12px;
}

/* create the two arcs */
.rss a:after {
   width:22px;
   height:22px;
   border-style:double;
   border-width:24px 24px 0 0;
   border-color:#fff;
   /* css3 */
   -moz-border-radius:0 50px 0 0;
   -webkit-border-radius:0 50px 0 0;
   border-radius:0 50px 0 0;
}

Acknowledgements

This post was inspired by an experiment on insicdesigns that producing a few social media icons using CSS. Their experiment did not use semantic HTML, meaningful text, or degrade nicely in a semi-modern browser like Internet Explorer 8. This is my attempt to remedy that.

Reply on Twitter Retweet on Twitter Favorite on Twitter

20 comments

#

Ian Devlin says…

It just goes to show how powerful CSS3 can be for creating something so simple and yet so useful.

#

Apostolos says…

Great work and very nice coding. Well done dude.

#

Pj says…

This is mental.

#

Evan Byrne says…

I think my brain just melted from your awesomeness!

#

twe4ked says…

Amazing work, love the rss icon!

#

Jesse says…

Amaaaaazing coding. You just shocked me.

#

miller says…

shocked,admire

#

Mia says…

Well- there ya go : you just reinvented the wheel ! and they said it could never be done ! lies lies all lies :D. KUDOS – these are UberAwesome :)

wishing you much continued future success within life & career endeavors .

M.

#

Boubakr Nour says…

Great…
it’s very useful

#

zenoven says…

I know little about CSS3. It’s really great

#

Maggie says…

I never thought it would be even possible! can I use these and the speech bubbles for Tumblr themes?

#

Dimitris says…

Still learning CSS. Cool stuff. Great

#

Kiran Prasad says…

It seems a bit odd to do this with CSS3. This might have just been an attempt to see if it could be done but why would this be better than images? I understand that they are selectable etc but i think the right now browsers have optimized for image download/render and css3 rendering is not very fast even on the browsers that support it. Any ideas on when to and not use something like this?

#

Pieter van Wijngaarden says…

That stuff is awesome :-). The RSS-icon is not correct in Safari (4.0.5) though, for some reason

-webkit-border-radius: 0 50px 0 0;

doesn’t work. Shows a 90 degree angle instead of a curve.

-webkit-border-top-right-radius: 50px;

does! :-) I don’t know what the deal is in Chrome.

#

Nicolas says…

@Maggie Yes of course. The CSS icons might not really be appropriate though. Your call.

@Kiran The article says:

This is an experiment that uses CSS2.1 and CSS3…CSS is not necessarily the most appropriate tool for this kind of thing either.

@Pieter Thanks, I never got around to sorting that out. I’ve updated the CSS for the RSS and Delicious icons to give the rounding in Safari.

#

Mike Haydon says…

Gee, that’s freakin awesome! I didn’t even realize you could do gradients with css3. Thanks.

#

ZHAO Xudong says…

this is great,i really hope do not use any images in my site,and this really helps!
wo will try to make a buzz css icon.

#

Stewart says…

Wow! This is really great work. CSS3 amazes me everyday!

#

Optikal says…

if(brilliant) compliment = TRUE; send_thanks(“Nicolas Gallagher”, “nicolasgallagher.com”);

Comments are now closed.