SVG Stroke Properties
Last Updated :
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...