File size: 5,057 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
---
title: Spacing
description:
JSX style props for controlling the padding and margin of an element.
---
## Padding
### All sides
Use the `padding` prop to apply padding on all sides of an element
```jsx
// raw value
<Box padding="40px" />
<Box p="40px" /> // shorthand
// token value
<Box padding="4" />
<Box p="4" /> // shorthand
```
| Prop | CSS Property | Token Category |
| ------------- | ------------ | -------------- |
| `p`,`padding` | `padding` | `spacing` |
### Specific side
Use the `padding{Left,Right,Top,Bottom}` to apply padding on one side of an
element
```jsx
<Box paddingLeft="3" />
<Box pl="3" /> // shorthand
<Box paddingTop="3" />
<Box pt="3" /> // shorthand
```
Use the `padding{Start,End}` props to apply padding on the logical axis of an
element based on the text direction.
```jsx
<div className={css({ paddingStart: '8' })} />
<div className={css({ ps: '8' })} /> // shorthand
<div className={css({ paddingEnd: '8' })} />
<div className={css({ pe: '8' })} /> // shorthand
```
| Prop | CSS Property | Token Category |
| --------------------- | ---------------------- | -------------- |
| `pl`, `paddingLeft` | `padding-left` | `spacing` |
| `pr`, `paddingRight` | `padding-right` | `spacing` |
| `pt`, `paddingTop` | `padding-top` | `spacing` |
| `pb`, `paddingBottom` | `padding-bottom` | `spacing` |
| `ps`, `paddingStart` | `padding-inline-start` | `spacing` |
| `pe`, `paddingEnd` | `padding-inline-end` | `spacing` |
### Horizontal and Vertical padding
Use the `padding{X,Y}` props to apply padding on the horizontal and vertical
axis of an element
```jsx
<Box paddingX="8" />
<Box px="8" /> // shorthand
<Box paddingY="8" />
<Box py="8" /> // shorthand
```
| Prop | CSS Property | Token Category |
| --------------------- | ---------------------- | -------------- |
| `p`,`padding` | `padding` | `spacing` |
| `pl`, `paddingLeft` | `padding-left` | `spacing` |
| `pr`, `paddingRight` | `padding-right` | `spacing` |
| `pt`, `paddingTop` | `padding-top` | `spacing` |
| `pb`, `paddingBottom` | `padding-bottom` | `spacing` |
| `px`, `paddingX` | `padding-inline` | `spacing` |
| `py`, `paddingY` | `padding-block` | `spacing` |
| `ps`, `paddingStart` | `padding-inline-start` | `spacing` |
| `pe`, `paddingEnd` | `padding-inline-end` | `spacing` |
## Margin
### All sides
Use the `margin` prop to apply margin on all sides of an element
```jsx
<Box margin="5" />
<Box m="5" /> // shorthand
```
| Prop | CSS Property | Token Category |
| ------------ | ------------ | -------------- |
| `m`,`margin` | `margin` | `spacing` |
### Specific side
Use the `margin{Left,Right,Top,Bottom}` to apply margin on one side of an
element
```jsx
<Box marginLeft="3" />
<Box ml="3" /> // shorthand
<Box marginTop="3" />
<Box mt="3" /> // shorthand
```
Use the `margin{Start,End}` properties to apply margin on the logical axis of an
element based on the text direction.
```jsx
<Box marginStart="8" />
<Box ms="8" /> // shorthand
<Box marginEnd="8" />
<Box me="8" /> // shorthand
```
| Prop | CSS Property | Token Category |
| -------------------- | --------------------- | -------------- |
| `ml`, `marginLeft` | `margin-left` | `spacing` |
| `mr`, `marginRight` | `margin-right` | `spacing` |
| `mt`, `marginTop` | `margin-top` | `spacing` |
| `mb`, `marginBottom` | `margin-bottom` | `spacing` |
| `ms`, `marginStart` | `margin-inline-start` | `spacing` |
| `me`, `marginEnd` | `margin-inline-end` | `spacing` |
### Horizontal and Vertical margin
Use the `margin{X,Y}` properties to apply margin on the horizontal and vertical
axis of an element
```jsx
<Box marginX="8" />
<Box mx="8" /> // shorthand
<Box marginY="8" />
<Box my="8" /> // shorthand
```
| Prop | CSS Property | Token Category |
| --------------- | ------------- | -------------- |
| `mx`, `marginX` | `margin-left` | `spacing` |
| `my`, `marginY` | `margin-top` | `spacing` |
## Spacing Between
Use the `space{X,Y}` props to apply spacing between elements. This approach uses
the owl selector `> * + *` to apply the spacing between the elements using
`margin*` properties.
:::info
It's recommended to use the `space` prop over the `gap` prop for spacing when
you need negative spacing.
:::
```jsx
<Box display="flex" spaceX="8">
<Box>Item 1</Box>
<Box>Item 2</Box>
<Box>Item 3</Box>
</Box>
<Box display="flex" spaceY="8">
<Box>Item 1</Box>
<Box>Item 2</Box>
<Box>Item 3</Box>
</Box>
```
| Prop | CSS Property | Token Category |
| -------- | --------------------- | -------------- |
| `spaceX` | `margin-inline-start` | `spacing` |
| `spaceY` | `margin-block-start` | `spacing` |
|