Sanity UI array syntax for padding and breakpoints explanation

2 replies
Last updated: Jul 22, 2021
Sanity UI—what's up with the arrays to set some variables? Is it for breakpoints? e.g.
padding={[3, 3, 4]}
AI Update

Exactly! Yes, those array props in Sanity UI are for responsive breakpoints.

When you write something like padding={[3, 3, 4]}, you're defining different padding values at different viewport breakpoints. The array maps to Sanity UI's built-in media query breakpoints:

  • Index 0 (first value): applies at the smallest breakpoint (default: 0px)
  • Index 1 (second value): applies at the next breakpoint (default: 360px)
  • Index 2 (third value): applies at the next breakpoint (default: 600px)
  • And so on for larger breakpoints (900px, 1200px, etc.)

So padding={[3, 3, 4]} means:

  • Padding of 3 at 0px and above
  • Padding of 3 at 360px and above
  • Padding of 4 at 600px and above

This pattern is called responsive props in Sanity UI, and it works across many components and properties like padding, margin, fontSize, space, etc. It's a convenient way to handle responsive design without writing media queries manually.

The Sanity UI documentation mentions that "many primitives support responsive properties through arrays, allowing different values at various breakpoints for properties like size, padding, and spacing." This approach is inspired by similar patterns in other design systems like Theme UI and Styled System, making it familiar if you've used those libraries before.

You can see this pattern in action throughout the Sanity UI codebase—look at components like Box, Stack, Text, and others that accept spacing and sizing props.

Show original thread
2 replies
You're exactly right: it's for breakpoints. I'm not sure if it's documented yet (I'll take a look a bit later) but if you check the Arcade you can see them in action.
Perfect. Thanks—I did a little test myself and confirmed 🙂
Doesn't look like it's documented yet as far as I can tell. Getting Started just has an example of setting a single number for padding. No mention I could find on what the breakpoints are—ordering, browser sizes, etc.

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?