Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tailwind CSS custom breakpoints not working

I registered a custom breakpoint ('mymd': '962px') and after that all breakpoints that are lower in width do not work

tailwind.config.js

module.exports = {
  purge: [],
  darkMode: 'media', // or 'media' or 'class'
  theme: {
    screens: {
      'sm': '640px',
      'md': '768px',
      'mymd': '962px',
      'lg': '1024px',
      'xl': '1280px',
      '2xl': '1536px',
    },
  },
  variants: {
    extend: {},
  },
  plugins: [

  ],
}

html

<div class="sm:bg-red-900 
            md:bg-yellow-900 
            mymd:bg-gray-900 
            lg:bg-green-900 
            xl:bg-blue-900 
            2xl:bg-indigo-900 
            h-screen w-full">
2xl, xl, lg and mymd work correctly, but md & sm doesn't work

img - https://ibb.co/D4x3vF8

like image 625
Alex Avatar asked Jun 17 '26 12:06

Alex


2 Answers

I cannot create a new breakpoint between the default breakpoint, but I did this

theme

const defaultTheme = require('tailwindcss/defaulttheme');

module.exports = {
  purge: [],
  darkMode: 'media', // or 'media' or 'class'
  theme: {
    screens: {
      'xs': '425px',
      ...defaultTheme.screens,
    },
    extend: {
      screens: {
        '3xl': '1920px',
      },
    },
  },
  variants: {
    extend: {},
  },
  plugins: [

  ],
}

HTML

<div class="sm:bg-red-900
            lg:bg-green-900
            3xl:bg-indigo-900
            h-screen w-full">
</div>
like image 185
Alex Avatar answered Jun 21 '26 03:06

Alex


Try extending,

theme: {
 screens: {
   'sm': '640px',
   'md': '768px',
   'lg': '1024px',
   'xl': '1280px',
   '2xl': '1536px',
  },
  extend: {
    screens: {
      'mymd': '962px'
    }
  },
},

Update:

Seems to be working fine - check this sandbox You can view the result here

like image 39
painotpi Avatar answered Jun 21 '26 02:06

painotpi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!