One page often needs three blues at once: dark blue for the heading, full blue for the button, and light blue behind a box. In plain CSS you have to remember three different hex codes. In Tailwind the three are one colour family. Only the number differs.
Tailwind has a ready-made colour palette (a list of colours), and you always use it the same way. The class name has three parts: a prefix that names the CSS property, a colour name, then a shade number (how light or dark the colour is). text-blue-600 colours the letters blue, shade 600. bg-yellow-100 gives a yellow background, shade 100. The palette works like the fan of colour samples at a paint shop. Each colour has its own strip, and on that strip is a row of numbered squares, from the palest to the deepest. In Tailwind, the strip is the colour name (blue), and the number of the square is the shade (600).
The colour class formula
Here are the two elements from the exercise:
<p id="title" class="text-blue-600">Blue Title</p>
<div id="box" class="bg-yellow-100">Yellow Box</div>
text-blue-600makes the rulecolor: var(--color-blue-600): the title's letters turn blue.bg-yellow-100makes the rulebackground-color: var(--color-yellow-100): the box's background turns pale yellow.- Each class goes on its own element: the text colour on
#title, the background colour on#box.
The pattern is {prefix}-{colour}-{shade}, and the prefix decides which property gets the colour:
| Prefix | CSS property | Example |
|---|---|---|
text- |
color (letter colour) |
text-red-500 |
bg- |
background-color (background colour) |
bg-red-500 |
border- |
border-color (border colour) |
border-red-500 |
Colours without shades are written by name alone: text-white, bg-black, bg-transparent.
Shade numbers: 50 is the lightest
Every colour has 11 shades: 50, 100, 200, 300, 400, 500, 600, 700, 800, 900 and 950. 50 is the lightest, nearly white. 950 is the darkest, nearly black. 500 sits in the middle.
| Shade | How it looks | Good for |
|---|---|---|
| 50 to 200 | pale | soft backgrounds, for example bg-yellow-100 |
| 400 to 600 | full colour | buttons, icons, accents |
| 600 to 950 | deep | text on a light background, for example text-blue-600 |
That's why text-yellow-100 on a white page is barely readable: yellow 100 is nearly white. Text on a light background uses shade 600 and up. Text on a dark background uses 100 to 200, or text-white.
The colours available
- Greys:
slate,gray,zinc,neutral,stone. - Colours:
red,orange,amber,yellow,lime,green,emerald,teal,cyan,sky,blue,indigo,violet,purple,fuchsia,pink,rose. - Tailwind v4.2 adds four more greys:
mauve,olive,mist,taupe.
In v4, the value of each colour is written in the oklch colour format. For example, blue-600 = oklch(54.6% 0.245 262.881). You don't need to memorise the numbers, just the name and the shade.
See-through with a slash
To make a colour see-through, add / and a percentage at the end of a colour class:
<div class="bg-black/50 text-white p-4">Text over a photo</div>
bg-black/50= a black background at 50% opacity. If this box sits over a photo, the photo still shows, just darker. So the white text is readable.- The slash works on any colour:
text-blue-600/75,bg-yellow-100/50.
💡 Gradients
A gradient is a colour that changes slowly into another colour. In Tailwind, you write a gradient with three classes:
<div class="bg-linear-to-r from-blue-500 to-purple-500 text-white p-4">Gradient</div>
bg-linear-to-rmakes alinear-gradienttowards the right (r= right). That's the v4 name. v3 tutorials write itbg-gradient-to-r, and v4 still accepts it.from-blue-500is the starting colour, andto-purple-500the ending colour.
⚠️ The colour won't change?
- The class on the wrong element.
text-blue-600has to be on#title, andbg-yellow-100on#box. The exercise checks each id with its class, so if you swap the two classes, the exercise still fails. - Forgetting the shade number.
text-blueorbg-yellowisn't in the palette, so Tailwind makes no CSS for it, and the colour doesn't change. - A prefix taken from the CSS property name.
color-blue-600andbackground-yellow-100aren't Tailwind classes. The prefixes aretext-andbg-. - Building the colour name from pieces of text. An example is
"bg-" + colour + "-500". When Tailwind reads your files, it doesn't find that class name, because it isn't written whole. Write the class whole.
TL;DR: Colour classes are written {prefix}-{colour}-{shade}. The prefix names the property: text- for the letter colour (color), bg- for the background (background-color), border- for the border. The shade is how light or dark the colour is: 50 is the lightest, 950 the darkest, 500 the middle. Text on a light background uses 600 and up (text-blue-600), soft backgrounds use 50 to 200 (bg-yellow-100). text-white and bg-black have no number. A slash makes a colour see-through: bg-black/50 = black at 50% opacity. Gradients in v4: bg-linear-to-r from-blue-500 to-purple-500, from blue to purple towards the right. Put each class on the right element, and don't forget the shade number.
⚡ Prefix, colour, shade
Write:
<p id="title" class="text-blue-600">Blue Title</p>
<div id="box" class="bg-yellow-100">Yellow Box</div>
Meaning: The pattern is {prefix}-{colour}-{shade}. The shade is a number for how light or dark the colour is. The prefix says what gets the colour: text- colours the letters, bg- the background, border- the border. Each class goes on its own element.
The exercise checks each id with its class: text-blue-600 on #title, bg-yellow-100 on #box.
⚡ 50 is the lightest
Guess first: shade 50 is the lightest, 950 the darkest. Is text-yellow-100 readable on a white page?
Barely. Yellow 100 is nearly white, so the letters are almost the same colour as the page.
Meaning: Text on a light background uses shade 600 and up, soft backgrounds use 50 to 200. Without a shade number, as in text-blue, no CSS is made.
⚡ See-through with a slash
Write:
<div class="bg-black/50 text-white p-4">Text over a photo</div>
Meaning: bg-black/50 is a black background at 50% opacity. If this box sits over a photo, the photo still shows, just darker. So the white text (text-white) is readable.