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 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.
width="800" height="600" hardcoded, remove those attributes — keep only the viewBox.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.
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: #7c3aed; }
/* 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.