<img
src="technique_original.png"
alt="small pixelated man, upscaled with width and height attributes, appearing blurry" />Crisp pixel art look with image-rendering / notebook
Crisp pixel art look with image-rendering
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
img {
width: 48px;
height: 136px;
}<img
src="technique_original.png"
alt="small pixelated man, upscaled with CSS, appearing crisp" />img {
width: 48px;
height: 136px;
image-rendering: pixelated;
}<canvas id="game" width="128" height="128">A cat</canvas>canvas {
width: 512px;
height: 512px;
image-rendering: pixelated;
}// Get canvas context
const ctx = document.getElementById("game").getContext("2d");
// Load image
const image = new Image();
image.onload = () => {
// Draw the image into the canvas
ctx.drawImage(image, 0, 0);
};
image.src = "cat.png";img {
/* 5.7x scale factor */
width: 68.4px;
height: 193.8px;
image-rendering: pixelated;
}