📖 Scenario: You are building a simple webpage for a local bakery. The bakery wants a unique color theme that matches their brand colors instead of the default Tailwind colors.
🎯 Goal: Create a Tailwind CSS configuration that overrides the default color palette with the bakery's brand colors. Then use these custom colors in the webpage's background and text.
📋 What You'll Learn
Create a Tailwind CSS config file with a custom color palette
Add two custom colors: brand-primary with hex #D2691E and brand-secondary with hex #F5DEB3
Use brand-primary as the background color of the main section
Use brand-secondary as the text color inside the main section
Ensure the HTML uses semantic elements and is accessible
💡 Why This Matters
🌍 Real World
Many companies want their websites to match their brand colors exactly. Overriding Tailwind's color palette lets developers create consistent, branded designs quickly.
💼 Career
Web developers often customize CSS frameworks like Tailwind to meet client branding requirements. Knowing how to override and use custom colors is a key skill.
Progress0 / 4 steps
1
Create Tailwind CSS config file with default export
Create a file named tailwind.config.js and write export default {} to start the Tailwind CSS configuration.
Tailwind
Hint
This file tells Tailwind how to customize styles. Start with an empty export.
2
Add custom colors to the Tailwind config
Inside the tailwind.config.js file, add a theme object with a extend property. Inside extend, add a colors object with brand-primary set to "#D2691E" and brand-secondary set to "#F5DEB3".
Tailwind
Hint
Use theme.extend.colors to add new colors without removing defaults.
3
Create HTML structure using custom colors
Create an index.html file with a <main> element. Inside <main>, add a <h1> with the text "Welcome to the Bakery". Use Tailwind classes bg-brand-primary on <main> and text-brand-secondary on <h1>.
Tailwind
Hint
Use the custom colors as Tailwind classes exactly as bg-brand-primary and text-brand-secondary.
4
Add accessibility and responsive padding
In the index.html file, add role="main" to the <main> element for accessibility. Also add responsive padding classes p-4 sm:p-8 to <main> to make padding adjust on small screens.
Tailwind
Hint
Use role="main" for screen readers and responsive padding classes p-4 sm:p-8 for better mobile experience.
Practice
(1/5)
1. What is the main purpose of overriding the color palette in Tailwind CSS?
easy
A. To add or change colors to match your brand or design needs
B. To remove all default colors from Tailwind
C. To disable Tailwind's color utilities completely
D. To change the font sizes in Tailwind
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 A
Quick Check:
Overriding colors = Customize palette [OK]
Hint: Overriding colors means customizing palette, not removing defaults [OK]
Common Mistakes:
Thinking overriding removes all default colors
Confusing color palette with font sizes
Believing overriding disables Tailwind features
2. Which is the correct way to add a custom color named brandBlue without removing default colors in tailwind.config.js?
easy
A. extend: { colors: { brandBlue: '#1DA1F2' } }
B. colors: { brandBlue: '#1DA1F2' }
C. theme: { colors: { brandBlue: '#1DA1F2' } }
D. colors: extend { brandBlue: '#1DA1F2' }
Solution
Step 1: Use extend inside theme
To add colors without removing defaults, use extend inside theme.
Step 2: Correct syntax for adding colors
The correct syntax is extend: { colors: { brandBlue: '#1DA1F2' } }.
D. It removes all default colors because it overwrites colors directly
Solution
Step 1: Check how colors are added
Adding colors directly under colors replaces all default colors.
Step 2: Correct way to keep defaults
Use extend: { colors: { brandRed: '#E02424' } } inside theme to add without removing.
Final Answer:
It removes all default colors because it overwrites colors directly -> Option D
Quick Check:
Direct colors overwrite defaults [OK]
Hint: Direct colors overwrite defaults; use extend to add [OK]
Common Mistakes:
Not using extend and losing default colors
Thinking hex code is wrong
Misplacing config keys
5. You want to override the Tailwind color palette to add brandGreen and also change the default blue color to #005f73. Which config snippet correctly does this?