Why does my SVG stretch or squash in CSS?

SVG stretching in CSS happens when an SVG icon, logo, illustration, or chart is forced into a CSS box that does not match its internal viewBox ratio.

CSS SVG fix

Why does my SVG stretch or squash in CSS?

SVG stretching in CSS usually happens when the SVG is treated like a normal rectangle, but its internal drawing, viewBox, width, height, or preserveAspectRatio behavior is not allowed to keep the intended shape. The element may fit the layout, but the artwork inside can become too tall, too wide, squeezed, flattened, or distorted.

This is different from a normal image being cropped. A JPG can be covered, cropped, or contained. An SVG has its own coordinate system. If that coordinate system is missing, or CSS forces a conflicting ratio, the visible result can look broken even when the browser is doing exactly what your CSS asked for.

Quick diagnosis

If an SVG looks stretched, inspect the SVG markup and the CSS sizing rule together. The bug is rarely just one line. It is usually a mismatch between the SVG’s internal ratio and the box CSS is trying to create.

The viewBox is missing

Without a viewBox, the SVG may not scale from a reliable internal coordinate system.

CSS forces a new ratio

Setting both width and height can reshape the SVG box in a way the drawing was not designed for.

preserveAspectRatio is risky

Using none can intentionally distort the artwork instead of fitting it naturally.

Icons need fixed rules

Small inline SVGs can stretch inside buttons, flex rows, grid cells, or line-height changes.

Logos need a shell

A brand mark should not be forced into whatever shape the header happens to create.

The fix is ratio ownership

Let the SVG own its ratio or give it a wrapper that protects the intended shape.

Test the SVG box before blaming the whole layout

Select the SVG in DevTools and compare three things: the rendered box size, the SVG viewBox, and the CSS width and height. If the rendered box has a different proportion from the artwork, the browser is obeying your CSS while the drawing is being forced into the wrong shape.

Related: Try this in the FrontFixer Live Inspector.

Open Live Inspector →

What the bug looks like

A logo becomes flat, an icon turns tall, or an illustration looks squeezed.

Why it happens

The SVG’s internal ratio and the CSS box ratio are fighting each other.

What usually fixes it

Add a useful viewBox, protect the ratio, and avoid forcing both dimensions blindly.

Error 1

The SVG is missing a useful viewBox

The viewBox tells the browser how the SVG drawing should scale. Without it, the SVG may have width and height attributes, but it does not have a flexible internal map. That makes responsive resizing unpredictable, especially when CSS tries to scale the SVG inside a card, button, header, or logo slot.

Broken code

No internal map
SVG/CSSCopy CodeExpand
<svg width=”240″ height=”80″> <path d=”…” /> </svg> .logo svg { width: 100%; height: 120px; }

Broken visual result

Logo gets flattened
The SVG has a rendered size, but the drawing does not have a reliable scaling system.
The browser fills the box, but the artwork loses its intended proportion.

Correct code

viewBox controls scale
SVG/CSSCopy CodeExpand
<svg viewBox=”0 0 240 120″ role=”img”> <path d=”…” /> </svg> .logo svg { width: 100%; height: auto; display: block; }

Fixed visual result

Drawing keeps ratio
The SVG now has an internal coordinate system, so scaling keeps the intended ratio.
The wrapper can resize without distorting the artwork inside the SVG.
Error 2

preserveAspectRatio is set to none

preserveAspectRatio="none" tells the browser that distortion is allowed. That can be useful for abstract backgrounds, but it is dangerous for icons, maps, badges, logos, charts, and UI illustrations. The SVG fills the box, but it fills the box by stretching the drawing.

Broken code

Distortion allowed
SVGCopy CodeExpand
<svg viewBox=”0 0 100 100″ preserveAspectRatio=”none”> <circle cx=”50″ cy=”50″ r=”40″ /> </svg> .badge svg { width: 100%; height: 180px; }

Broken visual result

Circle becomes oval
stretched
symbol
UI card
looks normal
The container is not broken. The SVG itself is allowed to distort inside that container.
The layout looks fine, but the SVG geometry is being pulled vertically.

Correct code

Ratio protected
SVG/CSSCopy CodeExpand
<svg viewBox=”0 0 100 100″ preserveAspectRatio=”xMidYMid meet”> <circle cx=”50″ cy=”50″ r=”40″ /> </svg> .badge svg { width: 100%; height: auto; }

Fixed visual result

Symbol remains circular
true
circle
space can
change
The box can be responsive without changing the geometry of the SVG artwork.
The SVG may leave safe space, but the artwork stays trustworthy.
Error 3

The icon is stretched by its flex or grid parent

Small inline SVGs often break inside buttons and navigation rows. A parent might stretch children, a grid cell might fill available height, or a utility class might set width:100% and height:100%. The icon then stops behaving like an icon and starts behaving like a layout block.

Broken code

Icon fills parent
CSSCopy CodeExpand
.button { display: flex; align-items: stretch; } .button svg { width: 100%; height: 100%; }

Broken visual result

Icon becomes layout
arrow icon stretched across button
label
The icon is no longer a small visual cue. It is filling the entire control space.
A layout parent should not decide the icon’s artwork ratio.

Correct code

Icon owns size
CSSCopy CodeExpand
.button { display: inline-flex; align-items: center; gap: .6rem; } .button svg { inline-size: 1.1em; block-size: 1.1em; flex: 0 0 auto; }

Fixed visual result

Icon stays icon
icon
button label
The parent aligns the content, but the SVG keeps a deliberate icon size.
Give icon SVGs a token size and prevent flex/grid from stretching them.
Error 4

The logo is forced into a header shape

Logos are where SVG stretching is most visible. A header may give the logo slot a fixed width and height, then force the SVG to fill that slot. The layout may look aligned, but the brand mark becomes wider, shorter, or taller than it should be. A logo needs a maximum size and a protected ratio, not blind stretching.

Broken code

Header controls logo
CSSCopy CodeExpand
.site-logo { width: 260px; height: 48px; } .site-logo svg { width: 100%; height: 100%; }

Broken visual result

Brand mark compressed
menu
The logo fills the header slot, but the brand proportion is no longer trustworthy.
A header box should not be allowed to deform the brand asset.

Correct code

Logo shell protects ratio
CSSCopy CodeExpand
.site-logo { inline-size: min(260px, 70vw); } .site-logo svg { display: block; width: 100%; height: auto; }

Fixed visual result

Brand keeps proportion
menu
The header controls available width, but the SVG still controls its natural height.
A logo shell keeps brand artwork clean across desktop and mobile.
Premium pattern

Three production-minded SVG patterns

Premium SVG systems do not rely on random width and height overrides. They define viewBox rules, icon tokens, logo shells, and decorative illustration boundaries so each SVG has a clear job. The layout can stay responsive without making the artwork look cheap.

Premium code example 1

Icon token system
CSSCopy CodeExpand
.icon { inline-size: var(–icon-size, 1.25em); block-size: var(–icon-size, 1.25em); flex: 0 0 auto; color: currentColor; } .icon svg { display: block; width: 100%; height: 100%; }

Premium visual result 1

Reusable icon rhythm
One icon systempremium

Buttons, alerts, menus, and cards all use the same SVG sizing rule.

nav
card
alert
CTA
design system readyicons stay elegant
Pattern 1 is ideal for UI icons, dashboard buttons, menus, and reusable component libraries.

Premium code example 2

Responsive logo shell
CSSCopy CodeExpand
.brand-lockup { inline-size: min(320px, 72vw); } .brand-lockup svg { display: block; width: 100%; height: auto; max-height: 72px; }

Premium visual result 2

Brand ratio protected
Scalable logo
BrandMark
desktop width cap mobile max width height remains auto
Pattern 2 is ideal for logos, sponsor marks, payment badges, and header lockups.

Premium code example 3

Decorative SVG boundary
HTML/CSSCopy CodeExpand
<div class=”hero-art” aria-hidden=”true”> <svg viewBox=”0 0 600 420″ preserveAspectRatio=”xMidYMid meet”>…</svg> </div> .hero-art { max-inline-size: 620px; aspect-ratio: 10 / 7; overflow: hidden; }

Premium visual result 3

Illustration stays intentional

Responsive art shell

The illustration scales inside its own frame while the content surface stays clean and readable.

viewBox saferatio shellno distortion
Pattern 3 is ideal for hero illustrations, dashboard graphics, decorative blobs, and onboarding screens.

Fast practical rule

Do not fix SVG stretching by guessing larger widths or smaller heights. First give the SVG a correct viewBox. Then let one layer own the ratio. For icons, use fixed token sizes. For logos, use width plus height auto. For decorative SVGs, use a wrapper with an intentional aspect ratio.

Meaningful SVG

Logos, icons, charts, maps, and UI illustrations should keep their geometry.

Decorative SVG

Abstract waves, blobs, separators, and masks can stretch only when distortion is intentional.

Best first move

Add or verify the viewBox, then remove forced height and test again.

Most sneaky cause

A parent button, flex row, or grid cell stretches the SVG without touching the SVG markup.

Debug checklist

  • Check whether the SVG has a real viewBox.
  • Look for CSS that sets both width and height.
  • Remove preserveAspectRatio="none" unless distortion is intentional.
  • Set icon SVGs with inline-size, block-size, and flex:0 0 auto.
  • Use height:auto for responsive logos and illustrations that should keep their ratio.
  • Give decorative SVGs a wrapper when the layout needs a specific art box.
  • Test inside real buttons, headers, cards, and mobile rows.
  • Compare the rendered box ratio with the SVG artwork ratio.

How to choose between meet, slice, and none

For most meaningful SVGs, meet is the safest behavior because the whole drawing stays visible. It may leave extra space in the box, but the artwork keeps its shape. slice is useful when the SVG should cover the box like a hero illustration, but it can crop edges. none should be rare because it allows the drawing to stretch differently on each axis.

The clean production habit is simple: use meet for icons, logos, diagrams, and UI symbols; use slice only for decorative artwork that can be cropped; use none only when distortion is the design. That decision alone prevents many SVG bugs from turning into mysterious CSS layout problems.

Cannibalization check

This fix targets SVG-specific distortion: viewBox, preserveAspectRatio, icon token sizing, and logo ratio shells. The regular image stretching fix is for bitmap images. The aspect-ratio fix is for wrapper shape problems. This page is focused on SVG artwork being squeezed or stretched inside a CSS box.

Final takeaway

SVG stretching in CSS happens when the SVG’s internal drawing system and the CSS layout box disagree. The browser is not confused. It is following the size rules you gave it. The visual breaks because the artwork needs a protected ratio, a useful viewBox, or a smaller dedicated icon rule.

Fix the ownership: let the SVG drawing keep its coordinate system, let the wrapper control layout when needed, and avoid forcing meaningful SVG artwork into random box shapes. That turns a stretched icon or squashed logo into a clean responsive asset.

Want more fixes like this?

Browse more CSS, SVG, image, responsive design, and layout debugging guides in the FrontFixer library.

Leave a Comment