HTML Academy
Challenge: Rainbow
Dimensions in SVG12/15
Back to the list of tasks
  • 1. SVG Width and Height
  • 2. The viewBox Attribute
  • 3. viewBox and Dimensions
  • 4. Challenge: Fish
  • 5. The preserveAspectRatio Attribute
  • 6. Flexible Background with preserveAspectRatio
  • 7. Challenge: Flexible Margins
  • 8. Alignment in preserveAspectRatio
  • 9. preserveAspectRatio and viewBox
  • 10. Filling the Space
  • 11. Challenge: Rainbow
  • 12. Units
  • 13. Coordinate systems
  • 14. Coordinate Systems and Transforms
  • 15. Challenge: Yellow Leaf
Coordinate systems
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Units

In order to basically use SVG, all you need to understand is how outer dimensions work. But to create more complex designs, you need to understand how inner dimensions work.

You can use different units in SVG, such as, for example: px, em, ex, pt, pc, cm, mm, in, and percent.

There are also coordinate system units, or user space units, which by default correspond to pixels, so you can omit the units for dimensions and coordinates if you are using pixels.

Comments

  • object.svg
  • style.css
SVG
<svg viewBox="0 0 250 250" preserveAspectRatio="xMidYMid meet" width="250" height="400"> <circle r="100" cx="125" cy="125" fill="gold" stroke="yellowgreen" stroke-width="10"/> </svg>
CSS
svg { border: 2px solid teal; }

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. Experiment with stroke-width: for the circle, try setting it using percentages, millimeters, or em.

    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.