Skip to content
Related Articles

Related Articles

Improve Article

SVG width Attribute

  • Last Updated : 15 Oct, 2020

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" 
        xmlns="http://www.w3.org/2000/svg">
          
        <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" 
        xmlns="http://www.w3.org/2000/svg">
          
        <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:

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :