Box

Box is the most abstract layout component that allows to apply margin and padding properties according to the spacing system. By default, it renders a div element.

The Box component is useful because it helps with several common cases: create a layout that uses Forma 36 spacing system; and compose new component and allow to override element using the as property.

Import

import { Box } from '@contentful/f36-components';
// or
import { Box } from '@contentful/f36-core';

Examples

Margins & Paddings

Margins and paddings for Box component are based on our spacing system.

Here is an overview of spacings that are available:

  • spacing2Xs
  • spacingXs
  • spacingXs
  • spacingS
  • spacingM
  • spacingL
  • spacingXl
  • spacing2Xl
  • spacing3Xl
  • spacing4Xl

Here is a good example that demonstrates how you can apply margin and padding properties to the Box component:

as property

If you want to keep all the styling you've applied to a component but just switch what's being ultimately rendered (be it a different HTML tag or a different custom component), you can use the "as" prop to do this at runtime.

Props (API reference)