Arbitrary values let you use custom sizes or colors not in Tailwind's default list. This helps you make your design exactly how you want.
Why arbitrary values exist in Tailwind
class="property-[value]"Use square brackets [ ] to wrap your custom value.
Make sure to write the value exactly as CSS expects, including units like rem, px, %, etc.
class="bg-[#1a2b3c]"class="mt-[3.5rem]"class="rounded-[12px]"class="text-[18px]"This example shows a button with a custom background color, padding, and rounded corners using arbitrary values. When you hover, the background changes to another custom color.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Arbitrary Values Example</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="flex items-center justify-center min-h-screen bg-gray-100"> <button class="bg-[#ff6347] text-white px-[2.5rem] py-[1rem] rounded-[1.25rem] hover:bg-[#e5533d] transition"> Custom Button </button> </body> </html>
Arbitrary values give you freedom but use them wisely to keep your design consistent.
Always include units like rem or px when needed, or the style might not work.
Check your browser's developer tools to see the applied styles and debug if needed.
Arbitrary values let you use any CSS value inside Tailwind classes.
They help you customize designs beyond Tailwind's default options.
Use square brackets and include proper units for your custom values.
Practice
Solution
Step 1: Understand Tailwind's default options
Tailwind provides many predefined classes but cannot cover every possible CSS value.Step 2: Purpose of arbitrary values
Arbitrary values let you write any CSS value inside square brackets to customize styles beyond defaults.Final Answer:
To allow using any custom CSS value beyond default Tailwind options -> Option AQuick Check:
Arbitrary values = custom CSS values [OK]
- Thinking arbitrary values limit styling
- Confusing arbitrary values with animations
- Believing arbitrary values replace JavaScript
Solution
Step 1: Recall Tailwind arbitrary value syntax
Arbitrary values use square brackets with the CSS value inside, e.g.,w-[450px].Step 2: Check each option
Onlyw-[450px]uses square brackets and includes units correctly.Final Answer:
w-[450px]-> Option BQuick Check:
Correct syntax = w-[450px] [OK]
- Omitting square brackets
- Missing units like px
- Using dash instead of brackets
<div class="w-[30rem] bg-blue-500 text-white p-4">Hello</div>
Solution
Step 1: Interpret the class
This sets the width to exactly 30rem, which is about 480 pixels (1rem ≈ 16px).w-[30rem]Step 2: Check other classes
bg-blue-500sets a blue background,text-whitesets white text, andp-4adds padding.Final Answer:
Width of 30rem (about 480px) with blue background -> Option CQuick Check:
Arbitrary width 30rem + blue bg = Width of 30rem (about 480px) with blue background [OK]
- Confusing rem with px
- Ignoring background color class
- Assuming default width
<div class="h-[100] bg-red-400">Error</div>
Solution
Step 1: Check the arbitrary value syntax
The height is set ash-[100]but lacks units like px or rem.Step 2: Understand CSS requirements
CSS requires units for length values unless it's zero; so100alone is invalid.Final Answer:
Missing units inside the arbitrary value brackets -> Option AQuick Check:
Units required inside brackets [OK]
- Forgetting units inside arbitrary values
- Thinking brackets are wrong syntax
- Assuming Tailwind classes are invalid
Solution
Step 1: Use square brackets for arbitrary values
Custom values must be inside square brackets with units, e.g.,rounded-[12px]andp-[1.25rem].Step 2: Check each option
Onlyrounded-[12px] p-[1.25rem]correctly uses brackets and includes units for both border radius and padding.Final Answer:
rounded-[12px] p-[1.25rem]-> Option DQuick Check:
Arbitrary values need brackets + units [OK]
- Omitting brackets
- Leaving out units
- Mixing syntax without brackets
Ready to prove it?
Pass the test and this pattern moves unknown
