CSS vector-effect Property

The CSS vector-effect property controls how certain SVG graphical effects behave when an element is transformed or scaled.

Its most commonly used value, non-scaling-stroke, keeps an SVG element's stroke width visually consistent when the element is enlarged or reduced. This is useful for icons, diagrams, charts, and other scalable vector graphics.

Note: The vector-effect property applies to SVG graphics. It does not control borders on ordinary HTML elements.

vector-effect Syntax

The vector-effect property accepts keywords that determine how SVG graphical effects respond to transformations.

Basic Syntax

.example {
  vector-effect: none;
}

Non-Scaling Stroke

.example {
  vector-effect: non-scaling-stroke;
}

Combined With stroke-width

.example {
  stroke: #0066cc;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

Applied to an SVG Shape

<svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
  <rect class="example" x="20" y="20" width="160" height="60" fill="none" />
</svg>

CSS-Wide Keywords

.example {
  vector-effect: initial;
}
.example {
  vector-effect: inherit;
}
.example {
  vector-effect: unset;
}
.example {
  vector-effect: revert;
}
.example {
  vector-effect: revert-layer;
}

Invalid Values

.example {
  vector-effect: fixed;
}
.example {
  vector-effect: no-scale;
}
.example {
  vector-effect: stroke;
}

The values fixed, no-scale, and stroke are not valid vector-effect values.

Property Values

Value Description
none Applies normal SVG rendering behavior. Strokes scale with the element. This is the initial value.
non-scaling-stroke Prevents the stroke width from scaling with the element's transformations.
non-scaling-size Defined in SVG 2 for keeping an element's size independent of certain transformations. Not supported for general production use.
non-rotation Defined in SVG 2 for preventing an element's rotation from following certain transformations. Not supported for general production use.
fixed-position Defined in SVG 2 for specialized fixed-position behavior. Not supported for general production use.

Property Characteristics

Characteristic Value
Initial value none
Inherited No
Applies to SVG graphics elements and supported SVG text content elements
Computed value As specified
Animation type Discrete
Percentages Not applicable
Specification Scalable Vector Graphics (SVG) 2

Note: The non-scaling-stroke value is the practical, widely implemented value beyond none. The other SVG 2 values are defined in the specification but lack interoperable browser support.

How It Works

SVG graphics are resolution-independent and can be resized or transformed without losing their geometric detail.

Normally, when an SVG shape is scaled, its stroke scales along with the shape. The vector-effect property can change that behavior.

Step 1: Create an SVG Shape

<svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
  <rect x="40" y="25" width="120" height="50" fill="none" stroke="#0066cc" stroke-width="4" />
</svg>

Step 2: Apply a Transformation

rect {
  transform: scale(1.5);
  transform-origin: center;
  transform-box: fill-box;
}

The rectangle becomes larger, and its stroke normally becomes thicker.

Step 3: Prevent Stroke Scaling

rect {
  vector-effect: non-scaling-stroke;
}

Step 4: Compare the Results

The rectangle still changes size, but its stroke remains at a consistent visual width instead of becoming thicker.

Important Distinction

The property does not prevent the SVG geometry from scaling. It changes how the stroke is rendered relative to the transformation.

The none Value

The none value uses normal SVG rendering behavior. Strokes scale along with the transformed geometry.

Syntax

.example {
  vector-effect: none;
}

HTML Example

<svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
  <circle class="normal-stroke" cx="100" cy="50" r="25" fill="none" />
</svg>

CSS Example

.normal-stroke {
  stroke: #0066cc;
  stroke-width: 4;
  vector-effect: none;
  transform: scale(1.5);
  transform-origin: center;
  transform-box: fill-box;
}

How It Behaves

When the circle is enlarged, both its geometry and its stroke are enlarged.

When to Use It

Use none when the stroke should scale naturally with the SVG shape.

Default Behavior

Because none is the initial value, it does not need to be declared unless you are overriding another rule.

The non-scaling-stroke Value

The non-scaling-stroke value prevents the width of an SVG stroke from changing as a result of scaling transformations.

Syntax

.example {
  vector-effect: non-scaling-stroke;
}

HTML Example

<svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
  <circle class="fixed-stroke" cx="100" cy="50" r="25" fill="none" />
</svg>

CSS Example

.fixed-stroke {
  stroke: #0066cc;
  stroke-width: 4;
  vector-effect: non-scaling-stroke;
  transform: scale(1.5);
  transform-origin: center;
  transform-box: fill-box;
}

How It Behaves

The circle becomes larger, but the stroke remains approximately the same visual width.

When to Use It

Use non-scaling-stroke when line thickness should remain consistent as SVG graphics are resized, zoomed, or transformed.

Common Applications

  • SVG icons that appear at different sizes.
  • Lines and outlines in diagrams.
  • Chart lines that should remain readable during zooming.
  • Interactive SVG maps.
  • Technical drawings and illustrations.

Important Consideration

The stroke is still drawn around the transformed shape. Only its scaling behavior changes.

Other Specification Values

SVG 2 defines additional vector-effect values, but they are not interoperably implemented in current browsers.

non-scaling-size

.example {
  vector-effect: non-scaling-size;
}

This value is intended to prevent the size of an element from changing under certain transformations.

non-rotation

.example {
  vector-effect: non-rotation;
}

This value is intended to prevent rotation from affecting an element in the usual way.

fixed-position

.example {
  vector-effect: fixed-position;
}

This value is intended for specialized positioning behavior relative to transformations.

Browser Compatibility

These values are included for specification reference. They should not be relied upon for production websites because browsers generally do not implement their intended behavior.

Recommended Approach

Use none or non-scaling-stroke for supported SVG rendering behavior.

SVG Transformations

SVG elements can be transformed using CSS or SVG transformation attributes.

The vector-effect property is especially useful when a transformation changes the apparent size of a stroke.

Scaling an SVG Shape

.example {
  transform: scale(2);
}

Scaling Without Thickening the Stroke

.example {
  transform: scale(2);
  vector-effect: non-scaling-stroke;
}

Nonuniform Scaling

.example {
  transform: scale(2, 1.5);
  vector-effect: non-scaling-stroke;
}

The geometry scales differently along the horizontal and vertical axes, while the stroke remains non-scaling.

Translation

.example {
  transform: translate(20px, 10px);
  vector-effect: non-scaling-stroke;
}

Translation moves the shape without changing its size, so stroke scaling is not normally a concern.

Rotation

.example {
  transform: rotate(30deg);
  vector-effect: non-scaling-stroke;
}

Rotation changes the orientation of the shape but does not normally change stroke thickness.

Important Consideration

The main benefit of non-scaling-stroke appears when transformations include scaling or when the SVG viewport changes size.

SVG viewBox Scaling

The SVG viewBox attribute defines the internal coordinate system used to display SVG content.

When the rendered SVG dimensions change, its contents are scaled to fit the viewport according to the SVG's sizing rules.

Basic SVG

<svg width="200" height="100" viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
  <rect x="20" y="20" width="160" height="60" fill="none" stroke="#0066cc" stroke-width="4" />
</svg>

Larger Rendered Size

<svg width="400" height="200" viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
  <rect x="20" y="20" width="160" height="60" fill="none" stroke="#0066cc" stroke-width="4" />
</svg>

Without vector-effect, the stroke becomes visually thicker because the SVG coordinate system is scaled.

Prevent Stroke Scaling

<svg width="400" height="200" viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
  <rect x="20" y="20" width="160" height="60" fill="none" stroke="#0066cc" stroke-width="4" vector-effect="non-scaling-stroke" />
</svg>

How It Behaves

The rectangle scales with the SVG viewport, but its stroke remains at a consistent visual width.

When to Use It

This technique is useful for responsive SVG graphics that appear at different rendered sizes.

Working With stroke-width

The stroke-width property controls the thickness of an SVG stroke.

Normal Stroke

.example {
  stroke: #0066cc;
  stroke-width: 4;
  vector-effect: none;
}

Non-Scaling Stroke

.example {
  stroke: #0066cc;
  stroke-width: 4;
  vector-effect: non-scaling-stroke;
}

Changing the Stroke Width

.example {
  stroke-width: 8;
  vector-effect: non-scaling-stroke;
}

The stroke becomes thicker because its declared width changed. The vector-effect property prevents scaling caused by transformations, not deliberate changes to stroke-width.

Stroke Color

.example {
  stroke: #cc3300;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

Stroke Line Caps

.example {
  stroke-linecap: round;
  stroke-width: 4;
  vector-effect: non-scaling-stroke;
}

Stroke Line Joins

.example {
  stroke-linejoin: round;
  stroke-width: 4;
  vector-effect: non-scaling-stroke;
}

Important Consideration

The vector-effect property does not replace stroke-width. Both properties can be used together to control SVG outlines.

CSS Property vs. SVG Attribute

The vector-effect feature can be applied using a CSS declaration or an SVG presentation attribute.

CSS Property

.example {
  vector-effect: non-scaling-stroke;
}

SVG Presentation Attribute

<svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
  <circle cx="100" cy="50" r="30" fill="none" stroke="#0066cc" stroke-width="4" vector-effect="non-scaling-stroke" />
</svg>

CSS Overrides the Attribute

<circle class="example" vector-effect="none" />
.example {
  vector-effect: non-scaling-stroke;
}

The CSS declaration takes precedence over the SVG presentation attribute under the normal cascade.

Choosing an Approach

Use a presentation attribute for a self-contained SVG graphic or a CSS declaration when several SVG elements share the same styling.

External SVG Images

CSS in the parent HTML document generally cannot target individual shapes inside an SVG loaded through an <img> element. To style individual SVG shapes with page CSS, use inline SVG markup.

stroke

.example {
  stroke: #0066cc;
}

Defines the paint used for an SVG element's outline.

stroke-width

.example {
  stroke-width: 4;
}

Controls the thickness of an SVG stroke.

stroke-linecap

.example {
  stroke-linecap: round;
}

Controls the appearance of the ends of open SVG strokes.

stroke-linejoin

.example {
  stroke-linejoin: round;
}

Controls the appearance of corners where SVG stroke segments meet.

fill

.example {
  fill: none;
}

Controls the paint used inside an SVG shape.

transform

.example {
  transform: scale(1.5);
}

Applies transformations such as scaling, rotation, translation, and skewing.

transform-origin

.example {
  transform-origin: center;
}

Defines the origin used when transforming an element.

Complete Example

.example {
  fill: none;
  stroke: #0066cc;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: scale(1.5);
  transform-origin: center;
  transform-box: fill-box;
  vector-effect: non-scaling-stroke;
}

Inheritance

The vector-effect property is not inherited. SVG child elements do not automatically receive a parent's declared value.

Parent Group

svg g {
  vector-effect: non-scaling-stroke;
}

Setting the property on a group does not automatically apply it to every shape inside that group.

Apply to Child Shapes

svg g path,
svg g circle,
svg g rect {
  vector-effect: non-scaling-stroke;
}

Explicit Inheritance

svg g {
  vector-effect: non-scaling-stroke;
}
svg g path {
  vector-effect: inherit;
}

The child path explicitly inherits the parent's computed value.

Restore the Initial Value

.example {
  vector-effect: initial;
}

This restores the initial value of none.

Using unset

.example {
  vector-effect: unset;
}

Because the property is not inherited, unset restores its initial value.

Important Consideration

When styling multiple SVG shapes, target the graphical elements directly rather than assuming a group-level declaration will be inherited.

Practical Examples

Non-Scaling SVG Icon

.icon path {
  stroke: currentColor;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

Responsive SVG Outline

.responsive-svg {
  width: 100%;
  height: auto;
}
.responsive-svg rect {
  fill: none;
  stroke: #0066cc;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

Chart Lines

.chart-line {
  fill: none;
  stroke: #008866;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

Diagram Connectors

.diagram-connector {
  fill: none;
  stroke: #555;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

Interactive SVG Shape

.interactive-shape {
  fill: none;
  stroke: #0066cc;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
  transition: transform 0.2s ease;
  transform-box: fill-box;
  transform-origin: center;
}
.interactive-shape:hover {
  transform: scale(1.2);
}

SVG Map Borders

.map-region {
  fill: #e5eef7;
  stroke: #333;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

Technical Drawing

.technical-line {
  fill: none;
  stroke: #222;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

Important Consideration

These examples assume the classes are applied to SVG graphical elements. Applying the same declarations to ordinary HTML elements will not produce SVG stroke behavior.

vector-effect Example

This example compares two SVG rectangles. Both use the same stroke width, but the first uses normal scaling while the second uses non-scaling-stroke.

Each rectangle is displayed at twice its original size. Compare the thickness of their outlines.

HTML Example

<div class="vector-demo">
  <div class="vector-item">
    <strong>vector-effect: none</strong>
    <svg viewBox="0 0 200 100" width="300" height="150" xmlns="http://www.w3.org/2000/svg">
      <rect class="normal-vector" x="40" y="25" width="120" height="50" fill="none" />
    </svg>
  </div>
  <div class="vector-item">
    <strong>vector-effect: non-scaling-stroke</strong>
    <svg viewBox="0 0 200 100" width="300" height="150" xmlns="http://www.w3.org/2000/svg">
      <rect class="fixed-vector" x="40" y="25" width="120" height="50" fill="none" />
    </svg>
  </div>
</div>

CSS Example

.vector-demo {
  display: grid;
  gap: 20px;
}
.vector-item {
  padding: 15px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
}
.vector-item strong {
  display: block;
  margin-bottom: 10px;
}
.vector-item svg {
  display: block;
  max-width: 100%;
  height: auto;
}
.normal-vector {
  stroke: #0066cc;
  stroke-width: 4;
  vector-effect: none;
}
.fixed-vector {
  stroke: #0066cc;
  stroke-width: 4;
  vector-effect: non-scaling-stroke;
}
Browser Result
vector-effect: none
vector-effect: non-scaling-stroke

Understanding the Results

Both rectangles use the same declared stroke width. However, the first rectangle's stroke scales with the SVG viewport, while the second rectangle's stroke does not.

Normal Scaling

The first rectangle uses vector-effect: none. Its stroke becomes thicker when the SVG is displayed at a larger size.

Non-Scaling Stroke

The second rectangle uses vector-effect: non-scaling-stroke. Its stroke remains at a consistent visual width.

Experiment With Stroke Width

.fixed-vector {
  stroke-width: 8;
  vector-effect: non-scaling-stroke;
}

The stroke becomes thicker because the declared width changes, but it still does not scale with the SVG viewport.

Experiment With SVG Size

Change the SVG dimensions while keeping the same viewBox to compare how each stroke responds.

<svg viewBox="0 0 200 100" width="400" height="200" xmlns="http://www.w3.org/2000/svg">
  <rect class="fixed-vector" x="40" y="25" width="120" height="50" fill="none" />
</svg>

The rectangle becomes larger, but the non-scaling stroke maintains its visual thickness.

Accessibility Considerations

Consistent SVG stroke widths can improve the readability of diagrams, icons, and other graphical interfaces.

Maintain Visible Outlines

Use sufficient stroke thickness and contrast so important shapes remain distinguishable at different sizes.

Avoid Extremely Thin Strokes

A non-scaling stroke does not automatically become thicker when a graphic is enlarged. Choose a width that remains visible.

Provide Accessible Names

<svg role="img" aria-label="A blue outlined circle" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  <circle cx="50" cy="50" r="30" fill="none" stroke="#0066cc" stroke-width="3" vector-effect="non-scaling-stroke" />
</svg>

Decorative SVG Graphics

<svg aria-hidden="true" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  <circle cx="50" cy="50" r="30" fill="none" stroke="currentColor" stroke-width="3" vector-effect="non-scaling-stroke" />
</svg>

Decorative graphics can be hidden from assistive technologies when they do not convey meaningful information.

Support Zooming

Test SVG graphics at different zoom levels to ensure outlines remain visible and shapes are understandable.

Do Not Rely on Stroke Alone

Use labels, patterns, or other visual distinctions when graphics communicate important information.

Test Interactive Graphics

For interactive SVG controls, ensure keyboard accessibility, clear focus indicators, and appropriate accessible names.

Common Mistakes

Applying vector-effect to HTML Borders

div {
  border: 2px solid blue;
  vector-effect: non-scaling-stroke;
}

The property does not control ordinary HTML borders.

Using an Invalid Value

.example {
  vector-effect: fixed;
}

Use non-scaling-stroke to prevent SVG stroke scaling.

Assuming the Entire Shape Stops Scaling

The non-scaling-stroke value prevents stroke scaling, not geometric scaling.

Confusing vector-effect With stroke-width

The stroke-width property sets the stroke thickness. The vector-effect property controls how that thickness responds to transformations.

Expecting Unsupported Values to Work

The non-scaling-size, non-rotation, and fixed-position values are not interoperably supported.

Applying the Property Only to a Group

svg g {
  vector-effect: non-scaling-stroke;
}

Because the property is not inherited, this does not automatically apply the effect to child shapes.

Styling an External SVG Through img

CSS in the containing HTML page cannot normally target individual SVG shapes inside an external image loaded with <img>.

Forgetting to Define a Stroke

.example {
  fill: blue;
  vector-effect: non-scaling-stroke;
}

If the SVG shape has no visible stroke, the non-scaling stroke effect may not be noticeable.

Using Excessively Thin Outlines

Non-scaling strokes can remain too thin to see clearly when graphics are displayed at large sizes or on certain screens.

Ignoring Responsive SVG Behavior

Test graphics at different viewport sizes to verify that the stroke remains visually appropriate.

Important Considerations

Keep the following points in mind when using vector-effect:

  • The property controls aspects of SVG rendering behavior.
  • Its initial value is none.
  • The none value allows normal stroke scaling.
  • The non-scaling-stroke value prevents stroke width from scaling with transformations.
  • The property does not prevent SVG geometry from scaling.
  • It does not control ordinary HTML borders.
  • It is most useful for SVG graphics with visible strokes.
  • It works with the stroke and stroke-width properties.
  • Changing stroke-width still changes the stroke thickness.
  • The property is not inherited.
  • Apply it directly to SVG shapes when needed.
  • It can be specified as CSS or an SVG presentation attribute.
  • CSS declarations can override presentation attributes.
  • It works with SVG transformations.
  • It can help maintain consistent outlines during zooming.
  • It can help maintain consistent outlines when an SVG viewport is resized.
  • It is useful for SVG icons and diagrams.
  • It is useful for chart lines and technical drawings.
  • It can improve the visual consistency of interactive SVG graphics.
  • The non-scaling-size value is not interoperably supported.
  • The non-rotation value is not interoperably supported.
  • The fixed-position value is not interoperably supported.
  • The property has a discrete animation type.
  • Test graphics at different rendered sizes.
  • Ensure strokes remain visible and have sufficient contrast.
  • Provide accessible names for meaningful SVG graphics.
  • Use inline SVG when page CSS must target individual shapes.

Browser Support

The CSS vector-effect property has broad support in modern browsers for the none and non-scaling-stroke values.

The additional values defined in SVG 2, including non-scaling-size, non-rotation, and fixed-position, are not interoperably implemented and should not be relied upon for production use.

For current compatibility information, visit Can I Use? and search for vector-effect.

Supported Declaration

.example {
  vector-effect: non-scaling-stroke;
}

SVG Presentation Attribute

<path d="M10 10 L90 90" stroke="blue" stroke-width="3" vector-effect="non-scaling-stroke" />

Feature Detection

@supports (vector-effect: non-scaling-stroke) {
  .example {
    vector-effect: non-scaling-stroke;
  }
}

Fallback Behavior

If a browser does not support the value, the SVG uses its normal stroke rendering behavior.

Testing Recommendations

Test SVG graphics at multiple sizes and zoom levels. Compare stroke thickness when scaling is applied and verify that outlines remain readable.

Specifications

The vector-effect property is defined in the Scalable Vector Graphics (SVG) 2 specification.

Scalable Vector Graphics (SVG) 2 - Vector Effects

The specification describes how vector effects influence the rendering of SVG graphical elements during transformations.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: vector-effect