TExcelTAD
Home › Tailwind CSS › Backgrounds & Gradients

Backgrounds & Gradients

Besides solid colours (bg-sky-500), Tailwind has utilities for gradients, background images, and how backgrounds are sized, positioned and repeated.

Linear gradients

A gradient needs a direction plus colour stops:

Class Meaning
bg-linear-to-r gradient towards the right (to-t, to-b, to-l, to-tr, to-bl …)
bg-linear-45 gradient at a 45° angle (any number)
from-pink-500 start colour
via-purple-500 optional middle colour
to-indigo-500 end colour
from-10% / via-30% / to-90% stop positions

Note: v4 renamed bg-gradient-to-r to bg-linear-to-r. The old name still works for now, but new code should use bg-linear-*.

html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="space-y-3 p-4 text-sm font-semibold text-white">
  <div class="rounded-lg bg-linear-to-r from-cyan-500 to-blue-600 p-4">bg-linear-to-r from-cyan-500 to-blue-600</div>
  <div class="rounded-lg bg-linear-to-br from-pink-500 via-purple-500 to-indigo-500 p-4">to-br with a via colour</div>
  <div class="rounded-lg bg-linear-45 from-amber-400 from-20% to-red-600 to-80% p-4">bg-linear-45 with stop positions</div>
  <div class="rounded-lg bg-linear-to-r from-emerald-500 to-transparent p-4 text-emerald-900">fade to transparent</div>
</body>
</html>

Radial and conic gradients (new in v4)

Class Gradient
bg-radial circle/ellipse from the centre
bg-radial-[at_25%_25%] radial from a custom position
bg-conic sweeps around a point like a clock hand
bg-conic-180 conic starting at 180°
html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="flex flex-wrap gap-4 p-4">
  <div class="size-32 rounded-full bg-radial from-yellow-200 to-orange-600"></div>
  <div class="size-32 rounded-full bg-radial-[at_30%_30%] from-white via-sky-400 to-indigo-900"></div>
  <div class="size-32 rounded-full bg-conic from-red-500 via-yellow-400 to-red-500"></div>
  <div class="size-32 rounded-full bg-conic-180 from-indigo-600 via-indigo-50 to-indigo-600"></div>
</body>
</html>

The second circle is a cheap "3D sphere" made purely with a radial gradient.

Background images, size and position

To use an image you supply the URL as an arbitrary value: bg-[url(/img/hero.jpg)]. Since this course avoids external images, the example below paints small gradient "tiles" instead, which behave exactly like images for size, position and repeat. Inside arbitrary values, write an underscore _ wherever CSS needs a space.

Class CSS
bg-cover / bg-contain / bg-auto / bg-size-[20px_20px] background-size
bg-center / bg-top / bg-right-bottom … background-position
bg-no-repeat / bg-repeat / bg-repeat-x background-repeat
bg-fixed / bg-local / bg-scroll background-attachment
bg-clip-text clip the background to the text shape
bg-origin-border / bg-origin-padding / bg-origin-content background-origin
html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="grid grid-cols-2 gap-3 p-4 text-xs font-semibold">
  <div class="h-28 rounded-lg border border-sky-300 bg-[radial-gradient(circle,#38bdf8_3px,transparent_4px)] bg-size-[20px_20px] p-2">repeating 20px tile</div>
  <div class="h-28 rounded-lg border border-rose-300 bg-[radial-gradient(circle,#f43f5e_10px,transparent_11px)] bg-size-[40px_40px] bg-center bg-no-repeat p-2">bg-no-repeat bg-center</div>
  <div class="h-28 rounded-lg border border-amber-300 bg-[linear-gradient(45deg,#fde68a_25%,transparent_25%)] bg-size-[16px_16px] p-2">striped pattern</div>
  <div class="h-28 rounded-lg border border-emerald-300 bg-[radial-gradient(circle,#10b981_10px,transparent_11px)] bg-size-[40px_40px] bg-right-bottom bg-no-repeat p-2">bg-right-bottom</div>
</body>
</html>

Gradient text

Combine a gradient with bg-clip-text and text-transparent to paint the gradient through the letters:

html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="flex min-h-screen items-center justify-center bg-slate-950 p-4">
  <h1 class="bg-linear-to-r from-sky-400 via-fuchsia-400 to-amber-300 bg-clip-text text-5xl font-black text-transparent">
    Gradient text
  </h1>
</body>
</html>

Tip: A soft background like bg-linear-to-b from-white to-slate-100 on a page section adds depth without distracting from the content.

Test yourself

What is the v4 name for v3's bg-gradient-to-r?

  1. bg-gradient-r
  2. bg-linear-to-r
  3. gradient-to-r
  4. bg-lg-r

Which classes create a three-colour gradient?

  1. from-* via-* to-*
  2. start-* mid-* end-*
  3. bg-1-* bg-2-* bg-3-*
  4. color-a color-b color-c

Which pair is needed for gradient-filled text (along with a gradient)?

  1. bg-clip-text and text-transparent
  2. text-gradient and bg-none
  3. bg-cover and text-white
  4. clip-path and opacity-0