Is there any known way to make the CSS style background-size
work in IE?

- 301
- 2
- 5
- 20

- 56,088
- 93
- 276
- 422
-
1What effect are you trying to get? – ZippyV Jun 07 '10 at 17:22
-
@ZippV I have a div that is about 250 pixels wide. but the background image is 300px wide. I want the background image to fit in completely (background-size:100%) so it is not getting cut off. Then on `:hover` I want the background size to change to the full 300px width (background-size:auto) to create the illusion of zooming – JD Isaacks Jun 07 '10 at 17:26
-
1You could achieve the same effect by using an img tag. If you need anything on top of it, use the z-index. – ZippyV Jun 07 '10 at 17:35
-
1@John consider changing the accepted answer if Dan's workaround worked for you! – Pekka May 29 '12 at 16:02
-
@ZippyV The IMG tag has sometimes unneeded side-effects, for example it can be selected or right clicked. These are sometimes OK, sometimes not. – peterh Nov 05 '14 at 15:50
-
just make your bg image the same aspect ratio as the container, and this works fine (so far on IE 10+ . got the same issue with a container with border-radius. – mars-o Jul 10 '20 at 14:39
8 Answers
A bit late, but this could also be useful. There is an IE filter, for IE 5.5+, which you can apply:
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(
src='images/logo.gif',
sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(
src='images/logo.gif',
sizingMethod='scale')";
However, this scales the entire image to fit in the allocated area, so if you're using a sprite, this may cause issues.
Specification: AlphaImageLoader Filter @microsoft

- 4,367
- 2
- 30
- 57

- 10,171
- 7
- 38
- 31
-
12I wonder why MS didn't just implement that functionarlity using CSS. Thanks a lot! – Martin Andersson Oct 11 '11 at 11:52
-
2
-
8If you are using links and buttons inside the element which we defined this, those links and buttons wont work. Does anyone know a method to fix this? – rubyprince Jun 19 '12 at 14:35
-
2I had to add `position: relative; z-index: 999` for input, a, button inside such divs – rubyprince Jun 20 '12 at 12:24
-
1This worked for me but now my anchors and such inside of the div that I gave the background image to will not work. It's like something is on top of them. When I take off the filters they work again as normal. Any suggestions on this? – teewuane Jul 06 '12 at 22:47
-
@teewuane..please refer my comment above...i added style `a {position: relative; z-index: 999}` to make the anchors work. z-index should be a greater number. – rubyprince Jul 22 '12 at 17:17
-
10The scale method doesn't keep the ratio though.. So it's best that your element has the same ratio as your image. – Yves Van Broekhoven Aug 31 '12 at 08:49
-
1this is what fixed my anchor tag issue: background: #fff url(image.jpg) no-repeat center center fixed\0/; /* IE8 HACK */ – ph33nyx Oct 09 '12 at 18:32
-
1What this does is it actually places this filter *over* the background. So the background image is there still repeating, and then this one is placed over it. Anything sharing the same base level as the background will be underneath this new layer (even though at times the layer is transparent). This disallows interaction with those elements. The method will properly stretch the image, but at what cost? Too hackish for me but a nice approach none the less. – Travis J Nov 10 '12 at 22:21
-
2Worth noting that if applied to the `body` or `html` elements, this property can break scrolling, links, and other page interactions. – SouthShoreAK Feb 06 '13 at 15:43
-
Thanks for this solution, it does work but only problem is it changes the aspect ratio of original image. Is there a way around it? – sublime Mar 26 '13 at 18:04
-
@Ramesh Rajendran, put this 'code' in the style that references your background image (in your stylesheet) – Dan May 11 '13 at 09:16
-
1works like charm for ie 8 and previous version. but should be careful while referencing a image src – NiRUS Aug 16 '13 at 18:52
-
1It seems to be important where you paste this in your CSS, before the "normal" background specs or after. Make sure to check with all browsers and devices. – Jonathan Nov 14 '13 at 18:41
-
@Gaurav123 - because it's a legacy IE function! Try using -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; – Dan Feb 06 '14 at 03:54
-
so I need to use both things under one class or id. and it will automatically pick corresponding to browser, correct ? – Gaurav123 Feb 06 '14 at 06:38
-
@Gaurav123 Yes. The question asked was specifically for IE hence why my answer is for older versions of IE only. Check out http://css-tricks.com/perfect-full-page-background-image/ "Awesome, Easy, Progressive CSS3 Way" for more information. – Dan Feb 06 '14 at 10:50
-
ok friend, Thanks. I am just looking into this link...Just want to confirm that do we have option for safari browser there as well ? – Gaurav123 Feb 06 '14 at 12:30
-
What if the pictures sources are inline and I want them all to be "covered"? – Björn Mar 24 '15 at 08:54
I created jquery.backgroundSize.js: a 1.5K jquery plugin that can be used as a IE8 fallback for "cover" and "contain" values. Have a look at the demo.

- 1,768
- 1
- 13
- 14
-
12According to jquery.backgroundSize.js's documentation, the plugin is deprecated, and they recommend [background-size-polyfill](https://github.com/louisremi/background-size-polyfill) instead. – VOIDHand Jun 02 '13 at 23:11
-
The updated version does not work with `background-position: fixed`. – Ryan Burney Sep 09 '13 at 16:41
-
@VOIDHand Both the filter and the polyfill did not work for me, I used jquery.backgroundSize for success – Chris Marisic Aug 12 '14 at 14:28
Thanks to this post, my full css for cross browser happiness is:
<style>
.backgroundpic {
background-image: url('img/home.jpg');
background-size: cover;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(
src='img/home.jpg',
sizingMethod='scale');
}
</style>
It's been so long since I've worked on this piece of code, but I'd like to add for more browser compatibility I've appended this to my CSS for more browser compatibility:
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;

- 347
- 2
- 7
-
@Gaurav123 try `-webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;` – honk31 Feb 07 '14 at 13:16
-
6this makes my ie8 to display background image twice - one with scaled dimensions and the second one the big not sized background. – arekk Apr 21 '14 at 21:32
-
ie7: Looks OK, but can no longer click on links. (Why ie7? Govt sites very slow to update) – Robbie Matthews May 27 '14 at 01:34
There is a good polyfill for that: louisremi/background-size-polyfill
To quote the documentation:
Upload backgroundsize.min.htc to your website, along with the .htaccess that will send the mime-type required by IE (Apache only — it's built in nginx, node and IIS).
Everywhere you use background-size in your CSS, add a reference to this file.
.selector { background-size: cover; /* The url is relative to the document, not to the css file! */ /* Prefer absolute urls to avoid confusion. */ -ms-behavior: url(/backgroundsize.min.htc); }

- 22,759
- 8
- 120
- 116
-
This polyfill just works. background-size:cover or contain in IE8. No muss, no fuss. – jimlongo Jan 30 '15 at 15:45
-
this approach supports both `contain` and `cover`. It contains 5.7KB not very bad because it will transfer in one network packet. – S.M.Mousavi Apr 16 '16 at 12:29
Even later, but this could be usefull too. There is the jQuery-backstretch-plugin you can use as a polyfill for background-size: cover. I guess it must be possible (and fairly simple) to grab the css-background-url property with jQuery and feed it to the jQuery-backstretch plugin. Good practice would be to test for background-size-support with modernizr and use this plugin as a fallback.
The backstretch-plugin was mentioned on SO here.The jQuery-backstretch-plugin-site is here.
In similar fashion you could make a jQuery-plugin or script that makes background-size work in your situation (background-size: 100%) and in IE8-. So to answer your question: Yes there is a way but atm there is no plug-and-play solution (ie you have to do some coding yourself).
(disclaimer: I didn't examine the backstretch-plugin thoroughly but it seems to do the same as background-size: cover)
you can use this file (https://github.com/louisremi/background-size-polyfill “background-size polyfill”) for IE8 that is really simple to use:
.selector {
background-size: cover;
-ms-behavior: url(/backgroundsize.min.htc);
}
I tried with the following script -
.selector {
background-image: url("img/image.jpg");
background-size: 100%;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-repeat: no-repeat;
}
It worked for me!

- 70
- 2
- 9