Extending default theme values lets you add your own colors, fonts, or sizes without losing the original Tailwind styles.
Extending default theme values in Tailwind
module.exports = {
theme: {
extend: {
propertyName: {
key: 'value'
}
}
}
}extend is used inside the theme section to add new values.
You keep all default values and add your own by placing them inside extend.
brandBlue without removing default colors.module.exports = {
theme: {
extend: {
colors: {
brandBlue: '#1DA1F2'
}
}
}
}xxs alongside default sizes.module.exports = {
theme: {
extend: {
fontSize: {
'xxs': '0.65rem'
}
}
}
}72 and 84 for margin or padding.module.exports = {
theme: {
extend: {
spacing: {
'72': '18rem',
'84': '21rem'
}
}
}
}This example shows how to add a new color brandBlue and a tiny font size xxs. The heading uses the new color, and the paragraph uses the new font size.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Tailwind Extend Theme Example</title> <script src="https://cdn.tailwindcss.com"></script> <script> tailwind.config = { theme: { extend: { colors: { brandBlue: '#1DA1F2' }, fontSize: { xxs: '0.65rem' } } } } </script> </head> <body class="p-6"> <h1 class="text-brandBlue text-3xl font-bold">Hello Brand Blue!</h1> <p class="text-xxs mt-2">This is extra small text using extended font size.</p> </body> </html>
Always use extend to add values so you don't remove Tailwind's defaults.
You can extend colors, spacing, font sizes, and many other theme properties.
Use the Tailwind CDN tailwind.config object for quick testing or update your tailwind.config.js file in projects.
Use extend inside theme to add new styles without losing defaults.
You can add colors, font sizes, spacing, and more this way.
This helps keep your design consistent and easy to update.
Practice
extend inside the theme in Tailwind CSS?Solution
Step 1: Understand the role of
Theextendin Tailwindextendkey insidethemeallows you to add new values while keeping the default ones intact.Step 2: Compare with replacing defaults
If you don't useextendand directly define values, you replace the defaults, losing them.Final Answer:
To add new styles without removing the default Tailwind styles -> Option CQuick Check:
Extend = Add without losing defaults [OK]
- Thinking extend replaces default styles
- Confusing extend with purge or disable
- Assuming extend removes unused styles
brandBlue with hex #1DA1F2 using extend in Tailwind config?Solution
Step 1: Locate where to put extend
Theextendkey must be inside thethemeobject to add new values.Step 2: Add new color inside extend.colors
The new color name and value go insidecolorsnested underextend.Final Answer:
"theme": { "extend": { "colors": { "brandBlue": "#1DA1F2" } } } -> Option AQuick Check:
Extend inside theme, colors inside extend [OK]
- Placing extend outside theme
- Adding colors directly inside theme without extend
- Misplacing extend inside colors
{
theme: {
extend: {
colors: {
softGreen: '#a8d5ba'
}
}
}
}Which class applies the new color as background?
Solution
Step 1: Understand Tailwind class naming for custom colors
Tailwind generates utility classes using the exact key name from the theme object as the class suffix, preserving case and format.softGreen(camelCase) becomesbg-softGreen.Step 2: Form the background color class
Background color classes arebg-followed by the exact color key name.Final Answer:
bg-softGreen -> Option DQuick Check:
Exact key match: softGreen -> bg-softGreen [OK]
- Assuming Tailwind converts camelCase to lowercase
- Adding hyphens between camelCase words
- Using underscores in place of camelCase
{
theme: {
extend: {
spacing: 72: '18rem'
}
}
}Solution
Step 1: Check syntax for spacing extension
Thespacingkey must have an object with key-value pairs inside curly braces.Step 2: Identify missing braces
Here,spacing: 72: '18rem'misses curly braces around{ 72: '18rem' }.Final Answer:
Missing curly braces around spacing values -> Option BQuick Check:
Objects need braces: spacing: { 72: '18rem' } [OK]
- Forgetting braces around nested objects
- Putting spacing inside colors by mistake
- Placing extend outside theme
xxl with value 2.5rem but keep all default font sizes. Which config snippet correctly extends the fontSize theme without losing defaults?Solution
Step 1: Understand how to keep default font sizes
To keep defaults, new values must be added insideextendundertheme.Step 2: Check each option's structure
{ theme: { extend: { fontSize: { xxl: '2.5rem' } } } } correctly placesfontSizeinsideextendinsidetheme. Others replace or misplace keys.Final Answer:
{ theme: { extend: { fontSize: { xxl: '2.5rem' } } } } -> Option AQuick Check:
Extend inside theme keeps defaults while adding new values [OK]
- Replacing fontSize directly, losing defaults
- Placing extend outside theme
- Omitting extend and overwriting defaults
Ready to prove it?
Pass the test and this pattern moves unknown
