Adding an icon to a headline or hyperlink

The attached pdf document shows how to add an icon to the left of a heading or link element using CSS.

In a nutshell, given that we have the following markup :

<li><a href="..." title="printer-friendly copy">Print this article</a></li>

Using padding to push the text to the right

We would like to snug in the image of a printer on the left-hand side of the text. For that, we will set the GIF image as background-image of the link, and push the text to the right with some padding (reminder : background images and color are still visible within the padding, but not in the margins).

Since we don’t have a class or id attribute to use for easily targetting that one link that is part of a list of links, we can use an attribute selector.

a[title*="printer-friendly"] {
padding-left: 30px;
background: url(images/printer.gif) no-repeat left center;

A word on attribute CSS selectors

Internet Explorer 6 does not support attribute selectors, but IE 7 does.

People often confuse the ~= operator with the *= one when using attribute selectors.

Selector What it does
p[class~="warning"] Use ~= for any attribute that accepts a space-separated list of words, such as the class attribute. This selects paragraphs that belong to the warning class, but may also belong to other classes as well.
p[class="warning"] This selects paragraphs that only belong to the warning class, and no other class.
a[href^="http"] This is a substring matching attribute selector. It selects links that have a href attribute that begins with letters http.
a[href$="pdf"] This is a substring matching attribute selector. It selects links that have a href attribute that ends with letters pdf.
a[title*="printer-friendly"] This is a substring matching attribute selector. It selects links that have a title attribute that contains these letters in that order : printer-friendly.

What if the link extends over several lines ?

Smaller text size

Larger text size

If the text extends over several lines, we may want to position the background image — the icon — so that it remains next to the first line of text, always. To position a background image relative to the text size inside a given element, we use em units. If within a given element the font-size is set to 12 pixels, 1 em is equal to 12 pixels, for that element. If within the same element the font-size is set to 14 pixels, 1 em is equal to 14 pixels, for that element.

Do not use pixels to position the background image, because the user may resize the text (see the two screenshots on the right), so you do not know for certain what size the text is within the element, in pixels. However, the size of the GIF image is fixed, and so is the padding that makes room for it on the left.

a[title*="printer-friendly"] {
padding-left: 30px; /*width of the GIF or png image*/
background: url(images/printer.gif) no-repeat 0em 0.5em;

Fine-tune the position of the icon by playing with the second em value, change it from ~0.3em to ~0.5em, until you like what you see.

UPDATE : There was a typo in the attribute selector table, and I corrected it on February 27th, 2007. The substring matching attribute that selects an attribute that begins with a given substring uses the ^= operator, not ~=. Sorry about that. Doh.

AttachmentSizeHitsLast download
iconizing.pdf74.49 KB577 years 33 weeks ago
Last edited by Caroline Schnapp about 10 years ago.

One file is attached to this posting. Login or register to download this file.


Thanks a lot.

Thanks a lot.

Outstanding info.

Outstanding information of your stuff, guy. I’ve study your current issues just before and you are just too awesome.

J Gateway is a new and

J Gateway is a new and upcoming condominium located in Boon Lay Way, Jurong East area. It is located right beside JCube, and the upcoming Westgate and Jem. With expected completion in mid 2016, it comprises of 4 towers with 783 units and stands 38 storeys tall.
Jurong Gateway

Incredible posting this is

Incredible posting this is from you. I am really and truly thrilled to read this marvelous post. You've really impressed me today. I hope you'll continue to do so! locksmith 89123

I absolutely enjoyed reading

I absolutely enjoyed reading your blog. Thank you so much for sharing with us some important knowledge on adding an icon to a headline or hyperlink.
tp180 video

Rolex watch they wear today

Rolex watch they wear today is surely going to offer them the status they had dreamt of.While there's been lots of fake Rolex watches made in China and Japan,you will find the best of the lot to be men special made Rolex replicas.

it seems your blog is really

it seems your blog is really good and nice.

Every day many new articles are written in the above article internet.but totally different from the others. Keep updated

Thanks a lot

Good article you're talking into. Insert a hyperlink into our article or file sometimes really helpful to navigate our audience. Keep posting and keep sharing dude.. :D

Very cool and nice post keep

Very cool and nice post keep updating us with good posts like those. Timber Merchants Bradford


Good article. Insert a hyperlink into our article or file its really helpful to us. Keep posting and keep sharing man. Thank you. how to get more followers on twitter fast

Parineeti Chopra Images

I understand the statement of Adding an icon to a headline or hyperlink now. Great images you love.

Best Free HD wallppaers

Great sharing that I was looking for a month. Nice post.

Saving Bond List

Download all prize bond list draw on bond result.

Best Baby Frock for Girls

Very nice design for all the baby girls that are cute.

Merci :)

Merci :)

Very interesting!

Very interesting!

Free hd wallpapers

This is a very nice icon for all you love the nature.

9HD walls

Great Stylish Flowers Wallpapers Download on 9hd wallpapers.

Best way to love to Pakistan

That is a great way to get love and research at a time. here PAKISTAN NATIONAL SONGS (URDU MILLI NAGHME) MP3 DOWNLOAD free.

I want to say about this

I want to say about this article, uummm this is amazing and nice post.
Content Writing Services

Free Background Wallpapers

Download latest Free Background Wallpapers free on hre.


I enjoyed over read your blog post. Your blog have nice information, I got good ideas from this amazing blog. I am always searching like this type blog post. I hope I will see again...

- usps tracking
- iphone 7 release date

This is really an awesome

This is really an awesome website. I have seen many websites but this one is awesome.
Value of Market Research Help


This tutorial has helped me a lot. I am trying online gokkasten betrouwbaar because a safe experience is important for our players.

You’ve written nice post,

You’ve written nice post, I am gonna bookmark this page, thanks for info. I actually appreciate your own position and I will be sure to come back here.
mortal kombat x, a10, roblox, color switch

kau hanya milikiku

amazing information is the nice post, like is you do i line it youdu, thank for information
anti jamur sinusitis dan cara menghilangkan lemak di leher

Great Blog.

Our quality control team will review and edit your essay paper before sending it to you.

kerala lottery is live kerala lottery result providers in kerala for buyers and sellers in kerala.kerala lottery
we know that common people are interested to watch kerala lottery result live , so we provide kerala lottery result as early as possible live or online .
we are not associated kerala lottery department or kerala government.kerala lottery resultsPromotional site of kerala lottery
kerala lottery result
kerala lottery result today
kerala lottery today result
today kerala lottery result
kerala state lottery results
kerala lottery today

Physical Layer Computer Network Assignment Help

This was a great and interesting article to read. I have really enjoyed all of this very cool information Physical Layer Computer Network Assignment Help

online BBA dissertation help

I loved the way you discuss the topic great work thanks for the share online BBA dissertation help

Here is the pokemon go

Here is the pokemon go cheats online.

Agen Domino Online Terpercaya

Starwin99 | Agen Domino StarWin99 Agen Judi Poker Domino Online Terpercaya

Starwin99 adalah Agen Domino Online & Bandar Domino yang
menyediakan Judi Online dengan permainan seperti Domino QQ, Adu Q, Judi Poker,
Domino 99 & Capsa Susun dengan Uang Asli Online.
Sebagai Bandar Q & Bandar Poker terpercaya, Starwin99 menyediakan permainan yang
100% adil, Pemain vs Pemain tanpa ada bot ataupun campur tangan admin. Sehingga
memberikan pengalaman judi domino online yang menyenangkan untuk anda
pecinta Judi Online Indonesia.

Thanks for the amazing

Thanks for the amazing information here. I have bookmarked this website for future use. Thanks a lot once again. Check our blog as well Kerala Lottery result today Latest WIN WIN lottery result today
Latest Dhanasree Lottery draw results

cat pod bed

I would also motivate just about every person to save this web page for any favorite assistance to assist posted the appearance. cat pod bed

prize bond

nice sharing dude

I was looking at some of

I was looking at some of your posts on this website and I conceive this web site is really instructive! Keep putting up.. instagram direct message from mac

great post

I just stumbled upon your blog and wanted to say that I’ve really enjoyed browsing your blog posts. In any case I will be subscribing to your feed and I hope you write again very soon!

Cupshe Floral Printing Dresses

I adore your websites way of

I adore your websites way of raising the awareness on your readers.I really enjoy reading and also appreciate your work.
company formation in hong kong

hack of 8 ball pool

Thanks for the tips guys. They were all great. I have been having issues with being fat both mentally and physically. Thanks to you guys i have been showing improvements. Do post more. hack of 8 ball pool

I surely acquiring more

I surely acquiring more difficulties from each surprisingly more little bit of it
company formation in hong kong


There are times when I find it difficult to make decisions, but still have to do. I know people always have emotions so that there is no justice. But I still hope.
baixar facebook l run 2 unblocked l slitherio l outlook entrar l facebook entrar l facebook iniciar sesión l hotmail entrar l hotmail iniciar sesión l run 2 game l return man 3

brilliant post

Gurgaon is business hub and is easily connected with the capital city of Delhi. Being regarded as the proclaimed business hub, Gurgaon is also a late night party hub for people who swear by the call centre or BPO environment of working. Escort services is Gurgaon are a rage among teens and business class people who just wish to have fun along with their already existing serious life.

Call girls in five star hotel in Gurgaon

Very cool hint! Thank you

Very cool hint! Thank you for showing him, I would like to code the same!
restaurants near me


I am very glad to read the post, it is very well written.You have done hard work in writing this post and i impressed your work.
1.49 Web Hosting Canada

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <css> <html> <javascript> <mysql> <php> <span> <a> <b> <i> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <sup> <sub> <dd> <del> <blockquote> <img> <q> <p> <div>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <css>, <html>, <javascript>, <mysql>, <php>, <rails>, <ruby>.

More information about formatting options

I have to wonder if you're a human spammer or a machine, or less likely someone who cares to leave his or her thoughts behind.