Custom spacing scale lets you create your own sizes for margins, padding, and gaps. This helps keep your design consistent and unique.
Custom spacing scale in Tailwind
module.exports = {
theme: {
extend: {
spacing: {
'72': '18rem',
'84': '21rem',
'96': '24rem',
'128': '32rem'
}
}
}
}Put your custom spacing inside the extend.spacing section to add to the default scale.
Use keys as strings for spacing names and values as CSS size units like rem, px, or %.
72 equal to 18rem.module.exports = {
theme: {
extend: {
spacing: {
'72': '18rem'
}
}
}
}sm, md, and lg with pixel values.module.exports = {
theme: {
extend: {
spacing: {
'sm': '8px',
'md': '16px',
'lg': '24px'
}
}
}
}half that equals 50% of the parent size.module.exports = {
theme: {
extend: {
spacing: {
'half': '50%'
}
}
}
}This example shows two boxes with very large padding using custom spacing sizes 72 and 84. The spacing is added to Tailwind's default scale using extend.spacing.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Custom Spacing Scale Example</title> <script src="https://cdn.tailwindcss.com"></script> <script> tailwind.config = { theme: { extend: { spacing: { '72': '18rem', '84': '21rem' } } } } </script> </head> <body class="p-8"> <div class="bg-blue-200 p-72 text-center"> This box has padding of 18rem (custom spacing 72). </div> <div class="bg-green-200 mt-8 p-84 text-center"> This box has padding of 21rem (custom spacing 84). </div> </body> </html>
Always use extend to add spacing so you don't remove Tailwind's default sizes.
You can use any CSS unit like rem, px, %, or em for spacing values.
Use meaningful names for spacing to make your code easier to understand.
Custom spacing scale lets you add your own spacing sizes to Tailwind.
Put your sizes inside extend.spacing in the Tailwind config.
Use your custom spacing classes like p-72 or m-84 in your HTML.
Practice
Solution
Step 1: Understand Tailwind spacing scale
Tailwind provides default spacing sizes, but sometimes you need sizes not included by default.Step 2: Purpose of custom spacing scale
Adding a custom spacing scale lets you define new spacing values to use in classes like padding or margin.Final Answer:
To create new spacing sizes beyond the default ones -> Option AQuick Check:
Custom spacing scale = new spacing sizes [OK]
- Confusing spacing scale with colors or fonts
- Thinking it enables animations
- Assuming it changes existing default sizes
Solution
Step 1: Locate correct config property for spacing
Custom spacing values go inside theextend.spacingobject in tailwind.config.js.Step 2: Check syntax correctness
"extend: { spacing: { 72: '18rem' } }" inside tailwind.config.js correctly places 72: '18rem' inside extend.spacing. Other options put spacing at root or wrong keys like colors or fontSize.Final Answer:
"extend: { spacing: { 72: '18rem' } }" inside tailwind.config.js -> Option CQuick Check:
Custom spacing inside extend.spacing [OK]
- Placing spacing directly at root instead of extend
- Adding spacing under colors or fontSize
- Using incorrect syntax or missing quotes
{
extend: {
spacing: {
84: '21rem'
}
}
}
What will be the padding size applied by the class p-84 in HTML?Solution
Step 1: Understand custom spacing value
The config defines spacing 84 as '21rem', so class p-84 means padding: 21rem.Step 2: Interpret class effect
Class p-84 applies padding of 21rem on all sides of the element.Final Answer:
21rem padding on all sides -> Option DQuick Check:
p-84 = padding 21rem [OK]
- Confusing 84 with 8.4 or 2.1 rem
- Thinking class is invalid without default spacing
- Assuming padding applies only to one side
extend: {
spacing: {
100: '25rem'
}
}
But using m-100 in HTML does not apply margin. What is the likely problem?Solution
Step 1: Check if config syntax is correct
The config syntax is correct; 100: '25rem' inside extend.spacing is valid.Step 2: Understand Tailwind build process
After changing tailwind.config.js, you must restart the build or dev server to apply changes.Final Answer:
You forgot to restart the build process after config change -> Option BQuick Check:
Restart build after config update [OK]
- Assuming spacing value format is wrong
- Using wrong class name syntax
- Thinking Tailwind disallows custom spacing
extend.spacing part in tailwind.config.js to use both sizes correctly?Solution
Step 1: Correct syntax for multiple custom spacings
Custom spacing values go inside extend.spacing as key-value pairs with keys as numbers and values as strings with units.Step 2: Analyze incorrect options
Placing spacing at the root overrides defaults. Using string keys or numeric values without units is invalid. Arrays are not supported for spacing definitions.Final Answer:
{ extend: { spacing: { 72: '18rem', 84: '21rem' } } } -> Option AQuick Check:
Multiple spacings as key-value pairs in extend.spacing [OK]
- Using numbers without units for spacing values
- Placing spacing outside extend
- Using arrays instead of objects for spacing
Ready to prove it?
Pass the test and this pattern moves unknown
