Open In App

SVG RectElement.width Property

Last Updated : 30 Mar, 2022
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

The SVG RectElement.width property returns an SVGAnimatedLength corresponding to the attribute of the given rectangle element.

Syntax:

RectElement.width

Return Values: This property returns SVGAnimatedLength object that can be used get the width of the rect element

Example 1: 

HTML
<!DOCTYPE html>
<html>

<body>
    <svg width="350" height="150" 
        xmlns="http://www.w3.org/2000/svg">
        
        <rect width="100" height='100' 
            fill="green" id="gfg" x=20 y=40 />
            
        <script>
            var g = document.getElementById("gfg");
            console.log(g.width)
        </script>
    </svg>
</body>

</html>

Output:

Example 2: 

HTML
<!DOCTYPE html>
<html>

<body>
    <svg width="350" height="150" 
        xmlns="http://www.w3.org/2000/svg">
        
        <rect width="190" height='100' 
            fill="green" id="gfg" x=20 y=40 />
            
        <script>
            var g = document.getElementById("gfg");
            console.log(g.width)
        </script>
    </svg>
</body>

</html>

Output:


Next Article

Similar Reads