Building Responsive React UIs With Tailwind CSS
Tailwind makes responsive design easy with breakpoint prefixes. Here is how to build responsive React UIs.
Building Responsive React UIs With Tailwind CSS
Responsive design is where Tailwind shines. Its breakpoint prefixes let you write responsive styles inline without media queries. Here is how to build responsive React UIs.
The Breakpoint Prefixes
Tailwind uses prefixes like sm:, md:, lg:, and xl: to apply styles at different screen sizes. For example, md:flex means apply flex from the medium breakpoint up.
Mobile-First by Default
Tailwind is mobile-first. A class without a prefix applies at all sizes. A prefixed class applies at that breakpoint and up. So write base styles first, then add larger-screen styles with prefixes.
A Responsive Grid
You can write grid-cols-1 md:grid-cols-3 to show one column on mobile and three on larger screens, all in one className. No media queries in a CSS file.
Responsive Spacing
Use prefixes for spacing too: p-4 md:p-8 gives more padding on larger screens. This keeps responsive adjustments colocated with the element.
Hiding and Showing
Use hidden md:block to hide an element on mobile and show it on larger screens, or block md:hidden for the opposite. This is common for navigation toggles.
Avoid Hardcoded Sizes
Use Tailwind's spacing scale rather than arbitrary pixel values, so your responsive adjustments stay consistent with your design tokens.
The Takeaway
Tailwind's breakpoint prefixes let you write responsive styles inline, mobile-first. Write base styles, then add sm:, md:, lg:, and xl: prefixes for larger screens, all in the className without separate media queries.
Tailwind uses breakpoint prefixes like sm:, md:, lg:, and xl: to apply styles at different screen sizes. You write responsive styles inline in the className, without separate media query files.
Yes. A class without a prefix applies at all sizes. A prefixed class like md:flex applies at that breakpoint and up. So you write base mobile styles first, then add larger-screen styles with prefixes.
Use prefixes on grid-cols. For example, grid-cols-1 md:grid-cols-3 shows one column on mobile and three on larger screens, all in one className with no media queries.
Use hidden md:block to hide on mobile and show on larger screens, or block md:hidden for the opposite. This is common for navigation toggles and elements that should only appear at certain sizes.
Prefer Tailwind's spacing scale over arbitrary pixel values, so your responsive adjustments stay consistent with your design tokens. Arbitrary values are available when you truly need them, but the scale keeps things consistent.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

