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 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.
width="800" height="600" hardcoded, remove those attributes — keep only the MDN: viewBox.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.
SVG is unbeatable for logos, icons, illustrations, and simple graphics. But it has limits:
/* 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>
| Use Case | Format | Why |
|---|---|---|
| Logo in header | SVG | Crisp at any resolution |
| Icon system | SVG sprite | One file, infinite icons, color with CSS |
| Hero illustration (simple) | SVG | Small file, scales to 4K |
| Hero illustration (complex) | PNG @2x | Faster to render than heavy SVG |
| Email graphics | PNG | Universal client support |
| Social media post | PNG or JPG | Platforms 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.