</> ConvertAtlas Developer Tools
Level 1 · Beginner — CSS Foundations Lesson 4 Beginner 12 min

Colors and Backgrounds

Colour text and backgrounds with named, hex, rgb and hsl values — and add gradients.

Colour is the fastest way to make a page feel designed. CSS gives you several ways to express colour and to fill element backgrounds. Let us make things colourful.

Colour formats

Named colours like <code>tomato</code> are simplest. Hex codes like <code>#2563eb</code> are most common in real projects. <code>rgb()</code> mixes red/green/blue, and <code>hsl()</code> uses hue, saturation and lightness — the easiest to tweak.

HTML
<p class="a">Named</p>
<p class="b">Hex</p>
<p class="c">RGB</p>
<p class="d">HSL</p>
CSS
.a{color:crimson}
.b{color:#2563eb}
.c{color:rgb(16,185,129)}
.d{color:hsl(280,70%,50%)}
Result
Four ways to write a colour.

Background colour

The <code>background-color</code> property fills an element behind its content. With padding and rounded corners it becomes a card, badge or button.

HTML
<span class="badge">New</span>
CSS
.badge{background-color:#2563eb;color:#fff;padding:6px 14px;border-radius:999px}
Result
A pill badge from background + padding + radius.

Gradients

The <code>background</code> property can hold a gradient with <code>linear-gradient()</code> — a smooth blend between colours, great for hero sections and buttons.

HTML
<div class="hero">Gradient</div>
CSS
.hero{background:linear-gradient(135deg,#7c3aed,#2563eb);color:#fff;padding:30px;border-radius:14px;text-align:center}
Result
A two-colour linear gradient.
Common mistake
Don't
.box { color: navy; } /* expected a navy box */
Do
.box { background-color: navy; color: #fff; }

Using color when you mean background-color (or vice versa). color is the text; background-color is behind it.

Best practice

Pick a small, consistent palette (one or two main colours plus neutrals). Too many colours make a page feel chaotic and unprofessional.

Try it yourself

Build a card: give it a background colour, white text, padding and rounded corners. Then try replacing the background with a linear-gradient.

Quick quiz

1. Most common colour format in real projects?

2. What fills the area behind content?

3. Which function makes a gradient?

Key takeaways
  • Colour formats: named, hex (most common), rgb(), hsl() (easy to tweak).
  • color is text; background-color is behind the element.
  • background can hold linear-gradient() for smooth blends.
  • Keep a small, consistent palette.