Changing the default colors helps you match your website's style. It makes your design unique and consistent.
Overriding color palette in Tailwind
module.exports = {
theme: {
extend: {
colors: {
primary: '#1DA1F2',
secondary: '#14171A'
}
}
}
}Use extend to add or change colors without removing Tailwind's defaults.
Define colors as hex codes, rgb, or named colors.
brandBlue without removing default colors.module.exports = {
theme: {
extend: {
colors: {
brandBlue: '#0d47a1'
}
}
}
}module.exports = {
theme: {
colors: {
red: '#ff0000',
green: '#00ff00'
}
}
}module.exports = {
theme: {
extend: {
colors: {
gray: {
100: '#f5f5f5',
900: '#111111'
}
}
}
}
}This example shows how to override Tailwind's color palette by adding primary and secondary colors. The page background uses the primary color, and the button uses the secondary color. The button changes color on hover.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Custom Color Palette</title> <script src="https://cdn.tailwindcss.com"></script> <script> tailwind.config = { theme: { extend: { colors: { primary: '#1DA1F2', secondary: '#14171A' } } } } </script> </head> <body class="bg-primary text-white min-h-screen flex flex-col items-center justify-center"> <h1 class="text-4xl font-bold mb-4">Welcome to My Site</h1> <button class="bg-secondary px-6 py-3 rounded hover:bg-gray-700 transition">Click Me</button> </body> </html>
Always use extend unless you want to replace all default colors.
Test your colors for good contrast to keep text readable.
You can use the Tailwind Play tool to try colors live in the browser.
Override colors by adding or changing them in the Tailwind config.
Use extend to keep default colors and add your own.
Custom colors help your site look unique and match your brand.
Practice
Solution
Step 1: Understand Tailwind's default colors
Tailwind provides a default color palette for quick styling.Step 2: Purpose of overriding colors
Overriding lets you add or change colors to fit your brand or design.Final Answer:
To add or change colors to match your brand or design needs -> Option AQuick Check:
Overriding colors = Customize palette [OK]
- Thinking overriding removes all default colors
- Confusing color palette with font sizes
- Believing overriding disables Tailwind features
brandBlue without removing default colors in tailwind.config.js?Solution
Step 1: Use
To add colors without removing defaults, useextendinsidethemeextendinsidetheme.Step 2: Correct syntax for adding colors
The correct syntax isextend: { colors: { brandBlue: '#1DA1F2' } }.Final Answer:
extend: { colors: { brandBlue: '#1DA1F2' } } -> Option AQuick Check:
Use extend to add colors [OK]
- Adding colors directly under colors removes defaults
- Wrong object nesting in config
- Syntax errors like missing braces
tailwind.config.js snippet, what background color will bg-brandBlue apply?module.exports = {
theme: {
extend: {
colors: {
brandBlue: '#1DA1F2'
}
}
}
}Solution
Step 1: Check the custom color definition
The config addsbrandBluewith hex#1DA1F2.Step 2: Understand class usage
The classbg-brandBlueuses this custom color as background.Final Answer:
A bright blue color #1DA1F2 -> Option CQuick Check:
bg-brandBlue = #1DA1F2 [OK]
- Assuming default blue is used instead
- Thinking it causes an error without import
- Confusing color names with default palette
module.exports = {
theme: {
colors: {
brandRed: '#E02424'
}
}
}Solution
Step 1: Check how colors are added
Adding colors directly undercolorsreplaces all default colors.Step 2: Correct way to keep defaults
Useextend: { colors: { brandRed: '#E02424' } }insidethemeto add without removing.Final Answer:
It removes all default colors because it overwrites colors directly -> Option DQuick Check:
Direct colors overwrite defaults [OK]
- Not using extend and losing default colors
- Thinking hex code is wrong
- Misplacing config keys
brandGreen and also change the default blue color to #005f73. Which config snippet correctly does this?Solution
Step 1: Adding new colors
Usetheme.extend.colorsto addbrandGreenwithout removing defaults.Step 2: Overriding existing colors
To change defaultblue, useextend.colors.blue: '#005f73'; this overrides it while keeping other defaults.Step 3: Correct config
Place both inextend.colors:{ brandGreen: '#0a9396', blue: '#005f73' }.Final Answer:
theme: { extend: { colors: { brandGreen: '#0a9396', blue: '#005f73' } } } -> Option BQuick Check:
New + override = extend.colors [OK]
- Defining overrides under theme.colors (loses default palette)
- Overwriting colors without extend losing defaults
- Incorrect nesting of colors object
Ready to prove it?
Pass the test and this pattern moves unknown
