Sometimes you need a value that is not in Tailwind's scale. Use square brackets.
Arbitrary values
| Class | CSS |
|---|---|
w-[350px] |
width: 350px |
bg-[#1f386b] |
background: #1f386b |
text-[22px] |
font-size: 22px |
top-[117px] |
top: 117px |
grid-cols-[200px_1fr] |
two columns (underscore = space) |
bg-[url(/img/bg.jpg)] |
background image |
CSS variables
bg-(--brand-color) uses a CSS variable (v4 shorthand).
Arbitrary properties
For CSS that has no utility: [mask-type:luminance].
Arbitrary variants
[&>li]:py-2 styles all direct li children.
Important
Add ! at the end to force a style: bg-red-500!.
Use them sparingly
Too many arbitrary values make designs inconsistent. If you use a value often, add it to @theme instead.
Example
Example — Arbitrary values in action
HTML
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<div class="p-6 space-y-4" style="--brand-color: #e8590c;">
<div class="w-[350px] max-w-full bg-[#1f386b] text-white p-4 rounded-[14px]">w-[350px], bg-[#1f386b], rounded-[14px]</div>
<p class="text-[22px] tracking-[0.2em] uppercase">text-[22px]</p>
<div class="bg-(--brand-color) text-white p-3 rounded-lg">bg-(--brand-color) from a CSS variable</div>
<div class="grid grid-cols-[120px_1fr] gap-3">
<div class="bg-slate-200 p-3">120px</div>
<div class="bg-slate-100 p-3">1fr (the rest)</div>
</div>
<ul class="[&>li]:py-2 [&>li]:border-b [&>li]:border-slate-200">
<li>Styled by an arbitrary variant</li>
<li>No class on each li</li>
</ul>
</div>