Custom breakpoints let you control when your website changes layout on different screen sizes. This helps your site look good on phones, tablets, and desktops.
Custom breakpoints in Tailwind
module.exports = {
theme: {
extend: {},
screens: {
'sm': '480px',
'md': '768px',
'lg': '1024px',
'xl': '1280px',
'2xl': '1536px',
'tablet': '640px',
'laptop': '1024px',
'desktop': '1280px'
}
}
}Define custom breakpoints inside the screens object in your tailwind.config.js file.
Use the breakpoint names as prefixes in your CSS classes, like tablet:bg-blue-500.
phone, tablet, and desktop.screens: {
'phone': '375px',
'tablet': '640px',
'desktop': '1024px'
}<div class="phone:bg-red-500 tablet:bg-green-500 desktop:bg-blue-500">
Responsive box
</div>This page uses custom breakpoints named phone, tablet, and desktop. The box changes its background color as you resize the browser window.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Custom Breakpoints Example</title> <script src="https://cdn.tailwindcss.com"></script> <script> tailwind.config = { theme: { extend: {}, screens: { 'phone': '375px', 'tablet': '640px', 'desktop': '1024px' } } } </script> </head> <body class="p-6"> <div class="phone:bg-red-300 tablet:bg-green-300 desktop:bg-blue-300 p-6 rounded"> Resize the browser to see background color change. </div> </body> </html>
After changing tailwind.config.js, restart your build process if you use one.
Use meaningful names for breakpoints that match your design needs.
Test your site on different devices or use browser DevTools to resize and check responsiveness.
Custom breakpoints let you control layout changes at screen widths you choose.
Define them in the screens section of tailwind.config.js.
Use breakpoint names as prefixes in your Tailwind CSS classes to apply styles conditionally.
Practice
Solution
Step 1: Understand what breakpoints do
Breakpoints let you apply different styles depending on screen size.Step 2: Identify the role of custom breakpoints
Custom breakpoints let you choose specific screen widths for style changes.Final Answer:
To control when styles change based on screen width -> Option DQuick Check:
Breakpoints = screen width control [OK]
- Confusing breakpoints with colors or fonts
- Thinking breakpoints create animations
- Assuming breakpoints change global styles
tablet at 768px in tailwind.config.js?Solution
Step 1: Identify the correct config key
Custom breakpoints go under the "screens" key in tailwind.config.js.Step 2: Use correct value format
Breakpoint values must be strings with units, e.g., "768px".Final Answer:
"screens": { "tablet": "768px" } -> Option AQuick Check:
screens + "768px" string = correct syntax [OK]
- Using number without units
- Using wrong key like "breakpoints"
- Omitting "px" unit in value
module.exports = { theme: { screens: { 'md': '640px', 'lg': '1024px', 'xl': '1280px' } } }Which class applies padding only on screens 1024px wide or larger?
Solution
Step 1: Understand breakpoint prefixes
Tailwind uses breakpoint names as prefixes followed by a colon, e.g., "lg:".Step 2: Match breakpoint to screen size
"lg" is 1024px, so "lg:p-4" applies padding at 1024px and above.Final Answer:
lg:p-4 -> Option AQuick Check:
Prefix "lg:" = 1024px+ padding [OK]
- Using breakpoint name after class (wrong order)
- Missing colon after breakpoint
- Confusing md and lg breakpoints
tablet at 768px but your styles using tablet:bg-red-500 don't apply. What is the likely error?Solution
Step 1: Check config changes effect
Tailwind requires restarting the build to load new config values.Step 2: Verify syntax and placement
Using "tablet:bg-red-500" is correct syntax; spacing or wrong keys cause errors but less likely here.Final Answer:
You forgot to restart the Tailwind build process after config change -> Option CQuick Check:
Restart build after config edits [OK]
- Using dash (-) instead of colon (:) in class prefix
- Defining breakpoint in wrong config section
- Adding spaces inside class names
desktop at 900px. Which Tailwind class setup correctly hides the sidebar on smaller screens and shows it on desktop and larger?Solution
Step 1: Understand default and breakpoint styles
"hidden" hides element by default (all screens). "desktop:block" shows it at 900px+.Step 2: Match classes to desired behavior
Using "hidden desktop:block" hides sidebar on small screens and shows on desktop and larger.Final Answer:
hidden desktop:block -> Option BQuick Check:
hidden + breakpoint:block = show on breakpoint [OK]
- Reversing hidden and block classes
- Using breakpoint:hidden instead of breakpoint:block
- Incorrect class order or syntax
Ready to prove it?
Pass the test and this pattern moves unknown
