There was a specification change in February 2021.
The definition of crisp-edges
has been updated to mean "use nearest neighbor," while pixelated
now means "maintain a pixelated appearance," indicating that an alternative to nearest neighbor filtering can be used if desired to keep the image looking pixelated.
As of the current year (2022), crisp-edges
(only supported in Firefox) and pixelated
(supported in Chrome/Edge and Safari) are actually functioning as nearest neighbor filters.
However, it's important to note that when using image-rendering: crisp-edges
to scale up images, users may not see the expected results due to the conversion from CSS pixels to device pixels based on the devicePixelRatio
, which may not always be an integer value.
For instance, scaling a 128x128 pixel image to 256x256 with image-rendering: pixelated
may not result in each original pixel being scaled to 2x2 due to variations in devicePixelRatio among different devices.
An example is provided below with a 64x64.png image and various scaling methods:
- Default (image-rendering: smooth)
- Image-rendering: pixelated
- Image-rendering: crisp-edges
- Offline scaling to 256x256 then scaled back to 128x128 using default (image-rendering: smooth)
.inline {
display: inline-block;
border: 1px solid red;
text-align: center;
padding: 10px;
}
<div class="inline">
<img src="https://i.sstatic.net/akzX9.png"
style="width: 128px; height: 128px;">
<div>smooth up</div>
</div>
<div class="inline">
<img src="https://i.sstatic.net/akzX9.png"
style="width: 128px; height: 128px; image-rendering: pixelated">
<div>pixelated up</div>
</div>
<div class="inline">
<img src="https://i.sstatic.net/akzX9.png"
style="width: 128px; height: 128px; image-rendering: crisp-edges">
<div>crisp up</div>
</div>
<div class="inline">
<img src="https://i.imgur.com/aahR6GT.png"
style="width: 128px; height: 128px;">
<div>smooth down</div>
</div>
<p>zoom in/out with Ctrl/Cmd +/-</p>
If you run the snippet and then zoom in your browser (Ctrl/Cmd +/-), you may notice differences in the visual quality of the scaled images depending on the method used.
Furthermore, a JavaScript library for scaling can help enhance the functionality of
image-rendering: pixelated/crisp-edges
by ensuring the image is always scaled to a multiple of device pixels.