HTML Academy
Challenge: Zigzags
Designing SVG Shapes12/20
Back to the list of tasks
  • 1. Fills
  • 2. Fill Opacity
  • 3. No Fill
  • 4. Challenge: Colorful Squares
  • 5. Strokes
  • 6. Stroke Width
  • 7. Stroke Opacity
  • 8. Challenge: Stroke Width and Transparency
  • 9. Line Ends
  • 10. Bend Type
  • 11. Challenge: Zigzags
  • 12. Dashed Lines, Part 1
  • 13. Dashed Lines, Part 2
  • 14. Challenge: Sunrise
  • 15. Life Saver, Part 1
  • 16. Life Saver, Part 2
  • 17. Life Saver, Part 3
  • 18. Life Saver, Part 4
  • 19. Stroke Offset
  • 20. Challenge: Lollypop
Dashed Lines, Part 2
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Dashed Lines, Part 1

In SVG, you can control the appearance of dashed lines by using the stroke-dasharray attribute. The length of the lines and the spaces between them is assigned as the value. You can specify one number. In this case, you get a dashed line consisting of lines and spaces of the same length:

1. stroke-dasharray="15":

2. If you set two numbers stroke-dasharray = "50 10", the first will control the length of the lines, and the second will control the length of the spaces:

3. The sequence can be continued: stroke-dasharray = "1 2 3 5 8 13 21". In this case, you get a dashed line with a complicated rhythm:

The CSS property stroke-dasharray works in the same way.

Comments

  • object.svg
  • style.css
SVG
<svg width="300" height="200"> <line x1="40" y1="50" x2="260" y2="50" stroke-width="10" stroke="tomato"></line> <line x1="40" y1="100" x2="260" y2="100" stroke-width="20" stroke="gold"></line> <line class="shape-dasharray" x1="40" y1="150" x2="260" y2="150" stroke-width="20" stroke="lightseagreen"></line> </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. Assign the attribute stroke-dasharray="10" to the first line,
    2. and then assign the value 50 15 to the second line.
    3. In the CSS, assign the value 5 10 15 20 to the stroke-dasharray property for the third line.

    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.