SVG Rectangle (original) (raw)

Last Updated : 28 Apr, 2025

SVG Rectangle is used in HTML is used to make rectangles. There is an element which is wrapped inside the element. Element has various attributes like rx and ry which are used to make the corners round of the rectangle. There is a width and height attribute that defines the size of the rectangle.

Syntax

Attributes

Example 1: In this example, we will see the SVG Rectangle with rounded corners using rx and ry attributes.

HTML `

SVG Rectangle

GeeksforGeeks

SVG Rectangle

<svg width="200" 
     height="200">
    <rect x="25" 
          y="25"
          rx="15" 
          ry="15" 
          width="150" 
          height="150" 
          stroke="green"
          stroke-width="3"
          fill="rgb(205, 250, 137)">
      </rect>
</svg>

`

Output:

svgt

SVG Rectangle

Example 2: In this example, we will see the SVG Rectangle with opacity.

HTML `

SVG Rectangle

GeeksforGeeks

SVG Rectangle with opacity

<svg width="250" 
     height="250">
    <rect x="10%"
          y="10%" 
          width="200" 
          height="200"
          stroke="green" 
          stroke-width="5"
          fill="yellow" 
          opacity="0.4">
    </rect>
</svg>

`

Output:

opacty

Fill rectangle with opacity