Course contentsShow
← Web Development
Lesson 631 of 2,98211. Utility-First CSS with TailwindFree lesson

Arbitrary Values: Square Brackets Syntax

Use arbitrary values like w-[347px] and bg-[#1da1f2] when Tailwind's scale doesn't have exactly what you need.

Arbitrary Values: Square Brackets Syntax

You'll learn how to use any custom value in Tailwind CSS when the built-in scale doesn't have exactly what you need.

Tailwind provides a comprehensive set of predefined values for spacing, colors, sizes, and more. But what happens when your design calls for a width of exactly 347 pixels, or a brand color like #1da1f2 that isn't in Tailwind's color palette?

Using Square Brackets for Custom Values

Tailwind's square bracket syntax lets you write arbitrary values directly in your class names. Think of it as an "escape hatch" that gives you complete precision without leaving the utility-first workflow.

The syntax is simple: wrap your custom value in square brackets right where you'd normally use a preset value.

Examples:

<!-- Custom width in pixels -->
<div class="w-[347px]">Exactly 347 pixels wide</div>

<!-- Exact hex color -->
<button class="bg-[#1da1f2]">Twitter blue button</button>

<!-- Custom spacing -->
<section class="mt-[73px] p-[2.5rem]">Precise margins</section>

<!-- Custom rotation -->
<img class="rotate-[17deg]" src="logo.png" alt="Tilted logo">

<!-- Any CSS value works -->
<div class="grid-cols-[200px_1fr_1fr]">Custom grid template</div>

When to Use Arbitrary Values

Use this feature when your design requires exact values that don't fit Tailwind's systematic scale. It's perfect for brand-specific colors, precise measurements from design mockups, or one-off adjustments. However, try to stick with Tailwind's defaults when possible—they promote consistency and maintainability.

Key Takeaway: Square brackets [...] let you inject any CSS value directly into Tailwind utilities, giving you unlimited flexibility while staying in the utility-first mindset.