Sometimes Tailwind CSS does not have a built-in class for a specific CSS property you want to use. Arbitrary properties let you add any CSS style directly in your HTML using Tailwind's special syntax.
Arbitrary properties for unsupported CSS in Tailwind
class="[property:value]"<div class="[scroll-margin-top:2rem]">Content</div><button class="[backdrop-filter:blur(5px)]">Blurred Background</button><p class="[text-shadow:2px_2px_4px_rgba(0,0,0,0.5)]">Shadowed Text</p>This example shows three uses of arbitrary properties: scroll-margin-top on a div, backdrop-filter blur on a button, and text-shadow on a paragraph. These styles are not built-in Tailwind classes but work using the arbitrary property syntax.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Arbitrary Properties Example</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="p-6"> <h1 class="text-2xl font-bold mb-4">Arbitrary Properties in Tailwind</h1> <div class="[scroll-margin-top:3rem] mb-6 border p-4"> This box has a scroll margin top of 3rem. </div> <button class="bg-blue-500 text-white px-4 py-2 rounded [backdrop-filter:blur(4px)]"> Blurred Background Button </button> <p class="mt-6 text-lg [text-shadow:2px_2px_3px_rgba(0,0,0,0.4)]"> This text has a shadow using an arbitrary property. </p> </body> </html>
Use dashes (-) instead of spaces in property names inside brackets, for example: [scroll-margin-top:1rem].
If the value contains spaces or special characters, wrap it in quotes: [content:'"Hello"'].
Arbitrary properties keep your HTML clean and avoid writing extra CSS files for small custom styles.
Arbitrary properties let you add any CSS style directly in Tailwind classes.
Use square brackets with property and value, like [property:value].
This helps when Tailwind does not have a built-in class for the style you want.
Practice
Solution
Step 1: Understand Tailwind's default classes
Tailwind provides many utility classes but may not cover every CSS property you need.Step 2: Purpose of arbitrary properties
Arbitrary properties let you write any CSS property and value inside square brackets to extend Tailwind easily.Final Answer:
To add custom CSS styles not available in Tailwind's default classes -> Option AQuick Check:
Arbitrary properties = custom CSS in Tailwind [OK]
- Confusing arbitrary properties with removing styles
- Thinking it runs JavaScript
- Assuming it creates animations automatically
scroll-margin-top to 2rem using Tailwind's arbitrary properties?Solution
Step 1: Recall Tailwind arbitrary property syntax
It uses square brackets with property and value separated by a colon, like[property:value].Step 2: Match syntax to options
Only [scroll-margin-top:2rem] matches the correct format:[scroll-margin-top:2rem].Final Answer:
[scroll-margin-top:2rem] -> Option DQuick Check:
Syntax = [property:value] [OK]
- Using equal sign instead of colon
- Placing brackets incorrectly
- Omitting brackets entirely
<div class="[border-radius:1rem] bg-blue-500 p-4 text-white">Hello</div>
Solution
Step 1: Analyze the classes
The class[border-radius:1rem]sets border radius to 1rem.bg-blue-500sets blue background.p-4adds padding.text-whitesets text color white.Step 2: Visualize the result
The div will show a blue box with white text and rounded corners of 1rem radius.Final Answer:
A blue box with white text and rounded corners of 1rem radius -> Option CQuick Check:
Arbitrary border-radius + bg-blue-500 = blue rounded box [OK]
- Ignoring arbitrary property effect
- Confusing background color classes
- Assuming default border radius
<div class="[padding-top=2rem] text-center">Content</div>
Solution
Step 1: Check arbitrary property syntax
Tailwind requires a colon between property and value inside brackets, like[padding-top:2rem].Step 2: Identify the error
The code uses an equal sign=which is invalid syntax.Final Answer:
Using equal sign (=) instead of colon (:) inside brackets -> Option AQuick Check:
Arbitrary syntax = colon, not equal sign [OK]
- Using = instead of :
- Thinking camelCase is required
- Believing arbitrary properties can't style padding
scroll-padding-left with value 3rem to a div using Tailwind. Which class should you use, and why might this be necessary?Solution
Step 1: Recognize unsupported CSS property
Tailwind does not provide default classes forscroll-padding-left.Step 2: Use arbitrary property syntax
To add unsupported CSS, use square brackets with property and value separated by colon:[scroll-padding-left:3rem].Final Answer:
[scroll-padding-left:3rem] because Tailwind does not have a built-in class for this property -> Option BQuick Check:
Unsupported CSS = use arbitrary property [OK]
- Assuming Tailwind has built-in class for all CSS
- Placing brackets only around value
- Using colon directly in class without brackets
Ready to prove it?
Pass the test and this pattern moves unknown
