How to remove the ugly border around an image in a link

Common issuesThis question pops up almost weekly on message boards, mailing lists and in chat sessions:

How can I remove the ugly border around an image when it is linked?

I am amazed that this is still a question that needs to be asked, but the trick to remember is that when you put an image inside a link, like:

<a href="products.html">
  <img src="products.gif" alt="products" />
</a>

Then the browser puts a border around the image in the colour of the link. Therefore, changing the link border setting will not have any effect:

a {border:none; }

Instead, you need to set the image border to “none“:

 a img {border:none; }

It might be a good idea to define this as a preset in the beginning of your style sheet, to avoid the need to repeat it over and over again.

Also notice that the setting is “border:none”, which tells the user agent that there should not be a border – if you use “border:0″ you expect the User Agent to know how to display a border with a width of 0, which might not be possible.

I hope that this is going to be a post to show up high in google sooner or later, much like the ugly yellow form fields one.

7 Responses to “How to remove the ugly border around an image in a link”

  1. Georg Says:

    May save us a lot of repetitions.
    Is this where we stop writing long answers and just respond with:
    See [link] …?

  2. Henrique Costa Pereira Says:

    Wow… How age the person that asked you about how to remove a border from an image have? 8 or 9?

  3. Old Shitterhand Says:

    “I hope that this is going to be a post to show up high in google sooner or later, much like the ugly yellow form fields one.”

    I hope not. I hope you will write useful articles instead of crap.

  4. Chris Says:

    Hmm, I love you, too

  5. Digitally Speaking Says:

    “I am amazed that this is still a question that needs to be asked, but the trick to remember is that when you put an image inside a link, like:”

    There will always be people who don’t know this. Nobody knows everything, even I.

  6. ScarFace Says:

    Henrique Costa Pereira Says:
    December 14th, 2005 at 5:56 pm

    Wow… How age the person that asked you about how to remove a border from an image have? 8 or 9?

    ___________________________________

    …and you smart guy (Henrique Costa Pereira) how asshole are you really? You born with this knowledge and start working to NASA when you’re 4 ?

    look some stupid fucks…!!

  7. Zadig Galbaras Says:

    I have this problem my self, and cannot seem to get it solved.
    I have this in the css-file:

    a img {border: none; }

    I have put that line in every position I can think of, even inside the img-tag itself.
    There still appears a dotted line under my images containing a link.

    But then I am 54 years of age and dumb as a piece of wood.
    Maybe I shouldn’t ask my question here….

    But… What am I doing wrong?

Leave a Reply

Wait till I come! is the blog of Christian Heilmann , a developer evangelist living and working in London, England. Download vcard.

Feed me, Seymour: Entries (RSS) and Comments (RSS).