80

I am using gravatars and it's rather often when I downscale them with css, and I believe Google Chrome used to do it properly until recently ( I may be wrong, not sure when exactly the problem started to occur ) but now, images get blurred when downscaled, and that happens only in Chrome, FF downscales pretty good. I tried using image-rendering but it doesn't solve the problem. Can someone give me a hint what is the best way to go about it?

The example can be found here, open it in Chrome and then in FF, it should be way more blurred in Chrome than in FF.

Thank you

5
  • 1
    superuser.com/questions/530317/… outlines this issue quite well.
    – Mathias W
    Jun 19, 2016 at 11:35
  • 1
    @MathiasW This is a different issue, I am not zooming anything in here. Just open that link in FF and chrome ( without zooming in ) and see the image in chrome being blurred. Jun 19, 2016 at 15:46
  • 1
    This issue seems to be back 2017-05-10, I pretty sure images didn't used to be fuzzy, but currently on Chrome desktop they are fuzzy, the answer webkit setting fixes the issue (and images on Firefox are fine)
    – James
    May 10, 2017 at 15:58
  • It'd be nice to see your full code. For example "image-rendering doesn't work" doesn't help much if we don't know the value you used (especially since it's used in the accepted answer)
    – shaedrich
    Apr 7, 2021 at 8:15
  • In my case the problem was with the image itself, as it had an odd height.
    – CamaroSS
    Jan 27 at 6:36

12 Answers 12

162

I found the exact same issue on Mac: Firefox downscales the image really well, while Chrome makes it look blurry, which is very bad. I couldn't care less about rendering time or speed, I need the logo to look GOOD!

I found the following CSS rule fixing Chrome for Mac

image-rendering: -webkit-optimize-contrast;
15
  • 3
    saved my day - also works with background images. It's odd that Chrome really does a bad job downscaling PNGs without this rule.
    – low_rents
    Nov 24, 2017 at 10:03
  • 8
    Beware: this caused my images to be jagged/pixelated in Safari.
    – benjarwar
    Jan 19, 2018 at 17:54
  • 3
    This is not working for me in Chrome 64.0.3282.186 for Mac.
    – Badger
    Mar 5, 2018 at 10:58
  • 2
    @Badger You may want to try image-rendering: pixelated;
    – Chris S.
    Jun 5, 2019 at 14:02
  • 5
    Still an issue in 2020, and this answer still helped me (on Chrome 83)
    – manroe
    Jun 16, 2020 at 2:10
20

i find used transform: translateZ(0); is work.

by the similar question:How to prevent blur on image resize in Chrome?

3
  • Can you provide information why this solves the question's problem?
    – shaedrich
    Apr 7, 2021 at 8:13
  • Tested for Chromium-based (Chrome, Edge and Brave tested). According to this article, it makes the rendering be made by 3D hardware acceleration/GPU, and may cause issues with CSS animations, so better be used with caution. blog.teamtreehouse.com/… May 6, 2021 at 4:01
  • 1
    Worked like a charm, up until and including Chrome 81. Doesn't seem to work with 82 and 83 (dev) anymore.
    – mbw
    Aug 2, 2021 at 7:47
13

It seems that transform: translateZ(0); does not work anymore.
The only property I found which had any effect was image-rendering: -webkit-optimize-contrast; (note: this has a much different effect on iOS safari, where it makes the image very pixelated, so you'll only want to enable it on chrome and edge)

Here is a comparison using this image: <img src="https://i.stack.imgur.com/acaio.jpg" style="width: 244px; height: 244px;"> (on windows 10) comparison And a close-up of the text on the sign: I think firefox's rendering is significantly better, but optimize-contrast does help. close-up comparison

2
  • 32
    i am f*ing flabbergasted that this is a problem in 2021
    – Alex
    Oct 26, 2021 at 21:18
  • 3
    I suspect -webkit-optimize-contrast may have been removed recently. it seems to have no effect now (tested in ms edge version 99.0.1150.11, on linux)
    – 12Me21
    Feb 27 at 20:24
10

Update

I didn't realize that the image size after using 2x matched the target size and the browser wasn't downscaling. This solution only works if you can use a fixed size container for the image.

tl;dr

Set the image scale and Chrome will downscale properly. Tested in Chrome 84.

The important part is using srcset with 2x at the end.

<img srcset="image-2x.png 2x" alt="alt">

Full Answer

I tried image-rendering: -webkit-optimize-contrast. It improved the rendered image in Chrome but also gave me a bad looking version of the image in Safari.

At first, I needed downscaling because the 2x version of the image is still needed for Retina displays (otherwise the upscaling might look blurry). So I decided to create the two versions (1x and 2x).

After adding both, I saw that if I only used the original 2x image but with the 2x specified in srcset then the image will not render blurry anymore.

4
  • 1
    This is actually the correct approach, too bad your answer got downvoted ¯_(ツ)_/¯. Thanks! developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/… Sep 7, 2021 at 0:00
  • This did the trick for me, and not the "image-rendering" from the above answers. Upvoted this because no idea why this got downvoted.
    – Jrn
    Sep 9, 2021 at 10:57
  • 1
    In 2021 this REALLY needs to be accepted as the correct answer for this issue.
    – Nickfmc
    Dec 3, 2021 at 1:22
  • srcset with scale didn't work for me in my case
    – r g
    May 24 at 7:47
6

Pastullo's answer using image-rendering totally fixes the blurry image problem on Chrome, but the image is then pixelated on Safari. This combination of media queries worked for me to set the property on Chrome 29+ and unset it on Safari 11+:

@media screen and (-webkit-min-device-pixel-ratio:0)
and (min-resolution:.001dpcm) {
  img {
    image-rendering: -webkit-optimize-contrast !important;
  }
}

/* Unset for Safari 11+ */
@media not all and (min-resolution:.001dpcm)
{ @supports (-webkit-appearance:none) and (stroke-color:transparent) {
  img {
    image-rendering: unset !important;
  }
}}
4

Use will-change: transform; in Chrome for Windows and image-rendering: -webkit-optimize-contrast; for Mac.

1
  • 1
    UPD: do not use will-change: transform; on pages that contain a lot of images. This feature uses GPU to render images so it may slow down the browser. Nov 29, 2021 at 12:01
3

This will give you clean sharp images in scaled images in chrome. You need both translateZ(0) and scale not (1)

img {
border: none;
display: block;
transform: translateZ(0) scale(0.999999);
}

But if using any hover scale, make sure you also add in the translateZ(0) again.

i.e

img:hover {
transform: translateZ(0) scale(1.1);
}
2

Using transform: translateZ(1px); fixed the issue for me in Chrome, while not visually impacting other browsers.

1

I may complete this thread.

I found what could be considered as a bug (or maybe it's a feature).

If you downscale with CSS a logo in a big square bitmap image (500px x 500px JPEG for example) to 63px x 63px square, the result is very blurry in Chrome Version 97.0.4692.99 or any WebKit based browser I have on my computer. (Opera, Edge) But not Firefox.

Change to 64px x 64px, suddenly the result is better.

I suppose WebKit consider small sized images as unimportant and therefore could be scaled with a different, faster yet blurry algorithm.

If you scaled down logos on your website to 63px or 60px, consider making them a little bigger. Test in your inspector to verify if the rendering is satisfying.

You're all welcome!

0

I've found that the best way to resolve this issue is to just use an svg. Another option is to use css media queries to load adaptive images sizes.

4
  • For a lot of images, this is not an option. Also, they're not fully supported (see the notes for IE): caniuse.com/#feat=svg Jun 3, 2017 at 16:36
  • Not even Microsoft wants* you to care about that anymore. *) zdnet.com/article/…
    – Chris S.
    Jun 5, 2019 at 14:05
  • 1
    Not sure why this answer is rated so low. This is actually the most optimal solution. Most modern design tools support svg export now for any asset
    – D_S_X
    Jul 29, 2021 at 9:31
  • 1
    2021 approved. Upvote this guy. Dec 8, 2021 at 17:09
0

I propose another track because I was in the same situation: images slightly blurred under chrome but impeccable under firefox. Ctrl + "0" solved the problem. I had to one day use the zoom (Ctrl + "+" or "-") and did not reset it completely ...

0

For me, it displayed perfectly, if I made the image 2x times bigger and it will scale correctly in Chrome/MacOS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.