SVG Stroke attribute


Release date:2023-12-08 Update date:2023-12-08 Editor:admin View counts:92

Label:

SVG Stroke attribute

SVG Stroke attribute

SVG provides a wide range of stroke property. In this chapter, we will look at the following:

  • stroke

  • stroke-width

  • stroke-linecap

  • stroke-dasharray

All stroke attributes that can be applied to any kind of lines, text and elements are like the outline of a circle.

SVG stroke attribute

Stroke property defines a line, text, or element outline color:

Here is the SVG code:

Example

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <g fill="none">
    <path stroke="red" d="M5 20 l215 0" />
    <path stroke="blue" d="M5 40 l215 0" />
    <path stroke="black" d="M5 60 l215 0" />
  </g>
</svg>

SVG stroke-width attribute

Tstroke- width property defines a line, text, or element outline thickness:

Here is the SVG code:

Example

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <g fill="none" stroke="black">
    <path stroke-width="2" d="M5 20 l215 0" />
    <path stroke-width="4" d="M5 40 l215 0" />
    <path stroke-width="6" d="M5 60 l215 0" />
  </g>
</svg>

SVG stroke-linecap attribute

strokelinecap property defines the end of different types of open paths:

Here is the SVG code:

Example

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <g fill="none" stroke="black" stroke-width="6">
    <path stroke-linecap="butt" d="M5 20 l215 0" />
    <path stroke-linecap="round" d="M5 40 l215 0" />
    <path stroke-linecap="square" d="M5 60 l215 0" />
  </g>
</svg>

SVG stroke-dasharray attribute

strokedasharray property is used to create dashed lines:

Here is the SVG code:

Example

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <g fill="none" stroke="black" stroke-width="4">
    <path stroke-dasharray="5,5" d="M5 20 l215 0" />
    <path stroke-dasharray="10,10" d="M5 40 l215 0" />
    <path stroke-dasharray="20,10,5,5,5,10" d="M5 60 l215 0" />
  </g>
</svg>

Powered by TorCMS (https://github.com/bukun/TorCMS).