Add Icons Next To Hyperlinks Using CSS3


Hyperlink-IconsCascading Style Sheet is the heart of designers and with latest web technology such as CSS3, designing has become even more interesting. Thanks to CSS3 attribute value selectors, now you can style any file extension or tag.

I am using CSS3 attribute selector property in this tutorial to add Icons to hyperlinks. Previously we had to use JavaScript to add an icon next to the hyperlink on your blogger blog or website but now you can do it easily using CSS3. The icon will depend upon the type of file extension. If your link is pointing to a mp3 file then it will add a music symbol next to the link and so on. See the demo which shows 13 file format links,

Live Demo


How To Add Icons to Hyperlinks in Blogger?

  1. Go To Blogger > Design>  Edit HTML
  2. Check the "Expand Widget Templates" Box
  3. Search for this,

]]></b:skin>

     4.  Just above it paste the code given below,

/*--------- MBT Hyperlink Icons ----------*/

a[href*='.js'] {
background: url(http://4.bp.blogspot.com/-V8JUArvVlDg/TfUbt5n91dI/AAAAAAAADyU/1IBTSCCOqqs/s400/file_js.png) no-repeat 0 0;
padding:7px 0 0 25px;
}

a[href*='.gif'] {
background: url(http://3.bp.blogspot.com/-cm5RFNkVp00/TfUb5CerXjI/AAAAAAAADyc/2kTlh1gZtNA/s400/file_gif.png) no-repeat 0 0;
padding:7px 0 0 25px;
}

a[href*='.doc'] {
background: url(http://1.bp.blogspot.com/-ZH-3gjdNNvk/TfUbtq9_ZfI/AAAAAAAADyM/5faoK_0PTWY/s400/file_doc.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}

a[href*='.rar'] {
background: url(http://4.bp.blogspot.com/-uy-ymIWEbsU/TfUb6fTzK0I/AAAAAAAADy8/1F6rIj9GCyc/s400/file_rar.png) no-repeat 0px 0px;padding:7px 0 0 25px;
}

a[href*='.zip'] {
background: url(http://3.bp.blogspot.com/-W4uO8Fg9m7c/TfUcNyXIdqI/AAAAAAAADzU/fBOxrHNQ4Zw/s400/file_zip.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}

a[href*='.mp4'] {
background: url(http://4.bp.blogspot.com/-sz4_aCOdfzA/TfUb5RWH7ZI/AAAAAAAADyk/VhWkhTM8GCc/s400/file_mp4.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}

a[href*='.php'] {
background: url(http://3.bp.blogspot.com/-izMrgCy23Mc/TfUb6E3vLDI/AAAAAAAADy0/QhQdYov4ieA/s400/file_php.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}


a[href*='.xml'] {
background: url(http://2.bp.blogspot.com/-Etxu23Xq01M/TfUcM1TPaWI/AAAAAAAADzM/aW6KrL3HUlI/s400/file_xml.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}

a[href*='.pdf'] {
background: url(http://2.bp.blogspot.com/-1TXCLoxeksc/TfUb5v0cHLI/AAAAAAAADys/frrsfpSvB9g/s400/file_pdf.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}

a[href*='.xls'] {
background: url(http://2.bp.blogspot.com/-4mchydxbSDk/TfUcM0Hb7AI/AAAAAAAADzE/hTkZYduD6IY/s400/file_xls.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}


a[href*='.mpg'] {
background: url(http://3.bp.blogspot.com/-uZaIOrU9vHY/TfUcOJZbBqI/AAAAAAAADzc/9bBNR_Nujuc/s400/file_mpg.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}


a[href*='.bmp'] {
background: url(http://1.bp.blogspot.com/-XG8eI4EOxNQ/TfUbtRTAnUI/AAAAAAAADyE/XeFy0gdXWSs/s400/file_bmp.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}


a[href*='.avi'] {
background: url(http://3.bp.blogspot.com/-ToS4N4eSFPc/TfUbsyFM7gI/AAAAAAAADx8/veYOlPJ9-P4/s400/file_avi.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}


a[href*='.mp3'] {
background: url(http://2.bp.blogspot.com/-yZdVeVUN1dY/TfUbsnzwovI/AAAAAAAADx0/v7FT1FG3S2g/s400/audio_alt.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}

a[href*='mailto'] {
background: url(http://2.bp.blogspot.com/-qtnzCETuXWo/TfUjDdZtLKI/AAAAAAAADz8/pbxP1_s8R7w/s400/e_mail.png) no-repeat 0px 0px;
padding:0 0 0 25px;
}

 

    4.   Save your templates and you are done!

 

How it works?

The icons appear when the file extension is detected in the link. For Example if I add a link to pdf file like this,

<a href="http://www.mybloggertricks.com/xyz.pdf">Download E-book</a>

Then the link will appear like this when I publish it,

hyperlink-image

Now add any Ebook or any image link in your blogger posts, sidebars or footer anywhere you want and you will find cute icons appearing next to the link. You can also use icons of your choice by simply changing the icon image links  in the code above. The code is really easy to edit and I hope after having read so much of our tutorials you can at least edit this code. Have fun and let me know if you faced any problem. Enjoy! :)

PS: This technique is first bloggerized at MBT, any adoption of the code without attribution to MBT author will be taken as copyright violation.

Need Quick Help within 24 Hours? ASK NOW



If you don't want to get yourself into Serious Technical Trouble while editing your Blog Template then just sit back and relax and let us do the Job for you at a fairly reasonable cost. Submit your order details by Clicking Here »

17 comments : Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with 'Links' will be deleted immediately upon our review.

  1. ▁ ▂ ▃ ▄ ▅ ▆ █ 100%
    ─▀██▀───▀██▀─▀██──██─▀██▀▀ ▀─
    ──██─────██───██▄█▀───██▄█───
    ──██─────██───██▀█▄───██▀█───
    ─▄██▄▄█─▄██▄─▄██──██─▄██▄▄ ▄─ Thank you Mohammad! :D

    ReplyDelete
  2. very useful tips!! Thanks :D
    I expect more css3 tutorials from MBT :)

    ReplyDelete
  3. wow this is just superb.Like it a lot .There is so much interesting coming up everyday Mohd..thanks ...All this will help us a lot.

    ReplyDelete
  4. Step 3 -> Search for what?? Its ]]>.. You forgot to write :P

    And btw I don't understand how it works as we are not adding anything extra in the actual blogger post..
    Is it because of that a[href* which does all??
    If yes then it won't work for me as my links don't have any extension which is more good as less bad :) But no problems..

    ReplyDelete
  5. Nice tip, but there are more other techniques to use icon before text. but it is appreciate able.

    ReplyDelete
  6. @chris
    Thank you brother and I liked the unique style of your comment. :>

    @s'prdk
    Request accepted brother. glad you liked it.

    @Manisha
    You are welcomed dear sister and this gives me great pleasure when I hear that you are finding the tutorials helpful.

    @sam
    Thank you for reminding buddy. I updated all that you asked. :d

    @Incircle
    no doubt in it brother. CSS3 is still to be discovered. Thank you

    ReplyDelete
  7. Cool.. Exactly wat i guessed for "How it works?"..
    This wont work for me though..

    ReplyDelete
  8. maybe it was my first visit to your blog, but i enjoy reading your blog.. keep it going my friend.. succes4you
    if there is free time please visit my blog.. :D

    ReplyDelete
  9. Hi... Must@f@...

    Really Wonderful and Amazing Post. Sure it will give good look like 'better gmail' add on in gmail account. But it didnt work to me. i sent the result what i got in your mail. Check it. :)

    Regards
    H@r!

    ReplyDelete
  10. @Sam
    yes you are right since you share storage urls.

    @Reno
    Most welcomed brother. Pleasure. :>

    @hari
    I have sent a solution.

    @IShu
    welcome pal.

    ReplyDelete
  11. hey
    to be frank with you, I NV your blog.
    The layout, the footer in fact every thing is in perfect order.
    I have goten some motivation from your blog
    This is how a blog is suppose to look like !
    I'm puting most of your tips into practice.
    I will really appreciate it if you can give me a link.
    here is my blog.
    http://relationships-relationshiptips.blogspot.com/
    And maybe we can become guest writers on each other's blog.

    ReplyDelete
  12. is it possible to replace the link text with an image instead of adding icon beside it?

    i have lotsa links on my blog and wanted to change all of it into an image instead of text..is it possible?

    ReplyDelete
  13. is it possible to show icon before post title sort by label.I know its possible to add icon before post but what i want is for every label different image post title.For example music label,and then i post some post about music use label music and in front of post tile it shows that image,example 2 using sport label,before post title about sport (which uses label sport) some sport icon and so on ? THx

    ReplyDelete
  14. Hi Mohammad, This Tutorial is Awesome,,,
    but when I Place link Download like This :
    http://www.ziddu.com/download/16691776/RPP.1.GENAP.doc.html
    How It Work?
    thanks,

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. this is not working , i just tried it , any idea ?

    ReplyDelete