|
| 1 | +--- |
| 2 | +title: Layout Spacing |
| 3 | +category: Guides |
| 4 | +order: 7 |
| 5 | +relevantForAI: true |
| 6 | +--- |
| 7 | + |
| 8 | +## Layout Spacing |
| 9 | + |
| 10 | +```js |
| 11 | +--- |
| 12 | +type: embed |
| 13 | +--- |
| 14 | +<Alert variant="warning" margin="0 0 medium"> |
| 15 | + The spacing tokens documented on this page (such as <code>general.spaceMd</code>) require <strong>v11.7+</strong> components and are applied through the <code>margin</code> and <code>padding</code> props. If you are viewing the v11.6 version, <Link href={window.location.pathname.match(/v\d+_\d+/) ? window.location.pathname.replace(/v\d+_\d+/, 'v11_7') : `/v11_7${window.location.pathname}`}>switch to v11.7</Link> to see the examples working correctly. |
| 16 | +</Alert> |
| 17 | +``` |
| 18 | + |
| 19 | +Our design system provides a set of spacing tokens for consistent layouts and components. The current tokens are organized into a general t-shirt scale plus a handful of semantic tokens. Some tokens share a value but carry different meaning — prefer the semantically correct token for the context (e.g. use `gap.buttons` for spacing between buttons). |
| 20 | + |
| 21 | +The `margin` and `padding` props on InstUI components accept these tokens via **dot-path notation** (for example `margin="general.spaceMd"` or `padding="padding.card.lg"`), and support the familiar CSS-like 1–4 value shorthand. |
| 22 | + |
| 23 | +## Tokens |
| 24 | + |
| 25 | +### General scale |
| 26 | + |
| 27 | +| Key | Value | Value in pixels | |
| 28 | +| ----------------- | -------- | --------------- | |
| 29 | +| general.spaceNone | 0rem | 0px | |
| 30 | +| general.space2xs | 0.125rem | 2px | |
| 31 | +| general.spaceXs | 0.25rem | 4px | |
| 32 | +| general.spaceSm | 0.5rem | 8px | |
| 33 | +| general.spaceMd | 0.75rem | 12px | |
| 34 | +| general.spaceLg | 1rem | 16px | |
| 35 | +| general.spaceXl | 1.5rem | 24px | |
| 36 | +| general.space2xl | 2rem | 32px | |
| 37 | + |
| 38 | +### Semantic tokens |
| 39 | + |
| 40 | +| Key | Value | Value in pixels | |
| 41 | +| ----------------------------- | ------- | --------------- | |
| 42 | +| gap.sections | 3rem | 48px | |
| 43 | +| gap.buttons | 0.75rem | 12px | |
| 44 | +| gap.cards.sm | 0.75rem | 12px | |
| 45 | +| gap.cards.md | 1rem | 16px | |
| 46 | +| gap.cards.lg | 1.5rem | 24px | |
| 47 | +| gap.cards.nestedContainers.sm | 0.5rem | 8px | |
| 48 | +| gap.cards.nestedContainers.md | 0.75rem | 12px | |
| 49 | +| gap.cards.nestedContainers.lg | 1rem | 16px | |
| 50 | +| gap.inputs.horizontal | 0.75rem | 12px | |
| 51 | +| gap.inputs.vertical | 1rem | 16px | |
| 52 | +| padding.card.sm | 0.5rem | 8px | |
| 53 | +| padding.card.md | 0.75rem | 12px | |
| 54 | +| padding.card.lg | 1rem | 16px | |
| 55 | + |
| 56 | +## Applying spacing |
| 57 | + |
| 58 | +### Using the `margin` prop |
| 59 | + |
| 60 | +Most components support a `margin` prop that works like the CSS `margin` property. Pass a single token or use the 1–4 value shorthand to fine-tune individual edges. |
| 61 | + |
| 62 | +```js |
| 63 | +--- |
| 64 | +type: example |
| 65 | +--- |
| 66 | +<View as="div" display="block" borderWidth="small" padding="general.spaceSm"> |
| 67 | + <Button margin="0 general.spaceSm 0 0">Button 1</Button> |
| 68 | + <Button>Button 2</Button> |
| 69 | +</View> |
| 70 | +``` |
| 71 | + |
| 72 | +### Using the `padding` prop |
| 73 | + |
| 74 | +Components that render their own surface accept a `padding` prop, which resolves the same tokens. Semantic `padding.card.*` tokens are a good fit for card-like containers. |
| 75 | + |
| 76 | +```js |
| 77 | +--- |
| 78 | +type: example |
| 79 | +--- |
| 80 | +<View as="div" display="block" borderWidth="small" padding="padding.card.lg"> |
| 81 | + This container uses <code>padding.card.lg</code>. |
| 82 | +</View> |
| 83 | +``` |
| 84 | + |
| 85 | +## Deprecated tokens |
| 86 | + |
| 87 | +For compatibility reasons we still resolve two earlier generations of spacing tokens at runtime, but they should **not** be used when creating new layouts — prefer the current tokens above. |
| 88 | + |
| 89 | +### Phased-out tokens |
| 90 | + |
| 91 | +The flat `space0`–`space60` scale and the flat semantic tokens (`sections`, `buttons`, `paddingCardLarge`, `selects`, `tags`, etc.) were an interim set and have been superseded by the current general scale and dot-path semantic tokens. |
| 92 | + |
| 93 | +### Legacy tokens |
| 94 | + |
| 95 | +The original legacy keywords (`xxxSmall`, `small`, `medium`, `large`, `xxLarge`, etc.) remain so old layouts don't break when updating InstUI. |
0 commit comments