arrow_back
Back

Drawing rectangles

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

A rectangle is represented in SVG by the <rect> element.

Attributes:

  • width.
  • height.
  • x.
  • y.
  • rx.
  • ry.
  • fill - color name or a hex color value.
  • stroke - color of the border line.
  • stroke-width - thickness of the border line.
<rect width="100" height="200" />

Offset in pixels:

<rect x="20" y="20" width="100" height="200" />

Offset in %:

<rect x="10%" y="10%" width="80%" height="80%" />

Fill the rectangle with a blue color and add a black stroke:

<rect 
    x="20" 
    y="20" 
    width="100" 
    height="200" 
    fill="blue" 
    stroke="black" 
    stroke-width="3" />

Rounded corners

<rect x="10" y="10" width="100" height="200" rx="5" ry="10" />
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Drawing circles

arrow_forward