Learn how to customize UI extension layout using Flex, Box, and Inline components.
width
prop for images. But you can further configure your extension’s layout using the Flex
, Box
, and Inline
components, which are based on the CSS flexbox layout.
The Flex
, Box
, and Inline
components act as wrappers for other components. Flex
can be used on its own, while Box
can be used inside Flex
to fine tune spacing of child components. The Inline
component can be used on its own to automatically arrange child components in a horizontal row.
Below, learn more about each component along with usage examples.
Check out HubSpot’s Managing layout: Flex and Box sample project to view a full example of using Flex
and Box
.
Flex
component renders an empty div
container set to display=flex
. When wrapped around other components, this enables those child components to be arranged using props.
Below are the available Flex
props. To review all Flex
prop definitions, check out the components reference guide.
Prop | Values | Description |
---|---|---|
direction | row (default) | column | Arranges components horizontally or vertically by setting the main axis. |
justify | start (default) | center | end | around | between | Distributes components along the main axis using the available free space. |
align | start | center | baseline | end | stretch (default) | Distributes components along the cross-axis using the available free space. |
alignSelf | start | center | baseline | end | stretch | Distributes a child component along the cross-axis using the available free space. Use this prop for nested child Flex and Box components to align them differently from other child components in the Flex group. |
wrap | wrap | nowrap | Whether components will wrap instead of trying to fit on one line. |
gap | flush (default) | extra-small | small | medium | large | extra-large | Sets the spacing between components. |
direction
to row
. Then, use justify
to configure the horizontal distribution. By default, components will stretch across the container if justify
is not specified.
To arrange components horizontally and evenly spaced:
row
will be arranged on one line when possible. Use the wrap
prop to wrap components onto new lines when needed.
column
, then use the align
prop to distribute them. By default, components will stretch across the extension container width when align
is not specified.
To arrange components vertically at the start of the extension container:
Flex
component, you can use the gap
prop to apply even spacing between the tiles. This prop will apply spacing equally for both row
and column
directions.
Flex
components with Flex
to set more specific rules for individual components. A child Flex
component will not inherit props specified in the parent Flex
component, so you’ll need to repeat any props you’ve previously defined to maintain them.
Flex
, you can further configure individual component layout by wrapping a child of Flex
in a Box component.
This component supports the following props. To review all Box
prop definitions, check out the components reference guide.
Prop | Values | Description |
---|---|---|
alignSelf | start | center | baseline | end | stretch | Distributes a child component along the cross-axis using the available free space. Use this prop for nested child Flex and Box components to align them differently from other child components in the Flex group. |
flex | initial (default) | auto | none | number | Distributes components based on the available empty space around them. |
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.
For example, the four tiles below take up an increasing amount of space based on their flex
values.
Box
, you only need to wrap 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.
flex
value for only one Box
, you can use any number. This is because any number on its own will result in all available space being assigned to that one component.alignSelf
prop to override alignment rules for individual Box
components.
Inline
component to organize child components into a horizontal row.
Prop | Type | Description |
---|---|---|
gap | 'flush' (default) | 'extra-small' , 'xs' | 'small' , 'sm' | 'medium' , 'md' | 'large' , 'lg' | 'extra-large' , 'xl' | The amount of spacing between components. |
justify | 'start' (default) | 'center' | 'end' | 'around' | 'between' | Distributes components along the main axis using the available free space. |
align | 'start' | 'center' | 'end' | 'baseline' | 'stretch' (default) | Distributes components along the cross-axis using the available free space. |