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: 

  • stroke: set the stroke to an element.
  • stroke-width: set the stroke width of an element.
  • stroke-linecap: sets the ending stroke style.
  • stroke-dasharrray: set the style os a stroke such as dashed stroke.

Few examples are given below: 

Example 1: Stroke and stroke-dasharray property:



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

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

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

Supported Browsers : 

  • Chrome
  • Edge
  • Opera
  • Internet Explorer
  • Safari
  • Firefox

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.