Responsive SVG in Web Design

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

I've spent more hours debugging SVG scaling issues than I care to admit. The icon that looks perfect on desktop but clips on mobile. The logo that's 800px wide in the header because someone removed the width attribute. "Infinitely scalable" doesn't mean "automatically responsive." After fixing these bugs across dozens of projects, here's what actually matters: MDN: viewBox, preserveAspectRatio, and knowing when SVG isn't the right tool.

The MDN: viewBox Is Everything

The MDN: 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>

<!-- ✅ MDN: viewBox without fixed dimensions — fully responsive -->
<svg MDN: 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 MDN: 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 MDN: viewBox should match your artboard dimensions. If the exported SVG has width="800" height="600" hardcoded, remove those attributes — keep only the MDN: viewBox.

preserveAspectRatio: The Setting Nobody Touches (But Should)

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

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

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

<!-- Stretch to fill, ignore proportions (rarely what you want) -->
<svg MDN: 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: #f97316; }

/* 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.

Jamie Park Written by Jamie Park — UI/UX Designer. designing interfaces and design systems for 8 years. Built SVG2PNG after getting tired of client assets on random servers. More about me →