18

When I turn an image (<img>) into a hyperlink (by wrapping it in <a>), Firefox adds a black border around the image. Safari does not display the same border.

What CSS declaration would be best to eliminate the border?

5 Answers 5

31
img {
    border: 0
}

Or old-fashioned:

<img border="0" src="..." />
     ^^^^^^^^^^
Sign up to request clarification or add additional context in comments.

1 Comment

This solution helped me out a lot, wish I'd found it before the 2 hours of frustration! But I think using "a img{border: 0;}" is a better fitted solution to the original problem - the emphasis on the initial "a" because the problem only occurs when an image is wrapped in a hyperlink
9

Just add:

border: 0;

or:

a img {
  border: 0;
}

to remove border from all image links.

That should do the trick.

Comments

6

in the code use border=0. so for example:

<img href="mypic.gif" border="0" />

within css

border : 0;

under whatever class your image is.

1 Comment

attention: Your <img> tag is not correct. Either you have to use " to quote the border attribute value (because XML requires that), or you have to remove the / before the ending > (because SGML/HTML doesn't allow that)
3
a img {
    border-width: 0;
}

2 Comments

That's invalid CSS: '0' does not have a unit. Should just be "border-width: 0;".
@BobbyJack Of course 0 needs a unit. Even if it can be derived from the context, all numbers (and 0 is a number) need a unit to be meaningful. The browser automatically adds the 'px' if you leave it off, cleaning up for your laziness - but it still needs to be there.
1

Try this:

img {
  border-style: none;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.