Removing the image border in Chrome/IE9

74,823

Solution 1

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 2

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 3

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

Add attribute border="0" in the img tag

Solution 5

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">
Share:
74,823
Prasad
Author by

Prasad

Product ninja. UX devotee. Technology geek. Experiential learner. Innovating right products, leading products right. Zycus, L&amp;T, BITS Pilani alumnus. Husband, Son, Foodie, Storyteller, Wantrepreneur. Tweets #prodmgmt #ux #agile #culture #food #travel

Updated on September 18, 2020

Comments

  • Prasad
    Prasad over 3 years

    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?

    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;
    }
    <h1>Dashboard <img class="icon" border="0"></h1>

    See attached screenshot:

    Screenshot