CSS Reference ยท Filters, Masks and Shapes
The image-rendering property
Reference for the CSS image-rendering property: choose how the browser scales images up or down, including pixelated and crisp-edges for pixel art.
When a browser draws an image at a size different from its natural size, it has to guess the in-between pixels. By default it smooths the result, which looks good for photos but turns pixel art, QR codes and tiny icons into a blur. The image-rendering property is a hint about which scaling algorithm to prefer.
It applies to images of all kinds: <img>, <canvas>, <video>, and CSS background and border images.
.pixel-art { image-rendering: pixelated; }
Try it
Both canvases are only 8 by 8 pixels and are enlarged to 128 by 128 by CSS. The left one is interpolated and looks smudged; the right one keeps hard square pixels.
Syntax
image-rendering: auto | smooth | high-quality | crisp-edges | pixelated;
| Initial value | auto |
| Applies to | All elements (affects the images they draw) |
| Inherited | Yes |
| Animatable | No |
| Computed value | As specified |
Values
| Value | Description |
|---|---|
auto |
The browser's default scaling, normally smooth interpolation. |
smooth |
Asks for smooth scaling that keeps the image's look, similar to auto in practice. |
high-quality |
Prefers quality over speed; may be slower. Often behaves like auto. |
crisp-edges |
Scales so that edges and contrast are preserved, without smoothing colors. The exact algorithm depends on the browser. |
pixelated |
Uses nearest-neighbor scaling when enlarging, so every source pixel becomes a sharp block. |
Usage notes
- It is only a hint. The specification lets browsers pick the algorithm, so
crisp-edgesand the smooth values do not look identical everywhere.pixelatedis the most predictable choice for pixel art. - Only enlarging changes. Shrinking an image uses its own filtering;
pixelatedmostly affects upscaling. - Good fits: pixel art, sprites, QR codes, barcodes and screenshots shown at integer multiples of their size.
- Bad fits: photographs. Hard blocks make them look broken.
- Vector images (SVG) have no pixels to scale, so the property does nothing for them.
- Canvas. For
<canvas>content you drew yourself, you can also turn off smoothing in script withctx.imageSmoothingEnabled = false. - Inheritance. Because the property is inherited, you can set it once on a container to cover every image inside it.
Browser support
auto and pixelated work in all current browsers. crisp-edges, smooth and high-quality are handled inconsistently, so check a compatibility table before relying on them, and treat them as hints.
Related
object-fitโ how an image fits its boximage-orientationfilter- Lesson: Styling images