Using Chakra UI's Responsive Style Props for Declarative Layouts
Learn how Chakra UI’s responsive style props let you declare breakpoint‑specific values directly in JSX, reducing media‑query boilerplate and keeping layout logic close to your components.
24 Jun 2026, 21:38 UTC

Problem: Hard‑coded media queries clutter JSX
When building a responsive layout with plain CSS or CSS‑in‑JS, developers often write separate media queries for each breakpoint. This approach scatters styling logic across files, makes it hard to see the full responsive behavior at a glance, and increases the chance of mismatched values when breakpoints change.
Thesis: Chakra UI’s responsive style props let you declare breakpoint‑specific values directly in JSX, keeping layout logic close to the component and reducing boilerplate.
How the system works
Chakra UI’s theme defines a breakpoints array (default: ['base', 'sm', 'md', 'lg', 'xl']). Style props such as width, margin, padding, fontSize, etc., accept either an array or an object where each entry corresponds to a breakpoint in order. At runtime, Chakra UI translates the array into a series of @media screen and (min-width: …) rules using the breakpoint values from the theme.
For JavaScript logic, the useBreakpointValue hook provides the same breakpoint‑aware selection, enabling conditional rendering or calculations without writing custom media queries.
Worked example: a responsive card
Consider a card that should take the full width on small screens, half width on medium screens, and a quarter width on large screens. Using responsive style props, the JSX looks like this:
import { Box, Text } from '@chakra-ui/react';
function ResponsiveCard() {
return (
Responsive Card
);
}
To verify the generated CSS, open Chrome DevTools, select the Box element, and view the Styles pane. You should see rules similar to:
@media screen and (min-width: 40em) { width: 50%; }
@media screen and (min-width: 64em) { width: 25%; }
(The exact em values come from the theme’s breakpoint definitions.)
Trade‑off and limitation
The main limitation is index coupling: if you customize the theme’s breakpoints (e.g., add a 2xl breakpoint) but leave existing responsive arrays unchanged, the mapping shifts. A width array of [ '100%', '50%', '25%' ] would now apply 50% at the old sm breakpoint instead of the new md, potentially breaking layouts.
Practical way to check: after updating the theme with extendTheme({ breakpoints: [..., '2xl'] }), reload the app and resize the browser. Observe the points at which the width changes; they should align with the new breakpoint values. If they don’t, adjust the arrays to match the new breakpoint order.
Actionable closing
Start by extracting responsive configurations into reusable components or custom props when the JSX becomes dense. For example:
const responsiveWidth = { base: '100%', sm: '50%', md: '25%' };
…
This keeps the component readable while still leveraging Chakra UI’s declarative responsive system. When you need breakpoint‑aware JavaScript, reach for useBreakpointValue instead of writing custom media queries. By keeping layout definitions close to the component and verifying changes via DevTools, you maintain a clear, maintainable responsive design.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.