SVG Stroke Properties - GeeksforGeeks

07 Aug, 2020
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
<!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: 
HTML
<!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 : 
Chrome
Edge
Opera
Internet Explorer
Safari
Firefox
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Types of CSS (Cascading Style Sheet)
HTML | <img> align Attribute
Form validation using HTML and JavaScript
HTML Introduction
How to Upload Image into Database and Display it using PHP ?
Express.js express.Router() Function
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
Top 10 Angular Libraries For Web Developers
How to create footer to stay at the bottom of a Web page?