SVG image-rendering Property for Image Scaling

The image-rendering property in CSS and SVG allows developers to define the interpolation algorithm browsers use when scaling embedded raster images within an SVG document. By applying this property to an SVG <image> element or its parent container, you can control whether the browser renders scaled bitmaps using smooth anti-aliased filtering or sharp, nearest-neighbor pixel preservation. This article explains how scaling interpolation functions within SVG, the available property values, and how to apply them for different visual requirements.

How Interpolation Works in SVG

When an SVG contains an embedded raster graphic (such as a PNG, JPEG, or WebP) via the <image> tag, the raster content does not scale natively like vector paths. Instead, when the SVG viewport resizes or when the <image> dimensions differ from the source file’s intrinsic dimensions, the rendering engine must recalculate the pixel values.

The image-rendering property instructs the graphics engine on which mathematical algorithm to apply during this resampling process.

Supported Values and Interpolation Behaviors

The image-rendering property accepts several values that alter the scaling algorithm:

Syntax and Application

The image-rendering property can be applied inside an SVG either as an SVG presentation attribute or through standard CSS.

Using the SVG Presentation Attribute

<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
  <image href="icon.png" width="200" height="200" image-rendering="pixelated" />
</svg>

Using CSS Styling

svg image.sharp-render {
  image-rendering: pixelated;
}

svg image.photo-render {
  image-rendering: auto;
}

Because image-rendering is an inherited property, applying it to a <g> (group) tag or the root <svg> element applies that interpolation method to all nested <image> elements automatically.

Practical Use Cases