Custom Values — Tailwind CSS

A value that isn't on Tailwind's scale is written as an arbitrary value, inside square brackets: w-[200px] becomes width: 200px, h-[60px] becomes height…

Sometimes a design asks for a number that isn't on Tailwind's scale, such as a width of exactly 200px. That's what an arbitrary value is for: a value you write yourself inside square brackets, such as w-[200px]. Tailwind copies what's inside the brackets into the CSS as it is. Picture buying clothes. Usually you take them from the rack: S, M, L, quick and all in matching sizes. When nothing fits, you go to a tailor and ask for an exact size. Tailwind's scale is the rack, and the square brackets are the tailor.

Square brackets: the exact value

The design asks for a blue box of 200 × 60px. On Tailwind's old scale (v3), the nearest widths are w-48 (192px) and w-52 (208px), and both miss. So the width and height are written by hand:

<div id="custom" class="w-[200px] h-[60px] bg-blue-500">
  Custom Size
</div>
Class CSS it generates Meaning
w-[200px] width: 200px; exactly 200px wide
h-[60px] height: 60px; exactly 60px tall
bg-blue-500 background-color: var(--color-blue-500); blue from the built-in palette

What's in the brackets is written as it is

Before you read on, guess: you write w-[200], with no px. How wide does the box become?

Tailwind doesn't check whether what's inside the brackets is valid CSS (written by the rules of CSS). Tailwind only copies it into the CSS, and then the browser decides.

You write CSS it generates Result in the browser
w-[200px] width: 200px; 200px wide
w-[200] width: 200; invalid, thrown away
w-200px none not a Tailwind class
w-[50%] width: 50%; half its parent's width
p-[10px_20px] padding: 10px 20px; the underscore becomes a space

So w-[200] doesn't make a 200px box. Tailwind writes width: 200, but a number with no unit isn't valid for width, so the browser throws that rule away. The box goes back to a <div>'s default width: as wide as its parent. There's no error message at all, which is why people often don't notice this trap.

Why replace spaces with _? The class attribute is split into class names at every space. So p-[10px 20px] is read as two classes, p-[10px and 20px], and neither generates any CSS.

Not just sizes: colours and more

Square brackets work on almost every Tailwind class:

<p class="text-[13px] text-[#ff6600]">Orange text at 13px</p>
<div class="bg-[#1da1f2] mt-[13px]">A custom blue, 13px top margin</div>
<div class="grid grid-cols-[200px_1fr]">A 200px column, then the rest</div>

When to use the scale, when to use brackets

The exercise editor runs Tailwind v4, like the Playground, so w-50 and h-15 work there too. But the exercise is about square brackets, so write w-[200px] and h-[60px].

⚠️ Brackets that quietly do nothing

TL;DR: A value that isn't on Tailwind's scale is written as an arbitrary value, inside square brackets: w-[200px] becomes width: 200px, h-[60px] becomes height: 60px, text-[#ff6600] becomes color: #ff6600. Tailwind copies what's inside as it is. So the unit is required (the browser throws w-[200] away). A space inside the brackets is written _. Without the brackets (w-200px), there's no CSS at all. Use the built-in scale first, brackets for one-off values, and @theme (the block where you add to or change Tailwind's default values) for values you use again and again. In v4, a CSS variable such as --brand is used with bg-(--brand).

⚡ An exact size in square brackets

Write:

<div id="custom" class="w-[200px] h-[60px] bg-blue-500">
  Custom Size
</div>

Meaning: A value that isn't on Tailwind's scale goes inside square brackets, and Tailwind copies it as it is: w-[200px] becomes width: 200px, h-[60px] becomes height: 60px. The colour stays bg-blue-500 from the palette, so not every class needs brackets.

⚡ What's inside is copied as it is

Guess first: you write w-[200], with no px. How wide is the box?

As wide as its parent. Tailwind writes width: 200, but a number with no unit isn't valid, so the browser throws that rule away with no error message, and the box goes back to its default width.

Meaning: The unit is required, and spaces inside the brackets become _, as in p-[10px_20px]. Without brackets, as in w-200px, there's no CSS at all.

In the exercise, the checker (the program that checks your answer) looks for a width of 200px and a height of 60px, so write them with px.

⚡ The scale first

Meaning: Spacing and sizes from Tailwind's scale keep a page consistent. Brackets are for one-off values that really aren't on the scale. Values you use again and again are better as theme tokens (named values you register once) in the @theme block.

What you will learn