Box | UI components (BETA)
The Box
component renders an empty div
container for fine tuning the spacing of components. Commonly used with the Flex component.
To see an example of how Flex
and Box
can be used for layout, check out HubSpot's Manage layouts: Flex and Box sample project.
Prop | Type | Description |
---|---|---|
alignSelf |
'start' | 'center' | 'end' | 'baseline' | 'stretch' |
Distributes a child component along the cross-axis using the available free space. Use this prop for nested Box components to align them differently from other child components in the Flex group. |
flex |
'initial' | 'auto' (default) | 'none' | Number |
Distributes components based on the available empty space around them. Options are as follows:
|
You only need to use Box
as a wrapper for components that you want to adjust. For example, if you wrap one component in a Box
with a flex
value, only that one component will have its width adjusted based on the available empty space.
Use the flex
prop in a Box
component to assign any extra spacing to components using either a default value (e.g. auto
) or a specific number. When using a number, the components will be distributed based on the ratio of their assigned numbers. This also means that, when assigning a flex
value for only one Box
, you can use any number, because any number by itself will result in all available space being assigned to that Box
.
For example, the four tiles below take up an increasing amount of space based on their flex
values.
Use the alignSelf
prop to override alignment rules for individual Box
components.
Thank you for your feedback, it means a lot to us.