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 |
- The shape is always the same: the class prefix (such as
w-), then a CSS value inside[ ].w-becomeswidth,h-becomesheight,bg-becomesbackground-color. - The colour stays
bg-blue-500from the palette. Only the width and height need a custom value. So don't turn every class into brackets.
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>
text-[#ff6600]becomescolor: #ff6600. Hex,rgb(...)andhsl(...)all work.text-[13px]becomesfont-size: 13px. Tailwind recognises13pxas a size and#ff6600as a colour, so both can usetext-.- Have a CSS variable of your own, such as
--brand? In Tailwind v4, write its name inside round brackets:bg-(--brand)becomesbackground-color: var(--brand).
When to use the scale, when to use brackets
- The scale first. Spacing and sizes from the scale keep a page tidy and consistent. In Tailwind v4, a number on the scale can be anything, and one step = 4px:
w-50= 200px,h-15= 60px. - Brackets for one-off values that really aren't on the scale: a 37px icon, a
top-[117px]position, a colour taken from a client's logo. - A value you use again and again, such as a brand colour on 30 buttons, is better as a theme token in the
@themeblock. A theme token is a named value you register once, then use through a class such asbg-brand. The Tailwind Config lesson shows how.
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
- Forgetting the unit. The browser throws
w-[200]away. Writew-[200px]andh-[60px], with thepx. In the exercise, the checker looks for a width of200pxand a height of60px. - Forgetting the brackets.
w-200pxisn't a class, so it has no CSS. The value has to be inside[ ]. - A space inside the brackets.
p-[10px 20px]breaks into two classes. Use an underscore:p-[10px_20px]. - The v3 variable syntax. In v3, a CSS variable was written
bg-[--brand]. In v4, that class becomesbackground-color: --brand, which isn't valid. Usebg-(--brand)orbg-[var(--brand)].
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.