Arbitrary Values
The design scale covers most needs, but sometimes you need an exact value from a design file: a 137px sidebar, a brand colour #1da1f2, a special grid template. Arbitrary values let you write any CSS value right in a class name using square brackets.
Square brackets: any value
| Class | CSS |
|---|---|
w-[137px] |
width: 137px |
top-[117px] |
top: 117px |
bg-[#1da1f2] |
background-color: #1da1f2 |
text-[22px] |
font-size: 22px |
grid-cols-[1fr_2fr_1fr] |
grid-template-columns: 1fr 2fr 1fr |
p-[calc(1rem+2px)] |
padding: calc(1rem + 2px) |
shadow-[0_8px_0_#000] |
a custom box-shadow |
Spaces aren't allowed inside a class name, so use underscores where CSS needs a space. Tailwind converts them back (and keeps them in URLs). If you need a literal underscore, escape it: \_.
<!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">
<div class="w-[137px] rounded bg-[#1da1f2] p-2 text-[13px] text-white">w-[137px] bg-[#1da1f2]</div>
<div class="grid grid-cols-[1fr_2fr_1fr] gap-2 text-center text-sm">
<div class="rounded bg-emerald-200 p-2">1fr</div><div class="rounded bg-emerald-400 p-2">2fr</div><div class="rounded bg-emerald-200 p-2">1fr</div>
</div>
<button class="rounded-lg border-2 border-black bg-yellow-300 px-4 py-2 font-bold shadow-[4px_4px_0_#000] active:translate-x-1 active:translate-y-1 active:shadow-none">Brutalist button</button>
</body>
</html>CSS variables: parentheses
To use a CSS variable as the value, v4 has a short syntax with parentheses:
| v4 | Equivalent | v3 syntax |
|---|---|---|
bg-(--brand) |
bg-[var(--brand)] |
bg-[--brand] |
w-(--sidebar-width) |
w-[var(--sidebar-width)] |
w-[--sidebar-width] |
This is great for values computed by JavaScript:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="p-6">
<label class="text-sm">Progress: <input id="r" type="range" min="0" max="100" value="35" class="accent-indigo-600"></label>
<div class="mt-3 h-4 w-full overflow-hidden rounded-full bg-gray-200">
<div id="bar" class="h-full w-(--progress) rounded-full bg-indigo-600 transition-all" style="--progress: 35%"></div>
</div>
<script>
const r = document.getElementById('r');
r.addEventListener('input', () => {
document.getElementById('bar').style.setProperty('--progress', r.value + '%');
});
</script>
</body>
</html>Type hints
Some utilities accept several kinds of value. text-* can be a size or a colour; bg-* a colour, an image or a position. Tailwind guesses from the value (#hex is clearly a colour), but with a variable it can't tell. Add a type hint:
| Class | Meaning |
|---|---|
text-(length:--my-size) |
treat as a font size |
text-(color:--my-color) |
treat as a colour |
bg-[url(/hero.png)] |
url() makes it obviously an image |
Arbitrary properties
Need a CSS property Tailwind has no utility for? Write the whole declaration in brackets:
| Class | CSS |
|---|---|
[mask-type:luminance] |
mask-type: luminance |
[writing-mode:vertical-rl] |
vertical text |
hover:[text-shadow:0_0_8px_red] |
works with variants too |
[--gap:1rem] |
set a CSS variable |
Arbitrary variants
You can also write a custom selector as a variant, with & standing for the element:
| Class | Targets |
|---|---|
[&>li]:py-1 |
direct <li> children |
[&_a]:underline |
all <a> descendants |
[&:nth-child(3)]:font-bold |
the third child (or simply nth-3:) |
[@supports(display:grid)]:grid |
an at-rule condition |
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="flex gap-6 p-6">
<ul class="w-48 rounded-lg bg-white ring-1 ring-gray-200 [&>li]:border-b [&>li]:border-gray-100 [&>li]:px-3 [&>li]:py-2 [&>li:last-child]:border-0">
<li>Styled from the parent</li><li>with arbitrary variants</li><li>no classes on li</li>
</ul>
<p class="h-40 rounded bg-amber-100 p-2 font-bold [writing-mode:vertical-rl]">Vertical text ↓</p>
</body>
</html>The important modifier
Add ! at the end of a class to make it !important — handy when fighting third-party CSS:
<div class="bg-red-500!">Always red</div>Note: v3 put the
!at the start (!bg-red-500). v4 prefers the end; the old form still works but is deprecated.
Tip: If you use the same arbitrary value in several places, promote it to a theme variable (
--color-twitter: #1da1f2) so it gets a real name and stays consistent.
Test yourself
How do you write grid-template-columns: 1fr 2fr as an arbitrary class?
grid-cols-[1fr 2fr]grid-cols-[1fr_2fr]grid-cols-[1fr-2fr]- Spaces are not possible
What is the v4 shorthand for w-[var(--sidebar)]?
w-[--sidebar]w-(--sidebar)w-{--sidebar}w-$sidebar
Which class sets writing-mode: vertical-rl, a property without a built-in utility?
writing-vertical-rl[writing-mode:vertical-rl]style-[writing-mode](writing-mode:vertical-rl)