SVG Rectangle
How to Draw a Rectangle?
The <rect>
SVG element that draws rectangles, defined by their position, width, and height.
In this example, we will draw a basic rectangle, defined by the width and the height by using <rect>
SVG element.
Example
How to Custom a Rectangle
In this example, we will customize a rectangle using fill
, stroke-width
, and stroke
SVG attributes.
Note: These SVG attributes can also be used as CSS properties.
Rectangle with Position and Radius
SVG allows us to control the position of the element with x and y attributes and it allows us the control the radius of the element by rx and ry attributes.
In this example, we will control the position and radius of the rectangle by x
, y
, rx
, and ry
SVG attributes
Example
Rectangle with Specific Opacity
SVG allows us to control the opacity of fill
and stroke
attributes separately.
fill-opacity - Controls the opacity of fill
attribute.
stroke-opacity - Controls the opacity of stroke
attribute.
In this example, we will control the opacity of fill
and stroke
SVG attributes separately using fill-opacity
and stroke-opacity
SVG attributes
Example
Rectangle with Common Opacity
Use SVG opacity
attribute to control the opacity of an object or of a group of objects.
In this example, we will control the opacity of rect
SVG element using opacity
SVG attribute.
Example
Attributes Value
Attribute | Explanation |
---|---|
x | x-axis co-ordinate of top left of the rectangle. Default is 0. |
y | y-axis co-ordinate of top left of the rectangle. Default is 0. |
rx | Specifies the horizontal corner radius of the rectangle. |
ry | Specifies the vertical corner radius of the rectangle. |
Reminder
Hi Developers, we almost covered 91% of SVG Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in SVG.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.