HTML Academy
Hello, SVG!
An Introduction to SVG2/15
Back to the list of tasks
  • 1. Hello, SVG!
  • 2. Drawing a Rectangle
  • 3. Rectangle Coordinates
  • 4. Corner Rounding
  • 5. Challenge: Fixing the TV
  • 6. Polygons
  • 7. Challenge: Pyramids
  • 8. Drawing a Circle
  • 9. Challenge: Target
  • 10. Drawing an Ellipse
  • 11. Challenge: Surprised Smiley
  • 12. Drawing Lines
  • 13. Challenge: Arithmetic Operators
  • 14. Drawing Polylines
  • 15. Challenge: Hot-Air Balloons
Rectangle Coordinates
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Drawing a Rectangle

There are several ways to draw a shape in SVG, where simple shapes have their own tags.

For example, you can draw a rectangle using the rect tag. The code for a simple rectangle looks like this:

<rect width="150" height="100"/>

Please note: All of the tags in the SVG must be closed. That is, they should look like this: <rect .../> or like this: <rect ...></rect>. We will use the first method.

Result:

The width and height attributes control the shape’s width and height, respectively. Values can be specified either using pixels or percentages.

For pixel values, you do not need to write px after the value, because pixels are the default unit of measurement in SVG. Percentages are calculated relative to the dimensions of the entire SVG image, where horizontal values are relative to width and vertical values are relative to height.

In modern browsers, the size and position of shapes cannot be controlled via CSS, but this will be possible in the future.

Comments

  • object.svg
  • style.css
SVG
<svg> </svg>
CSS
svg { border: 1px solid #dddddd; }

What didn’t you like in this task?

Thanks! We’ll fix everything at once!

The code has changed, click “Refresh” or turn autorun on.

You’ve gone to a different page

Click inside the mini-browser to shift the focus onto this window.

100%
Goalscompleted
0
    1. Draw a rectangle with a width of 50% and a height of 100.
    2. Add orange fill by specifying fill="orange".

    Cookies ∙ Privacy ∙ License Agreement ∙ About ∙ Contacts ∙ © HTML Academy OÜ, 2019−2025

    VISAMastercard

    Log in

    or

    Forgot your password?

    Sign up

    Sign up

    or
    Log in

    Restore access

    Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.

    Forgot to connect your email to the profile? Email us and we’ll help.