Tsallaka zuwa abun ciki
Justice Tech School

Colours

Colours can be names (tomato), hex codes (#16a34a), rgb() or hsl() values. Hex uses red, green and blue pairs; rgb(22, 163, 74) is the same colour in decimal. hsl(hue, saturation, lightness) is often easier to tweak by hand, with hue as an angle from 0 to 360.

Use color for text and background-color for the area behind it. Add transparency with rgb(0 0 0 / 50%) or hsl(200 80% 40% / 0.5). Always check that text has enough contrast with its background.

Example
<style>
  div { padding: 12px; margin: 6px 0; color: white; }
  .a { background: tomato; }
  .b { background: #166534; }
  .c { background: rgb(37, 99, 235); }
  .d { background: hsl(280, 70%, 40%); }
  .e { background: rgb(0 0 0 / 50%); }
</style>
<div class="a">Named</div>
<div class="b">Hex</div>
<div class="c">RGB</div>
<div class="d">HSL</div>
<div class="e">Half transparent black</div>

Exercise

Set the background colour.

body {
  : lightyellow;
}

Quiz Test

Which is a valid hex colour?

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