When a website displays the same SVG icon at different sizes, its strokes normally scale with the icon. To keep their width constant in the browser, open the SVG file in a code editor and add vector-effect="non-scaling-stroke" to each shape whose stroke should stay fixed. You can do the same to SVG markup embedded directly in an HTML page.
Try one line at two sizes
Paste this code into an HTML page and open the page in a browser. The viewBox defines a 24 by 24 coordinate space; the displayed width and height set the SVG viewport.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
<path d="M12 5V19" fill="none" stroke="teal" stroke-width="2" vector-effect="non-scaling-stroke" />
</svg>
Change the SVG's width and height to 48 and reload the page. The line becomes twice as long, but its stroke remains 2 CSS pixels wide. Remove vector-effect and compare the two sizes again: the 24-pixel version has a 2-pixel stroke, while the 48-pixel version has a 4-pixel stroke.
| SVG viewport | Normal stroke | Non-scaling stroke |
|---|---|---|
| 24 × 24 CSS px | 2 CSS px | 2 CSS px |
| 48 × 48 CSS px | 4 CSS px | 2 CSS px |
These values describe the stroke geometry in this example; antialiasing and screen pixel density can affect its apparent edge. The SVG 2 specification defines the vector effect.
Apply it to each painted element
Put the attribute on each path, line, or other shape whose stroke must stay constant. It is not inherited from a parent group. Leave it off elements whose outlines should grow with the artwork; an icon can become visually too light at a larger size if every stroke stays fixed.
This example changes the SVG's display size in a browser; it does not change the stroke setting of an object in Illustrator or another design editor. A raster export has its own pixel dimensions and rendering behavior. Check any transformed or exported result at its intended size rather than assuming the 2-pixel comparison still applies.
If the destination needs a raster image, retain the SVG source and check the exported file at its final dimensions. The SVG and PNG guide covers choosing the delivery format.