Responsive SVG in Web Design

For designers & front-end developers · June 2026 · 5 min read

SVG is the only image format that scales infinitely without pixelation. But "infinitely scalable" doesn't automatically mean "works great at every screen size." Responsive SVG requires understanding three things: viewBox, preserveAspectRatio, and when SVG is the wrong choice. Let's get into it.

The viewBox Is Everything

The viewBox attribute defines the coordinate system of your SVG. It's four numbers: min-x min-y width height. Getting this right is 90% of the responsive SVG battle.

<!-- ❌ Fixed dimensions — will not scale -->
<svg width="200" height="200">...</svg>

<!-- ✅ viewBox without fixed dimensions — fully responsive -->
<svg viewBox="0 0 200 200">...</svg>

<!-- ✅ Best practice: responsive SVG in an img tag -->
<img src="icon.svg" alt="" style="width:100%;max-width:200px">

The rule: always set viewBox, never set width/height on the SVG element unless you need a specific fixed size. Let CSS control the rendered dimensions.

Design workflow tip: When exporting SVGs from Figma or Illustrator, check the export settings. "Responsive" should be checked, and the viewBox should match your artboard dimensions. If the exported SVG has width="800" height="600" hardcoded, remove those attributes — keep only the viewBox.

preserveAspectRatio: The Setting Nobody Touches (But Should)

preserveAspectRatio controls what happens when the SVG container's aspect ratio doesn't match the viewBox. It accepts two values: alignment and meet/slice.

<!-- Default: scales to fit, keeps proportions, centers in container -->
<svg viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet">

<!-- Fill entire container, crop overflow (like background-size: cover) -->
<svg viewBox="0 0 100 100" preserveAspectRatio="xMidYMid slice">

<!-- Stretch to fill, ignore proportions (rarely what you want) -->
<svg viewBox="0 0 100 100" preserveAspectRatio="none">

For hero graphics and decorative illustrations, xMidYMid slice often looks better — the SVG fills the space while keeping its proportions. For icons and logos, the default xMidYMid meet is what you want.

When SVG Is the Wrong Tool

SVG is unbeatable for logos, icons, illustrations, and simple graphics. But it has limits:

CSS Tricks for Responsive SVG

/* Make an inline SVG scale with its container */
.inline-svg { width: 100%; height: auto; }

/* Constrain max size while remaining responsive */
.icon { width: 100%; max-width: 48px; height: auto; }

/* Color an SVG icon with CSS (only works with inline SVG) */
.icon:hover path { fill: #7c3aed; }

/* Hide decorative SVGs from screen readers */
<svg aria-hidden="true">...</svg>

Quick Reference: SVG vs PNG for Web

Use CaseFormatWhy
Logo in headerSVGCrisp at any resolution
Icon systemSVG spriteOne file, infinite icons, color with CSS
Hero illustration (simple)SVGSmall file, scales to 4K
Hero illustration (complex)PNG @2xFaster to render than heavy SVG
Email graphicsPNGUniversal client support
Social media postPNG or JPGPlatforms don't accept SVG

Need to export an SVG design as PNG for a specific use case? SVG2PNG converts SVG to PNG, JPG, or WebP at any resolution — all in your browser, no upload needed.