CSS stroke-width Property


The CSS stroke-width property specifies the width of the stroke on the element.

The presentation attribute will be overridden: e.g. <path stroke-width=”3px” … />. The inline style won’t be overridden: e.g. <path style=”stroke-width: 3px;” … />.

Initial Value1
Applies toShapes and text content elements.
InheritedYes.
AnimatableNo.
VersionSVG 1.1 Specification
DOM SyntaxObject.strokeWidth = “0.5”;

Syntax

stroke-width: length | percentage | initial | inherit;

Example of the stroke-width property:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <h2>Stroke-width property example</h2>
    <svg viewBox="0 0 30 10">
      <circle cx="5" cy="5" r="3" stroke="#1c87c9" stroke-width="1" />
    </svg>
  </body>
</html>

Result

CSS stroke-width

Example of the stroke-width property with the “length” value:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <h2>Stroke-width property example</h2>
    <svg viewBox="0 0 30 10">
      <circle cx="5" cy="5" r="3" stroke="#1c87c9" stroke-width="3" />
    </svg>
  </body>
</html>

Example of the stroke-width property with the “%” value:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <h2>Stroke-width property example</h2>
    <svg viewBox="0 0 30 10">
      <circle cx="5" cy="5" r="3" stroke="#1c87c9" stroke-width="2%" />
    </svg>
  </body>
</html>

Values

ValueDescription
lengthSpecifies the width of the stroke.
percentageSpecifies the width of the stroke in %.
initialMakes the property use its default value.
inheritInherits the property from its parents element.

Leave a Reply

Your email address will not be published. Required fields are marked *