SVG width Attribute
Last Updated :
31 Mar, 2022
The width attribute defines the vertical length of an element.
Syntax:
width= "width"
Attribute Values:
- length: Length at which we want to set the width attribute.
- percentage: Percentage at which we want to set the width attribute.
We will use the width attribute for setting the width of the element.
Example 1: In this example we will use the width attribute for setting the width of rect using length value.
<!DOCTYPE html>
< html >
< body >
< svg viewBox = "0 0 900 300"
< rect y = "45" x = "45" width = "30"
height = "20" fill = "green" />
< rect y = "90" x = "45" width = "30"
height = "20" fill = "green" />
</ svg >
</ body >
</ html >
|
Output:
Example 2: In this example we will use the height attribute for setting the height of rect using percentage value.
<!DOCTYPE html>
< html >
< body >
< svg viewBox = "0 0 900 300"
< rect y = "45" x = "45" width = "30%"
height = "10%" fill = "green" />
< rect y = "90" x = "45" width = "30%"
height = "10%" fill = "green" />
</ svg >
</ body >
</ html >
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...