agyanadda@gmail.com

Tailwind Arbitrary Values

Customization and Best Practices 1 min read Updated Dec 1, 2026 Topic 25 of 27

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>

Test Yourself With Exercises

Exercise 1 Multiple Choice

How do you write a 350px width in Tailwind?

Exercise 2 True / False

In arbitrary values, an underscore represents a space.

Exercise 3 Fill in the Blank

If you use the same arbitrary value often, add it to @___ instead.

Frequently Asked Questions

Tailwind finds classes by scanning your files for complete class names. Build-time scanning cannot see dynamically joined strings; write the full class names or use inline styles.