--- productId: material-ui title: React Grid component components: PigmentGrid, Grid githubLabel: 'component: Grid' materialDesign: https://m2.material.io/design/layout/understanding-layout.html githubSource: packages/mui-material/src/Grid --- # Grid
The responsive layout grid adapts to screen size and orientation, ensuring consistency across layouts.
The `Grid` component works well for a layout with a known number of columns. The columns can be configured with multiple breakpoints to specify the column span of each child. {{"component": "@mui/docs/ComponentLinkHeader", "design": false}} ## How it works The grid system is implemented with the `Grid` component: - It uses [CSS Flexbox](https://www.w3.org/TR/css-flexbox-1/) (rather than CSS Grid) for high flexibility. - The grid is always a flex item. Use the `container` prop to add a flex container. - Item widths are set in percentages, so they're always fluid and sized relative to their parent element. - There are five default grid breakpoints: xs, sm, md, lg, and xl. If you need custom breakpoints, check out [custom breakpoints grid](#custom-breakpoints). - You can give integer values for each breakpoint, to indicate how many of the 12 available columns are occupied by the component when the viewport width satisfies the [breakpoint constraints](/material-ui/customization/breakpoints/#default-breakpoints). - It uses [the `gap` CSS property](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/gap) to add spacing between items. - It does _not_ support row spanning. Children elements cannot span multiple rows. We recommend using [CSS Grid](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_layout) if you need this functionality. - It does _not_ automatically place children. It will try to fit the children one by one, and if there is not enough space, the rest of the children will start on the next line, and so on. If you need auto-placement, we recommend using [CSS Grid](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_layout/Auto-placement_in_grid_layout) instead. :::warning The `Grid` component is a _layout_ grid, not a _data_ grid. If you need a data grid, check out [the MUI X `DataGrid` component](/x/react-data-grid/). ::: ## Fluid grids Fluid grids use columns that scale and resize content. A fluid grid's layout can use breakpoints to determine if the layout needs to change dramatically. ### Basic grid In order to create a grid layout, you need a container. Use the `container` prop to create a grid container that wraps the grid items (the `Grid` is always an item). Column widths are integer values between 1 and 12. For example, an item with `size={6}` occupies half of the grid container's width. {{"demo": "BasicGrid.js", "bg": true}} ### Multiple breakpoints Items may have multiple widths defined, causing the layout to change at the defined breakpoint. Width values apply to all wider breakpoints, and larger breakpoints override those given to smaller breakpoints. For example, a component with `size={{ xs: 12, sm: 6 }}` occupies the entire viewport width when the viewport is [less than 600 pixels wide](/material-ui/customization/breakpoints/#default-breakpoints). When the viewport grows beyond this size, the component occupies half of the total width—six columns rather than 12. {{"demo": "FullWidthGrid.js", "bg": true}} ## Spacing Use the `spacing` prop to control the space between children. The spacing value can be any positive number (including decimals) or a string. The prop is converted into a CSS property using the [`theme.spacing()`](/material-ui/customization/spacing/) helper. The following demo illustrates the use of the `spacing` prop: {{"demo": "SpacingGrid.js", "bg": true, "hideToolbar": true}} ### Row and column spacing The `rowSpacing` and `columnSpacing` props let you specify row and column gaps independently of one another. They behave similarly to the `row-gap` and `column-gap` properties of [CSS Grid](/system/grid/#row-gap-amp-column-gap). {{"demo": "RowAndColumnSpacing.js", "bg": true}} ## Responsive values You can set prop values to change when a given breakpoint is active. For instance, we can implement Material Design's [recommended](https://m2.material.io/design/layout/responsive-layout-grid.html) responsive layout grid, as seen in the following demo: {{"demo": "ResponsiveGrid.js", "bg": true}} Responsive values are supported by: - `size` - `columns` - `columnSpacing` - `direction` - `rowSpacing` - `spacing` - `offset` ## Interactive Below is an interactive demo that lets you explore the visual results of the different settings: {{"demo": "InteractiveGrid.js", "hideToolbar": true, "bg": true}} ## Auto-layout The auto-layout feature gives equal space to all items present. When you set the width of one item, the others will automatically resize to match it. {{"demo": "AutoGrid.js", "bg": true}} ### Variable width content When a breakpoint's value is given as `"auto"`, then a column's size will automatically adjust to match the width of its content. The demo below shows how this works: {{"demo": "VariableWidthGrid.js", "bg": true}} ## Nested grid The grid container that renders as a **direct child** inside another grid container is a nested grid that inherits its [`columns`](#columns) and [`spacing`](#spacing) from the top level. It will also inherit the props of the top-level grid if it receives those props. :::success Note that a nested grid container should be a direct child of another grid container. If there are non-grid elements in between, the grid container will start as the new root container. ```js