Removing the image border in Chrome/IE9

CssImageGoogle ChromeStylesheetBorder

Css Problem Overview


I am trying to get rid of the thin border that appears for every image in Chrome & IE9. I have this CSS:

outline: none;
border: none;

Using jQuery, I also added a border=0 attribute on every image tag. But the border as shown in the image still appears. Any solution?

<h1>Dashboard <img class="icon" border="0"></h1>

body {
    font: 10px "segoe ui",Verdana,Arial,sans-serif, "Trebuchet MS", "Lucida Grande", Lucida, sans-serif;
}
img, a img {
    outline: none;
    border: none;
}
.icon {
    width: 16px;
    height: 16px;
    text-indent: -99999px;
    overflow: hidden;
    background-repeat: no-repeat;
    background-position: -48px -144px;
    background-image: url(theme/images/ui-icons_0078ae_256x240.png);
    margin-right: 2px;
    display: inline-block;
    position: relative;
    top: 3px;
}

See attached screenshot:

Screenshot

Css Solutions


Solution 1 - Css

It's a Chrome bug, ignoring the "border:none;" style.

Let's say you have an image "download-button-102x86.png" which is 102x86 pixels in size. In most browsers, you would reserve that size for its width and height, but Chrome just paints a border there, no matter what you do.

So you trick Chrome into thinking that there is nothing there - size of 0px by 0px, but with exactly the right amount of "padding" to allow for the button. Here is a CSS id block that I am using to accomplish this...

#dlbutn {
	display:block;
	width:0px;
	height:0px;
	outline:none;
	padding:43px 51px 43px 51px;
	margin:0 auto 5px auto;
	background-image:url(/images/download-button-102x86.png);
	background-repeat:no-repeat;
}

Voila! Works everywhere and gets rid of the outline/border in Chrome.

Solution 2 - Css

Instead of border: none; or border: 0; in your CSS, you should have:

border-style: none;

You could also put this in the image tag like so:

<img src="blah" style="border-style: none;">

Either will work unless the image has no src. The above is for those nasty link borders that show up in some browsers where borders refuse to play nice. The thin border that appears when there is no src is because chrome is showing that in fact no image exists in the space that you defined. If you are having this issue try one of the following:

  • Use a <div> instead of an <img> element (effectively creating an element with a background image is all you are doing anyway, the <img> tag really isn't being used)
  • If you want/need an <img> tag use Randy King's solution below
  • Define an image src

Solution 3 - Css

For anyone who wants to get rid of the border when the src is empty or there is no src just use this style:

IMG[src=''], IMG:not([src])      {opacity:0;}

It will hide the IMG tag completely until you add a src

Solution 4 - Css

Add attribute border="0" in the img tag

Solution 5 - Css

If u didn't define a src or the src attribute is empty in a img tag most browsers will create a border. To fix this use transparent image as src:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAMAAAAoyzS7AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAlwSFlzAAALEgAACxIB0t1+/AAAAApJREFUeJxjYAAAAAIAAUivpHEAAAAASUVORK5CYII=" border="0">

Solution 6 - Css

If you are trying to fix the Chrome Bug on loading images, but you ALSO want your placeholder image to load use (with Lazy Loading images, for example) use can do this trick:

.container { overflow: hidden; height: 200px; width: 200px }

.container img { width: 100%; height: 100% }

.container img[src=''],
.container img:not([src]) {
  width: 102%;
  height: 102%;
  margin: -1%;
}

This will make the border be hidden in the container's overflow and you won't see it.

Turn this: Chrome border bug

Into this: Chrome border bug fixed

Solution 7 - Css

I liked Randy King's solution in that chrome ignores the "border:none" styling, but its a bit complex to understand and it doesn't work in ie6 and older browsers. Taking his example, you can do this:

css:

ins.noborder
{
    display:block;
    width:102px;
    height:86px;
    background-image:url(/images/download-button-102x86.png);
    background-repeat:no-repeat;
}

html

<ins class="noborder"></ins>

Make sure when you use the ins tag to close it off with a "" or else the formatting will look funky.

Solution 8 - Css

In your img src tag, add a border="0", for example, <img src="img.jpg" border="0"> as per explained by @Amareswar above

Solution 9 - Css

using border="0" is an affective way, but you will need to add this attribute for each image.

i used the following jQuery to add this attribute for each image as i hate this outlines and borders around images.

$(document).ready(function () {
        $('img').each(function () {
            $(this).attr("border", "0");
        });
    });

Solution 10 - Css

inline css

<img src="logo.png" style="border-style: none"/>

Solution 11 - Css

You can remove the border by setting text-indent to a very big number, but the alt of the image also be gone. Try this

img:not([src]) {
    text-indent: 99999px !important;
}

Solution 12 - Css

I had a similar problem when displaying a .png-image in a div-tag. A thin (1 px I think) black line was rendered on the side of the image. To fix it, I had to add the following CSS style: box-shadow: none;

Solution 13 - Css

same as what @aaron-coding and @randy-king had - but just a more generic one to hide image border before they are loaded (i.e. with lazy-load.js or something

(apparently I can't do a code block in my original comment)

.lazy-load-borderFix {
  display: block;
  width: 1px !important;
  height: 1px !important;
  outline: none;
  padding: 0px;
  margin: -4px;
  background-image:none !important;
  background-repeat:no-repeat;
}

Solution 14 - Css

I fix it using padding style:

#picture {
    background: url("../images/image.png") no-repeat;
    background-size: 100%;
}

.icon {
    height: 30px;
    width: 30px;
    padding: 15px;
} 

The border is disappearing, while you are increasing padding value. Find your own value.

Solution 15 - Css

it worked for me. It took days which made me crazy.

img.logo
{
    display:block;
    width:100%;
    height:0px;
    outline:none;
    padding:43px 51px 43px 51px;
    margin:0 auto 5px auto;
}

Solution 16 - Css

the solution is to set the outline style to none (i.e.) outline:none, it's work with Me

Solution 17 - Css

First create an image type PNG transparent with photoshop in mini size. Then in your class please add:

content:url("url of your blank png");

Solution 18 - Css

That happens because you are using an img tag with no src attribute. The solution is puting the image into a div. Something like that:

<style>
         div#uno{
            display:block;
		 	width: 351px;
			height: 500px;
		 	background: url(especificaciones1.png) no-repeat;
		 	
		 }
		 div#dos{
            display:block;
		 	width: 612px;
			height: 500px;
		 	background: url(especificaciones2.png) no-repeat;
		 }

</style>
<div class="especificaciones">
   <div id="uno" class="imag1"></div>
   <div id="dos" class="imag2"></div>
</div>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPrasadView Question on Stackoverflow
Solution 1 - CssRandy KingView Answer on Stackoverflow
Solution 2 - CssZachView Answer on Stackoverflow
Solution 3 - CssJohnView Answer on Stackoverflow
Solution 4 - CssAmareswarView Answer on Stackoverflow
Solution 5 - Csscode19View Answer on Stackoverflow
Solution 6 - Cssaaron-codingView Answer on Stackoverflow
Solution 7 - CsssksallajView Answer on Stackoverflow
Solution 8 - CssdoodoodukesView Answer on Stackoverflow
Solution 9 - CssOldTrainView Answer on Stackoverflow
Solution 10 - Cssuser2645981View Answer on Stackoverflow
Solution 11 - CssHoang TrungView Answer on Stackoverflow
Solution 12 - CssZeratoView Answer on Stackoverflow
Solution 13 - CssrwcorbettView Answer on Stackoverflow
Solution 14 - CssAlexandrView Answer on Stackoverflow
Solution 15 - Cssvahid sabetView Answer on Stackoverflow
Solution 16 - CssFaridView Answer on Stackoverflow
Solution 17 - CssAmin KarimiView Answer on Stackoverflow
Solution 18 - CssAlejandro LiébanaView Answer on Stackoverflow