Skip to main content

Container

Containers are used to constrain a content's width to the current breakpoint, while keeping it fluid.

Import

import { Container } from "@chakra-ui/react";

Usage

To contain any piece of content, wrap it in the Container component.

Container Size

By default, the Container component sets the maxWidth of the content to 60 characters (60ch) but you can customize this by passing custom maxWidth values or changing the size tokens defined in theme.sizes.container.

  • About the default value: The ch unit is a relative unit defined by the rendered typeface's "0" character width. This width varies by the shape and style of the font.
  • If you are curious about the reason for this default value of 60 characters, consider this explanation about line length from Better Web Type.

Centering the children

In some cases, the width of the content can be smaller than the container's width. You can use the centerContent prop to center the content. It renders a flexbox with flexDirection set to column and alignItems set to center.

Props

Container composes Box so you can pass all Box related props in addition to this.

centerContent

Description

If true, container will center its children regardless of their width.

Type
boolean

colorScheme

Description

Color Schemes for Container are not implemented in the default theme. You can extend the theme to implement them.

Type
string

size

Description

Sizes for Container are not implemented in the default theme. You can extend the theme to implement them.

Type
string

variant

Description

Variants for Container are not implemented in the default theme. You can extend the theme to implement them.

Type
string