Open In App

SVG Stroke Properties

The SVG offers several stroke properties to be applied to the SVG element. There are lots of properties under stroke properties which can be applied any kind of lines, text, and outlines of elements like a circle.

Syntax:



<elementName stroke="stroke color"
      stroke-width="Width of the stroke"
      stroke-linecap="Ending style to a stroke"
      stroke-dasharray="make a dashed stroke">

Property value: 

Few examples are given below: 



Example 1: Stroke and stroke-dasharray property:




<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" 
        content="width=device-width, initial-scale=1.0">
  <title>Stroke and stroke-dasharray property</title>
</head>
<style>
  svg{
    background-color: green;
  }
</style>
<body
    
<p>stroke: </p>
  
  <svg width="100px" height="100px">
      <circle cx="50" cy="50" r="40" 
              stroke="yellow"/>
  </svg>
    
<p>stroke-dasharray: </p>
  
  <svg width="100px" height="100px">
      <circle cx="50" cy="50" r="40"
              stroke-dasharray=5 
              stroke="yellow"/>
  </svg>
</body>
</html>

Output:

Example 2: stroke-width and stroke-linecap property: 




<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" 
        content="width=device-width, initial-scale=1.0">
  <title>stroke-width and stroke-linecap property</title>
</head>
<style>
  svg{
    background-color: green;
  }
  .cls{
    display: flex;
  }
  .cl{
    margin:40px;
  }
</style>
<body
  <div class="cls">
    <div class="cl">
        
<p>stroke-width: </p>
  
      <svg width="100px" height="100px">
          <circle cx="50" cy="50" r="40" 
                  stroke-width=5 
                  stroke="yellow"/>
      </svg>
    </div>
    <div class="cl">
        
<p>stroke-linecap: round </p>
  
      <svg width="100px" height="100px">
          <circle cx="50" cy="50" r="40" 
                  stroke-width=5 
                  stroke-linecap="round" 
                  stroke-dasharray=5
                  stroke="yellow"/>
      </svg>
    </div>
    <div class="cl">
        
<p>stroke-linecap:square </p>
  
      <svg width="100px" height="100px">
          <circle cx="50" cy="50" r="40" 
                  stroke-width=3 
                  stroke-linecap="square" 
                  stroke-dasharray=5 
                  stroke="yellow"/>
      </svg>
    </div>
  </div>
</body>
</html>

Output:

Supported Browsers : 


Article Tags :