Skip to content

Instantly share code, notes, and snippets.

@heytulsiprasad
Created September 4, 2020 17:55
Show Gist options
  • Select an option

  • Save heytulsiprasad/e8bae1eba7b90ef66b8b1b1ae0861d96 to your computer and use it in GitHub Desktop.

Select an option

Save heytulsiprasad/e8bae1eba7b90ef66b8b1b1ae0861d96 to your computer and use it in GitHub Desktop.
Config tailwind to desktop first approach
module.exports = {
theme: {
extend: {},
screens: {
xl: { max: "1279px" },
// => @media (max-width: 1279px) { ... }
lg: { max: "1023px" },
// => @media (max-width: 1023px) { ... }
md: { max: "767px" },
// => @media (max-width: 767px) { ... }
sm: { max: "639px" },
// => @media (max-width: 639px) { ... }
},
},
variants: {},
plugins: [],
};
@won5572

won5572 commented Apr 29, 2022

Copy link
Copy Markdown

It's good idea.

@heytulsiprasad

Copy link
Copy Markdown
Author

It's good idea.

Yes, I always start with this approach.

@prathamesh-dukare

Copy link
Copy Markdown

aww, awesome stuff! my problem with desktop first is sorted

@heguerack

Copy link
Copy Markdown

Thank you! I will try it

@DonUggioni

Copy link
Copy Markdown

This works like a charm! Thank you!

@hannaofsweden

hannaofsweden commented Mar 2, 2023

Copy link
Copy Markdown

Containers will not work as expected unless you add something like this to your global stylesheet:

@layer base {
  .container {
    @apply max-w-[1280px] xl:max-w-[1024px] lg:max-w-[768px] md:max-w-[640px];
  }
}

@eroffa

eroffa commented Apr 12, 2023

Copy link
Copy Markdown

Improvement

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ['./src/**/*.{html,js}'],
  theme: {
    screens: {
      '2xl': {'max': '1535px'},
      'xl': {'max': '1279px'},
      'lg': {'max': '1023px'},
      'md': {'max': '767px'},
      'sm': {'max': '639px'},
    },
    container: {
      center: true,
      padding: '2rem',
    },
  },
  plugins: [],
}
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
    .container {
        @apply max-w-[1535px] xl:max-w-[1279px] lg:max-w-[1023px] md:max-w-[767px] sm:max-w-[639px];
    }
}

@layer components {}
@layer utilities {}

ghost commented Oct 8, 2023

Copy link
Copy Markdown

very nice idea for indian work

@cyrus01337

Copy link
Copy Markdown

@eroffa It's been a while since you've posted this so my bad if it's too late to ask.

Could you explain why you made the changes that you did to the original config?

@HamzaHamani

Copy link
Copy Markdown

@eroffa It's been a while since you've posted this so my bad if it's too late to ask.

Could you explain why you made the changes that you did to the original config?

he basically added more breakpoints for using max-width 'pc first' instead of the original approach in tailwind with mix-with 'mobile first'

@cyrus01337

cyrus01337 commented Dec 17, 2023

Copy link
Copy Markdown

he basically added more breakpoints for using max-width 'pc first' instead of the original approach in tailwind with mix-with 'mobile first'

Appreciate you. ❤️

@hxadogar

Copy link
Copy Markdown

We can also use (Fixed-range) Breakpoints:

module.exports = {
  theme: {
    screens: {
      'sm': {'min': '640px', 'max': '767px'},
      // => @media (min-width: 640px and max-width: 767px) { ... }

      'md': {'min': '768px', 'max': '1023px'},
      // => @media (min-width: 768px and max-width: 1023px) { ... }

      'lg': {'min': '1024px', 'max': '1279px'},
      // => @media (min-width: 1024px and max-width: 1279px) { ... }

      'xl': {'min': '1280px', 'max': '1535px'},
      // => @media (min-width: 1280px and max-width: 1535px) { ... }

      '2xl': {'min': '1536px'},
      // => @media (min-width: 1536px) { ... }
    },
  }
}

Arbitrary value

<div class="min-[320px]:text-center max-[600px]:bg-sky-300">
  Hello world
</div>

@izhan

izhan commented Aug 10, 2024

Copy link
Copy Markdown

Wrote a guide for desktop-first Tailwind here: https://www.subframe.com/blog/how-to-make-tailwind-desktop-first

Also recommend naming your breakpoints like so, especially if you're working on a web app:

/** @type {import('tailwindcss').Config} */
module.exports = {
  theme: {
    extend: {
      screens: {
        mobile: { max: "479px" },
        // => @media (max-width: 479px) { ... }

        tablet: { max: "767px" },
        // => @media (max-width: 767px) { ... }

        desktop: { min: "768px" },
        // => @media (min-width: 768px) { ... }
      },
    },
  },
}

@Truecoder513

Copy link
Copy Markdown

@izhan how can we make this config in tailwind 4 with the configuration in css file please

@osmuhin

osmuhin commented Feb 4, 2025

Copy link
Copy Markdown

@izhan how can we make this config in tailwind 4 with the configuration in css file please

@import "tailwindcss";

@custom-variant 2xl (@media (max-width: 96rem));
@custom-variant xl (@media (max-width: 80rem));
@custom-variant lg (@media (max-width: 64rem));
@custom-variant md (@media (max-width: 48rem));
@custom-variant sm (@media (max-width: 40rem));

@Truecoder513

Copy link
Copy Markdown

@izhan thks

@vietthai3011

Copy link
Copy Markdown

Thanks

@benemmaofficial

Copy link
Copy Markdown

@izhan how can we make this config in tailwind 4 with the configuration in css file please

@import "tailwindcss";

@custom-variant 2xl (@media (max-width: 96rem));
@custom-variant xl (@media (max-width: 80rem));
@custom-variant lg (@media (max-width: 64rem));
@custom-variant md (@media (max-width: 48rem));
@custom-variant sm (@media (max-width: 40rem));

This is it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment