SVG width Attribute
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 > |
chevron_right
filter_none
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 > |
chevron_right
filter_none
Output: