Thuộc tính image-rendering kiểm soát thuật toán scale ảnh: mượt (smooth), nét (crisp-edges), pixelated.
Cú pháp
selector { image-rendering: auto | smooth | crisp-edges | pixelated; }
Ví dụ so sánh 3 chế độ
<!DOCTYPE html>
<html>
<head>
<style>
img {
height: 200px;
width: 200px;
image-rendering: auto; /* mặc định */
}
#smooth { image-rendering: smooth; }
#pixelated { image-rendering: pixelated; }
#crisp { image-rendering: crisp-edges; }
</style>
</head>
<body>
<h3>Smooth (mặc định - bilinear)</h3>
<img id="smooth" src="small-image.jpg" alt="Smooth">
<h3>Pixelated (nearest-neighbor - giữ pixel art)</h3>
<img id="pixelated" src="pixel-art.png" alt="Pixelated">
<h3>Crisp-edges (cạnh nét - cho diagram/text)</h3>
<img id="crisp" src="diagram.png" alt="Crisp">
</body>
</html>
Khi nào dùng cái nào?
| Giá trị | Thuật toán | Phù hợp cho |
|---|---|---|
| auto / smooth | Bilinear/Bicubic | Ảnh chụp, gradient, hình ảnh tự nhiên |
| pixelated | Nearest neighbor | Pixel art, retro game, QR code, icon nhỏ phóng to |
| crisp-edges | Edge-preserving | Sơ đồ, text, line art, border sắc nét |