Skip to content
Justice Tech School

Gradients

Gradients are generated images, used with background or background-image. linear-gradient(direction, colour stops) blends along a line; radial-gradient() blends outward from a centre point. conic-gradient() sweeps around a point.

Add stops with positions like red 0%, gold 60%. Two stops at the same position make a hard edge, which is useful for stripes.

Linear and radial

Example
<style>
  div { height: 90px; margin-bottom: 10px; border-radius: 8px; }
  .lin { background: linear-gradient(to right, #f97316, #ec4899); }
  .rad { background: radial-gradient(circle at center, #fde047, #ea580c); }
</style>
<div class="lin"></div>
<div class="rad"></div>

Hard stripes

Example
<style>
  .stripes {
    height: 90px;
    background: repeating-linear-gradient(45deg, #0f766e 0 15px, #5eead4 15px 30px);
  }
</style>
<div class="stripes"></div>

Exercise

Create a gradient that goes to the right.

.bar {
  background: linear-gradient(to , red, blue);
}

Quiz Test

Where can a gradient be used?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.