0
0
Tailwindmarkup~15 mins

Arbitrary properties for unsupported CSS in Tailwind - Deep Dive

Choose your learning style9 modes available
Overview - Arbitrary properties for unsupported CSS
What is it?
Arbitrary properties in Tailwind CSS let you write any CSS style directly inside your HTML classes, even if Tailwind doesn't have a built-in utility for it. This means you can add custom styles without leaving your HTML or writing separate CSS files. It uses square brackets to wrap the CSS property and value, like a shortcut for unsupported styles.
Why it matters
Without arbitrary properties, you would have to write extra CSS files or inline styles for anything Tailwind doesn't support. This breaks the fast workflow Tailwind offers and makes your code harder to maintain. Arbitrary properties keep your styles consistent, quick to write, and easy to manage all in one place.
Where it fits
Before learning arbitrary properties, you should understand basic Tailwind utilities and how Tailwind classes work. After this, you can explore advanced Tailwind features like plugins and custom configurations to extend Tailwind further.
Mental Model
Core Idea
Arbitrary properties let you write any CSS style inside Tailwind classes by wrapping the CSS property and value in square brackets.
Think of it like...
It's like having a toolbox with fixed tools (Tailwind utilities), but sometimes you need a special tool not in the box, so you create your own on the spot without leaving your workspace.
Tailwind class example:

[class="bg-blue-500 p-4 [border-radius:12px] [--my-var:10px]"]

┌───────────────┐ ┌─────────────┐ ┌─────────────────────┐
│ bg-blue-500   │ │ p-4         │ │ [border-radius:12px]│
│ (built-in)    │ │ (built-in)  │ │ (arbitrary property)│
└───────────────┘ └─────────────┘ └─────────────────────┘
Build-Up - 7 Steps
1
FoundationUnderstanding Tailwind Utility Classes
🤔
Concept: Learn how Tailwind uses predefined class names to apply CSS styles.
Tailwind CSS provides many ready-made classes like 'bg-blue-500' for background color or 'p-4' for padding. You add these classes to HTML elements to style them quickly without writing CSS yourself.
Result
You can style elements fast using simple class names without writing CSS code.
Understanding Tailwind's utility-first approach is key to seeing why arbitrary properties are useful when you need styles outside the built-in set.
2
FoundationLimitations of Built-in Tailwind Utilities
🤔
Concept: Recognize that Tailwind doesn't cover every possible CSS property or value.
Tailwind covers many common CSS styles but can't include every possible property or custom value. For example, if you want a border radius of 12px but Tailwind only has 8px or 16px, you can't use a built-in class for 12px.
Result
You realize sometimes Tailwind utilities don't fit your exact design needs.
Knowing these limits prepares you to learn how arbitrary properties solve this gap.
3
IntermediateUsing Arbitrary Properties Syntax
🤔Before reading on: do you think you can write any CSS property inside Tailwind classes using normal class names? Commit to yes or no.
Concept: Learn the syntax to write any CSS property and value inside Tailwind classes using square brackets.
Tailwind allows you to write custom CSS inside square brackets in class names. For example, to set border-radius to 12px, write '[border-radius:12px]'. This tells Tailwind to apply that exact CSS style.
Result
You can add unsupported CSS styles directly in your HTML classes.
Understanding this syntax unlocks the power to customize styles without leaving Tailwind's utility system.
4
IntermediateCombining Arbitrary Properties with Built-in Utilities
🤔Before reading on: do you think arbitrary properties replace built-in utilities or work alongside them? Commit to your answer.
Concept: Learn how to mix arbitrary properties with regular Tailwind classes for flexible styling.
You can combine built-in classes like 'bg-red-500' with arbitrary properties like '[border-radius:10px]' in the same class attribute. This keeps your code clean and consistent.
Result
Your elements get both standard and custom styles together smoothly.
Knowing they work together helps you keep the best of both worlds: speed and flexibility.
5
IntermediateHandling Special Characters in Arbitrary Properties
🤔
Concept: Learn how to write CSS values with spaces or special characters inside arbitrary properties.
If your CSS value has spaces or special characters, wrap it in quotes inside the brackets. For example, '[font-family:"Open Sans"]' or '[background-image:url(\"image.png\")]'. This ensures Tailwind parses it correctly.
Result
You can use complex CSS values safely in arbitrary properties.
Understanding escaping and quoting prevents syntax errors and broken styles.
6
AdvancedUsing Arbitrary Properties for CSS Variables
🤔Before reading on: can you set CSS custom properties (variables) using arbitrary properties in Tailwind? Commit to yes or no.
Concept: Learn to define and use CSS variables inside Tailwind classes with arbitrary properties.
You can write '[--my-color:#123456]' to define a CSS variable directly in your class. Then use it elsewhere in your CSS or inline styles. This helps create dynamic and reusable styles.
Result
You can manage CSS variables without separate CSS files.
Knowing this lets you leverage CSS variables fully within Tailwind's utility system.
7
ExpertPerformance and Maintainability Considerations
🤔Before reading on: do you think overusing arbitrary properties can affect your project's CSS size and clarity? Commit to yes or no.
Concept: Understand the trade-offs of using many arbitrary properties in large projects.
While arbitrary properties are powerful, overusing them can increase your CSS output size and make your HTML classes harder to read. It's best to use them sparingly for truly custom styles and prefer built-in utilities or custom plugins when possible.
Result
You write cleaner, faster-loading, and maintainable code.
Knowing when to use arbitrary properties helps balance flexibility with performance and clarity.
Under the Hood
Tailwind's compiler scans your HTML classes and looks for patterns. When it sees square brackets, it extracts the CSS property and value inside, validates it, and generates a unique CSS rule for it. This rule is then included in the final CSS bundle, allowing any CSS property to be applied even if Tailwind doesn't have a predefined utility.
Why designed this way?
Tailwind was designed to be fast and utility-first but recognized it can't cover every CSS property or value. Arbitrary properties were introduced to keep the utility-first workflow while allowing unlimited customization without writing separate CSS. This avoids breaking the developer's flow and keeps styles consistent.
HTML classes with arbitrary properties

┌─────────────────────────────┐
│ <div class="p-4 [border-radius:12px]"> │
└─────────────┬───────────────┘
              │
              ▼
┌─────────────────────────────┐
│ Tailwind compiler detects []│
│ extracts 'border-radius:12px'│
└─────────────┬───────────────┘
              │
              ▼
┌─────────────────────────────┐
│ Generates CSS rule:          │
│ .\[border-radius\:12px\] { │
│   border-radius: 12px;      │
│ }                           │
└─────────────────────────────┘
              │
              ▼
┌─────────────────────────────┐
│ Final CSS includes this rule │
│ Applied to element at runtime│
└─────────────────────────────┘
Myth Busters - 4 Common Misconceptions
Quick: Do you think arbitrary properties can only set CSS properties that Tailwind already supports? Commit to yes or no.
Common Belief:Arbitrary properties only work for CSS properties Tailwind already has utilities for.
Tap to reveal reality
Reality:Arbitrary properties can set any valid CSS property, even those Tailwind doesn't support at all.
Why it matters:Believing this limits your creativity and leads you to write extra CSS files unnecessarily.
Quick: Do you think arbitrary properties are always better than writing custom CSS? Commit to yes or no.
Common Belief:Using arbitrary properties is always the best way to add custom styles in Tailwind projects.
Tap to reveal reality
Reality:While convenient, overusing arbitrary properties can bloat CSS and reduce readability; sometimes custom CSS or plugins are better.
Why it matters:Ignoring this can cause performance issues and harder-to-maintain codebases.
Quick: Do you think you can write arbitrary properties without escaping special characters? Commit to yes or no.
Common Belief:You can write any CSS value inside arbitrary properties without special syntax or escaping.
Tap to reveal reality
Reality:Values with spaces or special characters must be quoted or escaped to avoid errors.
Why it matters:Not escaping causes broken styles and confusing bugs.
Quick: Do you think arbitrary properties increase your CSS bundle size significantly even if used sparingly? Commit to yes or no.
Common Belief:Using a few arbitrary properties will drastically increase your CSS file size.
Tap to reveal reality
Reality:Each arbitrary property generates a unique CSS rule, but using them sparingly has minimal impact compared to many custom CSS files.
Why it matters:Understanding this helps you use arbitrary properties confidently without fear of performance loss.
Expert Zone
1
Arbitrary properties generate unique CSS selectors with escaped characters, which can affect specificity and debugging in browser tools.
2
Using arbitrary properties inside responsive or state variants (like hover:) requires special syntax and understanding of Tailwind's parser.
3
Tailwind's JIT compiler only includes arbitrary properties actually used in your HTML, keeping CSS size optimized.
When NOT to use
Avoid arbitrary properties when you need to reuse complex styles across many elements; instead, create custom utilities or plugins. Also, avoid them for styles that require media queries or pseudo-elements, where CSS files or Tailwind plugins are better.
Production Patterns
In production, developers use arbitrary properties for one-off custom tweaks like exact spacing, colors, or CSS variables. They combine this with Tailwind's built-in utilities and custom plugins for scalable, maintainable styling.
Connections
CSS Custom Properties (Variables)
Arbitrary properties allow defining CSS variables inline, connecting Tailwind to native CSS variable usage.
Knowing how to set CSS variables inside Tailwind classes helps create dynamic themes and reusable styles without separate CSS.
JIT Compilation
Arbitrary properties rely on Tailwind's Just-In-Time compiler to generate CSS rules on demand.
Understanding JIT explains why arbitrary properties don't bloat CSS files unnecessarily and only produce needed styles.
Natural Language Processing (NLP) Tokenization
Tailwind's parser tokenizes class names including arbitrary properties, similar to how NLP breaks sentences into meaningful parts.
Recognizing this parsing process helps understand why syntax like escaping and quoting is necessary for correct interpretation.
Common Pitfalls
#1Writing arbitrary properties without quotes for values with spaces.
Wrong approach:
Correct approach:
Root cause:Not knowing that CSS values with spaces must be quoted inside arbitrary properties.
#2Overusing arbitrary properties for common styles already in Tailwind.
Wrong approach:
Correct approach:
Root cause:Ignoring built-in utilities leads to verbose and inconsistent code.
#3Using arbitrary properties inside pseudo-class variants incorrectly.
Wrong approach:
Correct approach:
Root cause:Actually, this is correct syntax; the pitfall is forgetting to enable JIT mode or using an older Tailwind version that doesn't support this.
Key Takeaways
Arbitrary properties let you write any CSS style inside Tailwind classes using square brackets, filling gaps in Tailwind's built-in utilities.
They keep your styling workflow fast and consistent by avoiding separate CSS files for custom styles.
Proper syntax, including quoting and escaping, is essential to avoid errors with complex CSS values.
Use arbitrary properties sparingly to maintain performance and code clarity, combining them with built-in utilities and plugins.
Understanding Tailwind's JIT compiler and parsing helps you use arbitrary properties effectively and avoid common mistakes.