HTML Academy
Semi-Transparent Gradients
Linear Gradients14/23
Back to the list of tasks
  • 1. Hello, linear-gradient!
  • 2. Gradient Direction
  • 3. Diagonal Gradients
  • 4. Gradients at an Angle
  • 5. Diagonals vs. Degrees
  • 6. Challenge: Application Icons
  • 7. Uniform Multicolor Gradient
  • 8. Color Proportions and Color Stops
  • 9. Sharp Color Transitions
  • 10. Pseudo-Columns on Gradients
  • 11. Challenge: Flags
  • 12. Color Transitions in px
  • 13. Semi-Transparent Gradients
  • 14. Repeating Linear Gradient
  • 15. Creating a Complex Background – Part 1
  • 16. Creating a Complex Background – Part 2
  • 17. Creating a Complex Background – Part 3
  • 18. Let’s Create a Complex Background – Final Step
  • 19. Buttons – Part 1
  • 20. Buttons – Part 2
  • 21. Buttons – Part 3
  • 22. Challenge: Ornament Made of Shurikens
  • 23. Challenge: Satellites
Creating a Complex Background – Part 1
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Repeating Linear Gradient

In addition to the usual gradients, we have ones that are repeating as well. Their syntax is exactly the same as the syntax used for ordinary gradients, only instead of linear-gradient, you write repeating-linear-gradient. A repeating gradient is good for creating striped backgrounds or ornamental backgrounds using CSS.

There are a few things to know about repeating gradients:

  1. The fragment size is determined by the last color stop. For the repetition to be visible, the last color stop must be smaller than the size of the element with the gradient.
  2. If the first and last gradient colors are different, you will see sharp boundaries between the repeating fragments. To get rid of them, you need to set the same first and last colors.
  3. Color stops in repeating gradients are usually specified in pixels, but percentages may also be used.

By the way, instead of repeating gradients, you can use regular gradients in combination with the background-size and background-repeat properties. But repeating gradients are easier to use and require less code.

In this assignment, we will create repeating gradients from regular gradients. Pay attention to the size of the fragments. For example, exactly four fragments will fit into the first two blocks.

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <title>Repeating Linear Gradient</title> <meta charset="utf-8"> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <div class="box gradient-1"></div> <div class="box gradient-2"></div> <div class="box gradient-3"></div> <div class="box gradient-4"></div> </div> </body> </html>
CSS
html, body { margin: 0; padding: 0; } .container { margin: 20px auto; width: 440px; height: 440px; } .box { float: left; margin: 10px; width: 200px; height: 200px; box-shadow: 0 0 3px #666666; } /* The simplest option, which will create sharp boundaries when repeated */ .gradient-1 { background-image: linear-gradient(black 0, green 25px, yellow 50px); } /* Added sharp transitions inside the gradient. When repeated, we get stripes */ .gradient-2 { background-image: linear-gradient(black 0, black 17px, green 17px, green 33px, yellow 33px, yellow 50px); } /* Avoid sharp transitions when it is repeated */ .gradient-3 { background-image: linear-gradient(black 0, green 25px, yellow 50px, black 75px); } /* Color stops specified as percentages; two repeats will always fit in a block regardless of its size */ .gradient-4 { background-image: linear-gradient(black 0, green 25%, yellow 50%); }

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

    Change the linear gradient to a repeating one for the four blocks.

    1. First block.
    2. Second block.
    3. Third block.
    4. Fourth block.

    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.