CSS stroke Property
The CSS stroke property specifies the color or paint used to draw the outline of an SVG shape, path, or text.
It can use a solid color, a gradient, a pattern, or another supported SVG paint source. The stroke property determines what is painted, while related properties such as stroke-width, stroke-linecap, and stroke-dasharray control how the outline is drawn.
stroke Syntax
The stroke property accepts a color, an SVG paint server reference, none, or a supported paint keyword.
Basic Syntax
svg circle {
stroke: blue;
}
Common Values
svg circle {
stroke: none;
}
svg circle {
stroke: red;
}
svg circle {
stroke: #2563eb;
}
svg circle {
stroke: rgb(37 99 235);
}
svg circle {
stroke: hsl(220 83% 53%);
}
svg circle {
stroke: currentColor;
}
svg circle {
stroke: url(#outlineGradient);
}
svg circle {
stroke: context-stroke;
}
CSS-Wide Keywords
svg circle {
stroke: initial;
}
svg circle {
stroke: inherit;
}
svg circle {
stroke: unset;
}
svg circle {
stroke: revert;
}
svg circle {
stroke: revert-layer;
}
The default value is none, meaning no stroke is painted. A visible stroke also requires an appropriate stroke width and a shape with a drawable outline.
Property Values
| Value | Description |
|---|---|
none |
Disables stroke painting. This is the initial value. |
<color> |
Specifies a solid stroke color using valid CSS color syntax. |
currentColor |
Uses the computed value of the element's color property. |
url() |
References an SVG paint server, such as a gradient or pattern. |
context-fill |
Uses the fill paint of a context element, where supported. |
context-stroke |
Uses the stroke paint of a context element, where supported. |
initial |
Resets the property to none. |
inherit |
Uses the computed stroke value from the parent element. |
unset |
Uses the inherited value because stroke is inherited. |
revert |
Reverts the property according to CSS cascade origin rules. |
revert-layer |
Reverts the property according to CSS cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | none |
| Inherited | Yes |
| Applies to | SVG shapes, text, and other applicable SVG elements |
| Computed value | As specified, with colors computed and applicable URLs resolved to absolute URLs |
| Animation type | By computed value type, depending on the paint value |
| Percentages | Not applicable as standalone values |
| Related properties | stroke-width, stroke-opacity, stroke-dasharray |
| Specification | SVG 2 |
Valid Examples
svg path {
stroke: black;
}
svg path {
stroke: #0d9488;
}
svg path {
stroke: rgb(13 148 136 / 80%);
}
svg path {
stroke: currentColor;
}
svg path {
stroke: url(#gradientStroke);
}
svg path {
stroke: url(#gradientStroke) blue;
}
svg path {
stroke: none;
}
The final color in url(#gradientStroke) blue provides a fallback if the referenced paint server cannot be used.
Invalid Examples
svg path {
stroke: 10px;
}
svg path {
stroke: 50%;
}
svg path {
stroke: solid;
}
svg path {
stroke: linear-gradient(red, blue);
}
svg path {
stroke: red blue;
}
The stroke property does not accept widths, standalone percentages, CSS border styles, or CSS gradient functions as direct paint values.
How It Works
SVG shapes have two main painting components: the fill, which paints the interior, and the stroke, which paints the outline.
Step 1: Create an SVG Shape
<svg viewBox="0 0 200 120">
<circle cx="100" cy="60" r="40"/>
</svg>
Without additional styling, the circle uses the default black fill and has no visible stroke.
Step 2: Set a Stroke Color
circle {
stroke: #2563eb;
}
The circle now has a blue outline using the default stroke width of 1.
Step 3: Adjust the Stroke Width
circle {
stroke: #2563eb;
stroke-width: 5;
}
The outline becomes thicker while retaining the same color.
Step 4: Change the Fill
circle {
fill: #dbeafe;
stroke: #2563eb;
stroke-width: 5;
}
The circle has a light blue interior and a darker blue outline.
Complete SVG Example
<svg viewBox="0 0 200 120" role="img" aria-label="Light blue circle with a dark blue outline">
<circle cx="100" cy="60" r="40" fill="#dbeafe" stroke="#2563eb" stroke-width="5"/>
</svg>
Stroke Position
By default, an SVG stroke is centered on the path defining the shape. A stroke width of 10 extends approximately 5 units to either side of the path.
This matters when positioning shapes near the edges of an SVG viewport, where part of a thick stroke may be clipped.
stroke vs. fill
The stroke and fill properties control different parts of an SVG shape.
| Property | Purpose | Initial Value |
|---|---|---|
stroke |
Paints the outline of a shape or path. | none |
fill |
Paints the interior of a shape or path. | black |
Fill Without Stroke
.filled-shape {
fill: #2563eb;
stroke: none;
}
The shape has a blue interior without a painted outline.
Stroke Without Fill
.outlined-shape {
fill: none;
stroke: #2563eb;
stroke-width: 4;
}
The shape has a blue outline and no painted interior.
Fill and Stroke Together
.combined-shape {
fill: #bfdbfe;
stroke: #1d4ed8;
stroke-width: 4;
}
The shape has both a filled interior and an outline.
Important Consideration
The stroke property does not replace fill. Both properties can be used independently or together.
Using stroke-width
The stroke-width property determines the thickness of the painted outline.
Thin Stroke
.thin-outline {
stroke: #2563eb;
stroke-width: 1;
}
Medium Stroke
.medium-outline {
stroke: #2563eb;
stroke-width: 4;
}
Thick Stroke
.thick-outline {
stroke: #2563eb;
stroke-width: 10;
}
Stroke Width of Zero
.hidden-outline {
stroke: #2563eb;
stroke-width: 0;
}
The stroke paint remains defined, but a width of zero produces no visible outline.
Preventing Stroke Scaling
.fixed-width-outline {
stroke: #2563eb;
stroke-width: 3;
vector-effect: non-scaling-stroke;
}
The non-scaling-stroke value prevents the stroke width from scaling with SVG transformations.
Important Consideration
Use stroke to choose the paint and stroke-width to control its thickness.
Stroke Colors
The stroke property supports CSS color values, including named colors, hexadecimal notation, color functions, and special keywords.
Named Color
svg path {
stroke: coral;
}
Hexadecimal Color
svg path {
stroke: #2563eb;
}
RGB Color
svg path {
stroke: rgb(37 99 235);
}
HSL Color
svg path {
stroke: hsl(220 83% 53%);
}
Color With Alpha
svg path {
stroke: rgb(37 99 235 / 50%);
}
The stroke uses a partially transparent blue color.
currentColor
.outline-icon {
color: #2563eb;
}
.outline-icon path {
stroke: currentColor;
}
The SVG path uses the computed value of the color property, making it useful for icons that follow surrounding text colors.
Modern Color Functions
svg path {
stroke: oklch(60% 0.18 250);
}
Modern CSS color functions can be used where supported by the browser.
Transparent Stroke
svg path {
stroke: transparent;
}
The stroke is fully transparent. Unlike stroke: none, it still defines stroke paint that may affect certain SVG painting and interaction behaviors.
Gradients and Patterns
SVG strokes can use gradients and patterns instead of solid colors. These paint sources are defined in SVG and referenced using url().
Linear Gradient Stroke
<svg viewBox="0 0 220 120">
<defs>
<linearGradient id="strokeLinearGradient">
<stop offset="0%" stop-color="#2563eb"/>
<stop offset="100%" stop-color="#ec4899"/>
</linearGradient>
</defs>
<circle cx="110" cy="60" r="40" fill="none" stroke="url(#strokeLinearGradient)" stroke-width="10"/>
</svg>
The circle outline transitions from blue to pink.
Radial Gradient Stroke
<svg viewBox="0 0 220 120">
<defs>
<radialGradient id="strokeRadialGradient">
<stop offset="0%" stop-color="#facc15"/>
<stop offset="100%" stop-color="#ea580c"/>
</radialGradient>
</defs>
<circle cx="110" cy="60" r="40" fill="none" stroke="url(#strokeRadialGradient)" stroke-width="10"/>
</svg>
The stroke uses a radial gradient paint source.
Pattern Stroke
<svg viewBox="0 0 220 120">
<defs>
<pattern id="strokePattern" width="10" height="10" patternUnits="userSpaceOnUse">
<rect width="10" height="10" fill="#dbeafe"/>
<path d="M0 10 L10 0" stroke="#2563eb" stroke-width="3"/>
</pattern>
</defs>
<rect x="20" y="20" width="180" height="80" fill="none" stroke="url(#strokePattern)" stroke-width="12"/>
</svg>
The rectangle outline uses a repeating diagonal pattern.
Fallback Color
.gradient-outline {
stroke: url(#outlineGradient) #2563eb;
}
The solid blue color acts as a fallback if the SVG paint server reference cannot be used.
Important Consideration
CSS linear-gradient() and radial-gradient() functions cannot be assigned directly to stroke. Define an SVG gradient and reference it with url().
Stroke Opacity
The stroke-opacity property controls the opacity of an SVG stroke independently of its paint value.
Fully Opaque Stroke
.opaque-outline {
stroke: #2563eb;
stroke-opacity: 1;
}
Partially Transparent Stroke
.transparent-outline {
stroke: #2563eb;
stroke-opacity: 0.5;
}
Fully Transparent Stroke
.invisible-outline {
stroke: #2563eb;
stroke-opacity: 0;
}
Color Alpha and Stroke Opacity
.combined-opacity {
stroke: rgb(37 99 235 / 50%);
stroke-opacity: 0.5;
}
The color alpha and stroke opacity combine, producing an effective stroke opacity of approximately 25%.
Important Consideration
Use stroke to choose the paint and stroke-opacity to control its transparency. The opacity property can additionally affect the entire SVG element.
Related Stroke Styling
Several CSS properties control the appearance of SVG strokes without changing the paint specified by stroke.
| Property | Purpose |
|---|---|
stroke-width |
Controls stroke thickness. |
stroke-opacity |
Controls stroke transparency. |
stroke-linecap |
Controls the shape of open path endpoints. |
stroke-linejoin |
Controls how connected path segments join. |
stroke-dasharray |
Defines repeating dash and gap lengths. |
stroke-dashoffset |
Offsets the starting position of the dash pattern. |
stroke-miterlimit |
Limits the extension of sharp miter joins. |
paint-order |
Controls the painting order of fill, stroke, and markers. |
Dashed Stroke
.dashed-outline {
fill: none;
stroke: #2563eb;
stroke-width: 4;
stroke-dasharray: 10 5;
}
Creates a blue outline with repeating dashes and gaps.
Rounded Line Ends
.rounded-line {
fill: none;
stroke: #0d9488;
stroke-width: 8;
stroke-linecap: round;
}
Creates rounded endpoints on an open SVG path.
Rounded Corners
.rounded-corners {
fill: none;
stroke: #a855f7;
stroke-width: 8;
stroke-linejoin: round;
}
Rounds the joins between connected path segments.
Important Consideration
These properties modify stroke geometry, transparency, or painting order. The stroke property continues to determine the paint used for the outline.
CSS Property vs. SVG Attribute
SVG supports stroke as both a CSS property and a presentation attribute.
SVG Presentation Attribute
<circle cx="60" cy="60" r="40" stroke="#2563eb" stroke-width="4"/>
The stroke color is declared directly on the SVG element.
CSS Property
<circle class="outlined-circle" cx="60" cy="60" r="40"/>
.outlined-circle {
fill: none;
stroke: #2563eb;
stroke-width: 4;
}
The stroke is controlled through a stylesheet.
CSS Cascade
SVG presentation attributes participate in the CSS cascade with lower priority than ordinary author CSS declarations.
CSS Override Example
<circle class="outlined-circle" cx="60" cy="60" r="40" stroke="red"/>
.outlined-circle {
stroke: blue;
}
The CSS declaration overrides the presentation attribute, so the circle uses a blue stroke.
Inheritance
.icon-group {
fill: none;
stroke: #2563eb;
stroke-width: 3;
}
Child SVG shapes can inherit the stroke paint and width from a parent SVG group unless they define their own values.
Important Consideration
Use presentation attributes for simple, self-contained SVG graphics or CSS when stroke styles need to be shared, updated, or animated.
Animating Stroke Colors
Solid stroke colors can be animated using CSS transitions or keyframes.
CSS Transition
.interactive-icon path {
stroke: #2563eb;
transition: stroke 0.3s ease;
}
.interactive-icon:hover path {
stroke: #ec4899;
}
The path outline transitions from blue to pink when the SVG is hovered.
CSS Keyframe Animation
@keyframes stroke-color-change {
0% {
stroke: #2563eb;
}
50% {
stroke: #a855f7;
}
100% {
stroke: #0d9488;
}
}
.animated-outline {
animation: stroke-color-change 4s ease-in-out infinite;
}
The stroke color changes between blue, purple, and teal.
Hover With currentColor
.interactive-icon {
color: #2563eb;
transition: color 0.3s ease;
}
.interactive-icon:hover {
color: #ec4899;
}
.interactive-icon path {
stroke: currentColor;
}
Animating the inherited color property also changes strokes that use currentColor.
Reduced Motion
@media (prefers-reduced-motion: reduce) {
.interactive-icon,
.interactive-icon path,
.animated-outline {
animation: none;
transition: none;
}
}
Respect reduced-motion preferences when stroke animations are decorative.
Important Consideration
Solid colors can interpolate smoothly. Transitions between unrelated paint types, such as a solid color and an SVG gradient reference, generally do not interpolate as a continuous color transition.
Practical Examples
Simple SVG Outline
.basic-outline {
fill: none;
stroke: #2563eb;
stroke-width: 3;
}
Creates a blue outline without an interior fill.
Filled Shape With Outline
.filled-outline {
fill: #dbeafe;
stroke: #1d4ed8;
stroke-width: 4;
}
Combines a light blue fill with a darker blue outline.
Icon Using currentColor
.outline-icon {
color: #0d9488;
}
.outline-icon path {
fill: none;
stroke: currentColor;
stroke-width: 2;
}
Allows an SVG icon to follow its inherited text color.
Dashed Outline
.dashed-shape {
fill: none;
stroke: #a855f7;
stroke-width: 4;
stroke-dasharray: 8 4;
}
Creates a purple dashed outline.
Semi-Transparent Outline
.soft-outline {
fill: none;
stroke: #2563eb;
stroke-width: 6;
stroke-opacity: 0.4;
}
Creates a partially transparent blue outline.
Gradient Outline
.gradient-outline {
fill: none;
stroke: url(#outlineGradient) #2563eb;
stroke-width: 6;
}
Uses an SVG gradient with a solid color fallback.
Hover Color Change
.hover-outline {
fill: none;
stroke: #2563eb;
stroke-width: 4;
transition: stroke 0.3s ease;
}
.hover-outline:hover {
stroke: #ec4899;
}
Changes the stroke color on hover.
Remove an Outline
.no-outline {
stroke: none;
}
Disables stroke painting.
Reset to the Initial Value
.reset-outline {
stroke: initial;
}
Resets the stroke to none.
stroke Example
This example compares four SVG shapes using different stroke colors and styles. Each shape demonstrates how the stroke property works with related stroke properties.
HTML Example
<div class="stroke-demo">
<svg viewBox="0 0 600 180" role="img" aria-label="Four outlined SVG shapes with blue, teal, purple dashed, and pink strokes">
<circle class="stroke-blue" cx="75" cy="85" r="45"/>
<rect class="stroke-teal" x="185" y="40" width="90" height="90" rx="12"/>
<circle class="stroke-purple" cx="375" cy="85" r="45"/>
<path class="stroke-pink" d="M485 125 L530 40 L575 125"/>
</svg>
</div>
CSS Example
.stroke-demo svg {
display: block;
width: 100%;
height: auto;
}
.stroke-demo .stroke-blue {
fill: #dbeafe;
stroke: #2563eb;
stroke-width: 6;
}
.stroke-demo .stroke-teal {
fill: none;
stroke: #0d9488;
stroke-width: 8;
}
.stroke-demo .stroke-purple {
fill: none;
stroke: #a855f7;
stroke-width: 6;
stroke-dasharray: 12 6;
}
.stroke-demo .stroke-pink {
fill: none;
stroke: #ec4899;
stroke-width: 8;
stroke-linecap: round;
stroke-linejoin: round;
}
The blue circle has a filled interior, the teal rectangle has only an outline, the purple circle uses a dashed stroke, and the pink path has rounded endpoints and joins.
Comparing the Shapes
| Shape | Stroke Color | Additional Styling |
|---|---|---|
| Circle | Blue | Light blue fill |
| Rectangle | Teal | No fill, thick outline |
| Circle | Purple | Dashed outline |
| Path | Pink | Rounded endpoints and joins |
Changing the Blue Stroke
.stroke-demo .stroke-blue {
stroke: #dc2626;
}
Changes the blue circle outline to red.
Changing the Teal Stroke Width
.stroke-demo .stroke-teal {
stroke-width: 12;
}
Increases the rectangle's outline thickness.
Changing the Dashed Stroke
.stroke-demo .stroke-purple {
stroke-dasharray: 4 4;
}
Creates shorter dashes and gaps around the purple circle.
Making the Pink Stroke Transparent
.stroke-demo .stroke-pink {
stroke-opacity: 0.4;
}
Reduces the opacity of the pink outline to 40%.
Accessibility Considerations
SVG strokes often define the visible boundaries of icons, diagrams, charts, and other graphics. Their appearance should remain clear and distinguishable.
Maintain Sufficient Contrast
Important stroke outlines should have adequate contrast against adjacent colors and backgrounds. Thin, low-contrast outlines can be difficult to see.
Avoid Color-Only Communication
Do not rely solely on stroke colors to communicate status or meaning. Use labels, patterns, or other visual distinctions when necessary.
Use Appropriate Stroke Widths
Very thin strokes may become difficult to distinguish on small screens or at certain zoom levels. Choose widths that remain visible.
Provide Accessible SVG Names
Informative SVG graphics should have an accessible name or an equivalent text description.
<svg viewBox="0 0 100 100" role="img" aria-label="Blue outlined circle">
<circle cx="50" cy="50" r="35" fill="none" stroke="blue" stroke-width="4"/>
</svg>
Decorative Graphics
Purely decorative SVG graphics can use aria-hidden="true" to avoid unnecessary announcements.
Respect Reduced Motion
When stroke colors or dash patterns are animated, provide a reduced-motion alternative where appropriate.
Test Different Themes
Verify that stroke colors remain visible against light and dark backgrounds.
Consider Color Vision Differences
Use differences in line style, shape, or labeling when multiple stroke colors represent distinct categories.
Common Mistakes
Using stroke as a Border Shorthand
svg rect {
stroke: 5px solid blue;
}
The stroke property is not equivalent to the CSS border shorthand. Set the paint and width separately.
svg rect {
stroke: blue;
stroke-width: 5;
}
Forgetting stroke-width
The default stroke width is 1. A stroke may appear too thin unless an appropriate width is specified.
Using CSS Gradient Functions Directly
svg path {
stroke: linear-gradient(red, blue);
}
CSS gradient functions are not valid direct stroke paint values. Use an SVG gradient referenced with url().
Confusing stroke With fill
The stroke property paints the outline, while fill paints the interior.
Forgetting fill: none
SVG shapes are filled black by default. When creating outline-only icons, use fill: none if the interior should remain unpainted.
Using Invalid Width Values
svg path {
stroke: 10px;
}
A length is not a valid standalone stroke value. Use stroke-width for thickness.
Using stroke: none When Transparency Is Intended
The value none disables stroke painting. Use a transparent color or stroke-opacity: 0 when a transparent stroke paint is required.
Ignoring Stroke Clipping
Thick strokes can extend beyond the SVG viewport and become clipped. Leave enough space around shapes.
Forgetting Inheritance
The stroke property is inherited. A stroke assigned to an SVG group can affect descendant shapes unless they override it.
Using Duplicate Paint Server IDs
Gradient and pattern IDs should be unique within the document to avoid incorrect paint references.
Important Considerations
Keep the following points in mind when using stroke:
- It specifies the paint used for SVG outlines.
- The initial value is
none. - The property is inherited.
- It applies to applicable SVG elements, including shapes, paths, and text.
- It accepts valid CSS colors and supported SVG paint sources.
- The
currentColorkeyword allows strokes to follow text color. - The
url()function can reference SVG gradients and patterns. - A fallback color can follow a paint server reference.
- CSS gradient functions cannot be assigned directly to
stroke. - The
stroke-widthproperty controls outline thickness. - The default stroke width is
1. - A stroke width of zero produces no visible outline.
- Strokes are centered on their paths by default.
- Thick strokes may be clipped at SVG viewport boundaries.
- The
fillproperty independently controls interior paint. - The
stroke-opacityproperty controls stroke transparency. - Stroke dash patterns are controlled by
stroke-dasharrayandstroke-dashoffset. - Line caps and joins are controlled by separate stroke properties.
- SVG presentation attributes and CSS declarations can both define strokes.
- Ordinary author CSS declarations can override presentation attributes.
- Solid stroke colors can be animated.
- Gradient and pattern references should use unique IDs.
- Important outlines should remain visible against their backgrounds.
- Test stroke appearance across supported browsers and display sizes.
Browser Support
The CSS stroke property is widely supported for SVG graphics in modern browsers, including Chrome, Edge, Firefox, and Safari.
Basic solid colors, none, currentColor, and SVG gradient or pattern references are broadly supported. Advanced paint values such as context-fill and context-stroke may have more limited compatibility.
For current compatibility information, visit Can I Use? and search for stroke.
Feature Detection
@supports (stroke: #2563eb) {
.outlined-shape {
stroke: #2563eb;
}
}
Feature queries can test whether a browser recognizes the property and value syntax.
Fallback Behavior
If a declaration is invalid or unsupported, the browser ignores it. The element uses another applicable value from the cascade or the inherited stroke value, falling back to none when no other value applies.
Testing Recommendations
Test solid colors, gradient references, inherited strokes, stroke widths, and animations in the browsers you support.
Specifications
The stroke property is defined in the SVG 2 specification.
The specification defines how stroke paint is selected and applied to SVG graphics.
For additional documentation and examples, consult MDN Web Docs.
