Container - Keep React

A component for fixing an element's width to the current breakpoint.

Table of Contents#

Container Breakpoints#

The container class sets the maximum width of an element to match the minimum width of the current screen size. This is useful if you want to design for specific screen sizes instead of a fully flexible layout.

ClassBreakpointProperties
containerNonewidth: 100%
sm (640px)max-width: 640px
md (768px)max-width: 768px
lg (1024px)max-width: 1024px
xl (1280px)max-width: 1280px
2xl (1536px)max-width: 1536px

Centering Container#

To automatically center containers, you can enable the center option as true in your tailwind.config.ts file:

const config = {
  theme: {
    container: {
      center: true
    }
  }
}

Horizontal padding#

You can add horizontal padding to containers by setting the padding option in your tailwind.config.ts file:

const config = {
  theme: {
    container: {
      padding: '2rem',
    },
  },
}

Breakpoints padding#

If you need different padding for each screen size, you can specify a default value and override it for specific breakpoints using an object:

const config = {
  theme: {
    container: {
      padding: {
        DEFAULT: '1rem',
        sm: '2rem',
        lg: '4rem',
        xl: '5rem',
        '2xl': '6rem',
      },
    },
  },
}

Reference#

If you want to know more about container class then you can read the documentation of tailwind css container.