I'm using Tailwind's default breakpoint values in a TypeScript + React project compiled with Vite. But I noticed that in my project and on a section of their documentation that both repeated instances of the same modifiers within one element. In the doc's case md::
<img class="h-48 w-full object-cover md:h-full md:w-48" src="/img/building.jpg" alt="Modern building architecture">
Is there a way to group h-full and w-48 under one md: modifier to make certain styles more readable and easier to locate?
My Attempted Solution
Using Tailwind's default color palette and default breakpoint values, I made "Hello World" take on an orange background and the heaviest available font weight when the screen size is equal to or greater than sm's default minimum width of 640px:
<h1 className="sm:bg-orange-500 sm:font-black">Hello World</h1>
To reproduce the same result using one instance of the sm modifier within the same <h1> element, I tried adding curly braces around utility classes grouped together with commas:
<h1 className="sm:{bg-orange-500, font-black}">Hello World</h1>
It is NOT possible to group several Tailwind classes under a single breakpoint prefix, such as md: or lg:. If you need to customize your classes in this way, you may want to consider using an alternative tool, such as WindiCSS or UnoCSS. These tools offer similar functionality to Tailwind, but with additional features and customization options.