Using Arbitrary Values: Custom Styling in Tailwind CSS
Learn how to use arbitrary values in Tailwind CSS with square bracket notation to handle unique design needs without cluttering your configuration file.

Previously in this course, we explored customizing the theme to extend Tailwind's default design tokens. While a rigid design system is the backbone of professional UI development, you will inevitably encounter one-off requirements that don't fit your theme—this is where arbitrary values come in.
Breaking the System: When to Use Arbitrary Values
Tailwind is designed to keep your interface consistent by limiting your choices to a pre-defined scale. However, sometimes you need a specific pixel value, a unique hex code provided by a client, or an obscure CSS property that doesn't exist in the default utility set.
Arbitrary values allow you to "escape" the design system on a per-element basis. Instead of updating your tailwind.config.js for a style you'll only use once, you can write the raw CSS value directly in your HTML using square bracket notation.
The Syntax of Square Brackets
The syntax follows a simple pattern: utility-[value]. Tailwind's JIT (Just-in-Time) engine parses these classes at build time and generates the necessary CSS on the fly.
1. Implementing Arbitrary Colors
If you have a specific brand color that isn't in your theme, you can apply it directly to backgrounds, text, or borders.
HTML<!-- Background with a specific hex code --> style="color:#808080"><style="color:#4EC9B0">div class="bg-[#1da1f2]">...style="color:#808080"></style="color:#4EC9B0">div> <!-- Text color with an RGB value --> style="color:#808080"><style="color:#4EC9B0">p class="text-[rgb(255,0,0)]">Warning textstyle="color:#808080"></style="color:#4EC9B0">p>
2. Using Arbitrary Sizing
You can set dimensions, padding, or margins to exact values that aren't part of the standard spacing scale (like p-4 or w-64).
HTML<!-- Custom width and height --> style="color:#808080"><style="color:#4EC9B0">div class="w-[342px] h-[127px]">...style="color:#808080"></style="color:#4EC9B0">div> <!-- Custom padding --> style="color:#808080"><style="color:#4EC9B0">div class="p-[13px]">...style="color:#808080"></style="color:#4EC9B0">div>
Worked Example: The Custom Hero Badge
In our ongoing project, let's say we need a "New Feature" badge in our hero section that uses a very specific brand color and a non-standard height. We don't want to add these to our global config because they are unique to this specific element.
HTML<!-- A badge with a one-off height and brand color --> style="color:#808080"><style="color:#4EC9B0">span class="inline-block h-[27px] bg-[#ff5733] px-4 rounded-full text-white"> New Feature style="color:#808080"></style="color:#4EC9B0">span>
In this example, h-[27px] forces a specific height that isn't in the default scale, and bg-[#ff5733] applies the unique brand color without polluting your tailwind.config.js.
Hands-on Exercise
Open your project's index.html file. Locate the main hero section we built in our project setup lessons.
- Find an element where the default spacing feels "just a bit off."
- Instead of using
mt-4ormt-6, try using an arbitrary value likemt-[22px]. - Add a decorative border to your hero section using a custom color that isn't in the standard palette:
border-[3px] border-[#a855f7]. - Inspect the element in your browser dev tools to see the generated CSS class.
Common Pitfalls
- Overusing Arbitrary Values: This is the most common mistake. If you find yourself using
w-[300px]in five different places, move that value into yourtailwind.config.jsas a theme extension. Arbitrary values are for exceptions, not the rule. - Forgetting Units: If you use a number, Tailwind often defaults to pixels if it's a sizing utility, but for properties like
grid-template-columns, you must be explicit. Always include units (e.g.,[20rem],[50%]) when in doubt. - Spaces in Values: CSS properties cannot contain spaces inside the square brackets. If you need a value like
minmax(0, 1fr), use an underscore instead:grid-cols-[minmax(0,_1fr)].
FAQ
Q: Do arbitrary values increase my CSS bundle size? A: No. Because Tailwind uses a JIT engine, it only generates the specific CSS rules you actually use in your markup.
Q: Can I use modifiers with arbitrary values?
A: Absolutely. You can combine them with responsive or state modifiers: hover:bg-[#ff5733] or md:w-[500px] work exactly as expected.
Q: Should I use this for font sizes?
A: Yes, if you have a specific design file requirement for a "19px" font size, text-[19px] is perfectly acceptable for a one-off layout.
Recap
Arbitrary values give you the ultimate flexibility of CSS while maintaining the efficiency of a utility-first workflow. Use them sparingly to handle unique edge cases, but keep your design system consistent by moving repeated values into your configuration.
Up next: We will dive into performance optimization to ensure your production build is as small and fast as possible.
Work with me

Next.js Full-Stack Web App Development
A fast, SEO-ready full-stack web app built with Next.js 16 — from idea to deployed product, by an engineer who ships to production.

Next.js Website & Landing Page Development
A blazing-fast, SEO-optimized website or landing page in Next.js — the kind that loads instantly and ranks. Design-to-code, done right.

