Break Points IN Tailwind

Break Points IN Tailwind

Table of contents

Break Points In Tailwind

  1. 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 up

  • md: 768px and up

  • lg: 1024px and up

  • xl: 1280px and up

  • 2xl: 1536px and up

  1. 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>
  1. In this example, the p-4 class applies a padding of 1rem to all sides of the element by default, and the sm:p-6 class applies a padding of 1.5rem to all sides of the element on screens that are 640px or wider.

  2. You can also create custom breakpoints in Tailwind CSS by modifying the screens configuration in your tailwind.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: [],
}
  1. This code adds a new custom breakpoint with a width of 900px to the screens configuration. You can then use this breakpoint in your HTML and CSS like any of the default breakpoints.