Table of contents
Break Points In Tailwind
- Tailwind CSS uses a mobile-first approach to responsive design, which means that all styles are applied to smaller screen sizes first, and then overridden as the screen size increases. Tailwind provides a range of breakpoints for screens of different sizes, which are listed below:
sm
: 640px and upmd
: 768px and uplg
: 1024px and upxl
: 1280px and up2xl
: 1536px and up
- These breakpoints can be used to apply specific styles to elements based on the screen size. For example, to apply different padding values to an element on small screens and larger screens, you could use the
sm
breakpoint class to target small screens and the default class for larger screens:
htmlCopy code<div class="p-4 sm:p-6">
This element has more padding on small screens.
</div>
In this example, the
p-4
class applies a padding of 1rem to all sides of the element by default, and thesm:p-6
class applies a padding of 1.5rem to all sides of the element on screens that are 640px or wider.You can also create custom breakpoints in Tailwind CSS by modifying the
screens
configuration in yourtailwind.config.js
file. For example, to add a breakpoint for screens that are 900px wide, you could add the following code:
exports = {
theme: {
screens: {
'sm': '640px',
'md': '768px',
'lg': '1024px',
'xl': '1280px',
'2xl': '1536px',
'custom': '900px',
},
},
variants: {},
plugins: [],
}
- This code adds a new
custom
breakpoint with a width of 900px to thescreens
configuration. You can then use this breakpoint in your HTML and CSS like any of the default breakpoints.