Crisp pixel art in CSS

Browsers smooth scaled images by default, which turns pixel art into mush. One line fixes it.

SNP 026 #513 Filed css pixelart

css
img.pixel-art {
  image-rendering: pixelated;
}

Scale the image with whole multiples (200%, 300%) and every pixel stays a sharp square. Fractional scales make some pixels bigger than others, which looks uneven.

If you need a fallback for old Firefox, image-rendering: crisp-edges does the same there. On this site every PNG and GIF in a post gets the pixelated treatment; photos are JPEGs, so they stay smooth.