Tsallaka zuwa abun ciki
Justice Tech School

Backgrounds

background-color fills the area behind an element, including its padding. The background shorthand can combine colour, image, repeat, position and size in one declaration.

Backgrounds sit behind text, so pick a colour with strong contrast. You can layer several backgrounds by separating them with commas; the first one is on top.

Example
<style>
  .card {
    background-color: #fef3c7;
    color: #78350f;
    padding: 20px;
    border-radius: 8px;
  }
  .layered {
    background: linear-gradient(rgba(255,255,255,0.4), rgba(255,255,255,0.4)), #0ea5e9;
    padding: 20px;
  }
</style>
<div class="card">Solid background</div>
<br>
<div class="layered">Two backgrounds layered</div>

Exercise

Use the background property to set a plain colour.

.card {
  : #eee;
}

Quiz Test

Which area does background-color fill?

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