Guide · 4 min read
The SVG viewBox, width and height: one file, every box.
What an SVG's viewBox is, how it differs from width and height, how to make an SVG scale with its container, and why yours will not, shown on one file in two boxes, three ways.
Drop an image here
PNG, JPG, WebP, AVIF, GIF, BMP, TIFF or SVG · Up to 10 MB
meetthe default: all of it, with room aroundslicefills the box, cuts the overflownonestretched to the boxThe short version68 words
An SVG's viewBox gives the drawing's own coordinates: four numbers, its left, top, width and height. Width and height set how large it shows on the page. Keep the viewBox, drop the fixed width and height, and set the size with CSS, and the SVG scales with its container. preserveAspectRatio says how it fits a box of another shape: whole by default, filling with slice, stretched with none.
Updated 4 sources ↓
01The viewBox
What is the viewBox in an SVG?
The first is a logo drawn on a 1200 by 800 grid, with no fixed size: it takes the space it is given, as the file at the top does. The second is an icon's, drawn on a 24 by 24 grid and shown at 24 pixels.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">02viewBox vs size
What is the difference between viewBox, width and height?
Sets
- viewBox
- Which part of the drawing shows, in its own units
- width and height
- How large the SVG is on the page
Written as
- viewBox
- Four numbers: left, top, width, height
- width and height
- A length each: 240, 3em, 50vw
Left out
- viewBox
- The drawing is not scaled to its box
- width and height
- Inline, the SVG fills its container's width
| viewBox | width and height | |
|---|---|---|
| Sets | Which part of the drawing shows, in its own units | How large the SVG is on the page |
| Written as | Four numbers: left, top, width, height | A length each: 240, 3em, 50vw |
| Left out | The drawing is not scaled to its box | Inline, the SVG fills its container's width |
03Scale with the page
How do I make an SVG responsive?
<svg viewBox="0 0 1200 800" style="width:100%; height:auto">
…
</svg>04img or inline
Should I use an SVG in an img tag or inline?
Your page's CSS reaches inside
- <img src="logo.svg">
- No
- Inline <svg>
- Yes
Cached between pages
- <img src="logo.svg">
- Yes
- Inline <svg>
- No: it is part of each page
Alt text
- <img src="logo.svg">
- The alt attribute
- Inline <svg>
- Written into the SVG itself
Best for
- <img src="logo.svg">
- Logos and pictures that only show
- Inline <svg>
- Icons that change color, animated drawings
| <img src="logo.svg"> | Inline <svg> | |
|---|---|---|
| Your page's CSS reaches inside | No | Yes |
| Cached between pages | Yes | No: it is part of each page |
| Alt text | The alt attribute | Written into the SVG itself |
| Best for | Logos and pictures that only show | Icons that change color, animated drawings |
05Not scaling
Why is my SVG not scaling?
- No viewBoxNothing to scale from
- Without a viewBox, a new size crops or leaves space
- Add one: 0 0 and the drawing's own width and height
- A fixed sizewidth="240" wins
- Fixed attributes keep one size
- Remove them, and size it with CSS
- Space around itThe viewBox is larger than the drawing
- An empty margin inside the viewBox shows as space
- Crop the viewBox to the drawing
- A clean fileStart from one
- VecSnap's Web file carries a viewBox and no fixed size
- It fills the space you give it
06A clean SVG
How do I get an SVG of my logo that scales?
Drop your logo. Get its SVG.
- 01Drop the picture of your logo you have.
- 02Download the Web SVG: a viewBox, no fixed width or height.
- 03Put it in an img tag, or paste it inline, and size it with CSS.
Drop an image here
PNG, JPG, WebP, AVIF, GIF, BMP, TIFF or SVG · Up to 10 MB
07Questions
SVG sizing, answered.
Sources
- viewBoxMDN, read Oct 26, 2026
- preserveAspectRatioMDN, read Oct 26, 2026
- Including vector graphics in HTMLMDN, read Oct 26, 2026
- SVG 2: Coordinate systems, transformations and unitsW3C, read Oct 26, 2026
It says how the viewBox fits a box of another shape. The default, xMidYMid meet, shows all of it, centered; slice fills the box and cuts what overflows; none stretches it. The picture at the top shows all three.
Set fill on its shapes, with its code in the page; an img tag keeps the file's colors.
The drawing uses a grid 24 units wide and 24 high, starting at its top left: the usual grid of an icon set.
Change its width in CSS, or the width attribute on its tag; with a viewBox, the drawing scales to it, sharp at every size.
Yes: background-image: url("logo.svg"). Like an img tag, your page's CSS cannot recolor it there.
08More guides
Keep reading

Favicon size and format
Sizes, formats and the HTML, shown on one icon in a tab, a search result and a home screen.
Guide · 5 min read

What is an SVG file?
What the format is, and how to open, make and edit one, on a real file read line by line.
Guide · 4 min read

What is a vector file?
What one is, its formats, and how to tell a real one from pixels.
Guide · 3 min read

Image Trace in Illustrator, step by step
The steps, the settings and Expand, and what to do when Image Trace is grayed out.
Guide · 3 min read

How to change a logo's color
Change a logo's colors, make a white or a black version, and why a recolored PNG grows a halo.
Guide · 4 min read

How to fix a pixelated logo
Why a logo pixelates, the pixels each place asks for, and the fixes, shown on one small JPEG.
Guide · 5 min read

SVG vs PNG
Which format each job needs, shown on one drawing saved both ways.
Guide · 3 min read

How to change an SVG's color
Recolor an SVG in its text, with CSS or currentColor, and why one in an img tag will not change.
Guide · 4 min read

How to add a sticker border
A white edge and a smooth cut line, in Cricut, Illustrator, Inkscape or one step.
Guide · 5 min read
Inkscape Trace Bitmap, step by step
The steps, the modes and the settings, and what Trace Bitmap leaves on a real PNG.
Guide · 4 min read

How to vectorize an image in Photoshop
Make Work Path, color by color, and where it stops: what Photoshop can vectorize.
Guide · 4 min read

SVG vs EPS
What differs, which to send a printer, and one logo opened both ways.
Guide · 3 min read

How to vectorize an image in Canva
Canva's own apps, why a PNG saved as an SVG stays pixels, and an SVG you can recolor in Canva.
Guide · 4 min read

How to turn a Procreate drawing into a vector
Procreate shares no vector file: export the PNG that converts best, and draw for it.
Guide · 2 min read

How to make an SVG for Cricut
Why Design Space wants an SVG, and how to make one with a layer for each color.
Guide · 4 min read

Image Trace in Affinity, step by step
The steps, the two settings, where it is, and why traced corners come out round.
Guide · 4 min read

How to make an SVG for laser cutting
Why a traced SVG engraves some areas twice, and the file each laser app wants.
Guide · 5 min read

How to vectorize an image in Figma
Figma's own Vectorize, how to import or paste an SVG, and what makes a file easy to edit there.
Guide · 3 min read

How to reduce anchor points
Why a traced SVG has thousands, what they cost, and how to keep only the few a shape needs.
Guide · 2 min read
Drop an image. Check the file.
Converting is free. You see the whole result before you spend anything.
Drop an image here
PNG, JPG, WebP, AVIF, GIF, BMP, TIFF or SVG · Up to 10 MB