XML technologies / SVG / Creating simple SVG graphics / SVG tag syntax / The rect tag

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

The <rect> tag defines a rectangle. Besides the previously explained attributes id, width, height, x and y, it has the attributes rx and ry.

Note:
rx and ry abbreviate radius x and radius y. These will appear again when discussing curves and circles.

Both attributes matter only for rounded rectangle corners. They specify the radii of an imaginary ellipse determining how rounded the corners are. These attributes are optional: omitting them or setting them to 0 leaves the corners square.

The following figure shows two rectangles created with <rect>. In one, the attributes rx and ry are set to 8 to round the corners. In the other, both have the value 0.

Rectangle with square and rounded corners

Figure: Rectangle with square and rounded corners.

<?xml version="1.0" standalone="no"?>
...
<svg width="300" height="300">
  <rect x="10" y="20" width="100" height="50" rx="0" ry="0"/>
  <rect x="150" y="20" width="100" height="50" rx="8" ry="8"/>
</svg>

Note:
There is no separate tag for squares. To create one, use the <rect> tag and set the attributes width and height to the same value.

   

 

 

 

back to top