Keep SVG Stroke Width Constant with Non-Scaling Stroke

By the Axialis Engineering team ·

Non-Scaling Stroke for SVG Icons

Scale a stroked SVG icon up and its outline gets visibly heavier, because the browser multiplies stroke-width by the same factor as the geometry. Set vector-effect="non-scaling-stroke" on the path or its group and the stroke is rendered in screen pixels after the transform, so a 2px line stays 2px at 16px, 24px, or 96px.

This is a presentation attribute defined in SVG 2, also settable as the CSS property vector-effect. Chrome, Edge, Firefox, and Safari have shipped it for years; Internet Explorer never supported it, and a few PDF/print pipelines ignore it (see the trade-offs below).

Where non-scaling stroke matters: hairline icons

The effect pays off most for thin, line-built icons that must stay thin at any size. Common cases:

Pros and cons of vector-effect="non-scaling-stroke"

Prepare your SVG in IconVectors

  1. Open or create your icon:
    • File -> Open... (Ctrl+O) or New Icon (Ctrl+N), working on a square grid such as 24x24 so stroke widths land on whole-pixel coordinates.
    • Set fill and stroke to currentColor so the icon inherits its color from CSS once it ships.
    A stroke-built camera icon open on the IconVectors canvas at 600% zoom with the live pixel and vector preview panel
    Export a minified SVG via File -> Export -> Export Minified (Shift+Ctrl+M), then open View -> Source Code (F3) to add the vector-effect attribute.

Apply non-scaling stroke (inline attribute or CSS)

You can set the effect two ways. Use the inline attribute when you want it baked into the icon file; use SVG-scoped CSS when you would rather toggle it with a class.

  1. Inline attribute (path or group)
    <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
      <g vector-effect="non-scaling-stroke"
         stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round">
        <path d="M4 12 9 17 20 6"/>
      </g>
    </svg>

    On the <g> it covers every child path. Size the SVG with CSS (width/height) or a transform: scale() and the rendered stroke stays at 2px.

  2. SVG-scoped CSS
    <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
      <style>
        .ns { vector-effect: non-scaling-stroke; }
      </style>
      <path class="ns" d="M4 12 9 17 20 6"
            stroke="currentColor" stroke-width="2" fill="none"/>
    </svg>

Outline strokes instead: a step-by-step in IconVectors

Below about 16x16, a live stroke can sit between device pixels and blur at the caps and joins even with non-scaling-stroke on. For that crispness, or for PDF, print, and legacy targets that ignore vector-effect, convert the stroke to a filled path you control node by node.

  1. Select the stroked shape with the Selection Tool (V). To outline a whole icon at once, select every stroked path first.
  2. Outline the stroke with Path -> Outline Stroke Path (Ctrl+J). Each stroke becomes a filled shape whose outline matches the original width, caps, and joins, so it no longer depends on stroke-width.
  3. Simplify the result with Path -> Simplify Path... to drop the redundant nodes the outline adds and keep the exported file small.
  4. Align nodes to the pixel grid. Turn on View -> Snap to Grid (Shift+Ctrl+R), then nudge caps and joins to whole-pixel coordinates with the Path Edition Tool so they render crisp at 100%.
  5. Verify the geometry. Check the live pixel preview at 100% zoom, then open View -> Source Code (F3) to confirm the shapes are now filled paths with no stroke attribute.
  6. Export. Use File -> Export -> Export Minified (Shift+Ctrl+M) for the vector asset, or File -> Export -> Export to Multiple Bitmaps (Shift+Ctrl+F3) for bitmap-only targets.

Troubleshooting

Related guides

Start Making SVG Icons Today with IconVectors

Download the fully-functional 30‑Day Free Trial and unlock your icon design workflow.

Version 1.70 for Windows, macOS, and Linux