---
title: Grid
description: Use the grid component to create flexible and responsive grid-based layouts.
keywords: ['layout', 'responsive', 'columns', 'rows', 'spacing']
---

![The grid component applied to a section with different elements that spans in columns](https://github.com/primer/brand/assets/912236/6cd2805e-0148-4a1d-b373-07acd1aa7f51)

## Usage

Use the grid component to define a layout that maintains consistent element positioning and sizing across pages. The grid is based on a 12-column layout and uses vertical and horizontal gaps to separate content units consistently[^1].

Use the grid for general page layout, and grouping related elements with a similar purpose. E.g. A "contact us" form or a list of [cards](../../components/Card/index.md).

In most cases, we recommend using the same column span for each element to create a consistent layout.

[^1]: The grid component is implemented using the [CSS Grid Layout](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout) specification.

**✅ Do**

![](https://github.com/primer/brand/assets/912236/b4870b2e-5cf0-440c-9f51-0b1f81258b9b)

_Use the same column span for each content unit to create a consistent layout and spacing._

**❌ Don't**

![](https://github.com/primer/brand/assets/912236/0703ba43-7f47-4ad1-bc1d-020bc095e362)

_Don't use different column spans when grouping the same element type._

Use different column spans instead of an even distribution when creating a visual hierarchy between items or when defining a general page or a section layout. E.g. A section with an [image](../../components/Image/index.md) and [text](../../typography/Text/index.md), a layout with main content and a sidebar or a form with inputs and text areas.

**✅ Do**

![](https://github.com/primer/brand/assets/912236/bc442c41-3546-4341-bab3-1c649ccfe7d2)

_Use different column spans to create a visual hierarchy between a large image and text._

**❌ Don't**

![](https://github.com/primer/brand/assets/912236/f6307bee-3236-435a-a74d-b6d942a7925b)

_Don't span in few columns large images or long content text that will create unbalanced layouts._

**✅ Do**

![](https://github.com/primer/brand/assets/912236/83e4eedf-5cc2-4dcc-a9dd-48d563744dd2)

_Use different column spans when you want to create a visual hierarchy on a section between different elements.
Like a footer with notes and navigational lists._

**❌ Don't**

![](https://github.com/primer/brand/assets/912236/911a6b4b-791a-4186-8079-6296e17c65d0)

_Don't use equal column spans when the content is not related or the elements are different._

### Responsive

The grid component provides control over the number of columns at each breakpoint. For most of the cases, we recommend using the same column span on each child at each breakpoint to create a consistent layout and spacing in all screen sizes.

For example, a group of cards might span 3 columns on a extra large viewport, 4 columns on large viewports, 6 on medium and 12 columns on small viewports.

_Video demonstration — see the online docs._

_Use the same column span for each content unit at each breakpoint to create visually consistent layouts._

When using even column spans, we recommend to span each item full width on small viewports and stacking the items vertically to ensure that the content is readable and accessible on small screens.

_Video demonstration — see the online docs._

_Use full width on small viewports to ensure that the content is readable and accessible._

## Grid vs Stack

We recommend using either the grid or stack component, depending on how the child items are displayed and how they work on different screen sizes. If the element is a sequential list of items in a vertical or horizontal order, we recommend using the stack component. Otherwise, if the element needs columns and rows or for general page layout, we recommend using the grid component instead[^2].

### Grid examples

#### Page or section layout

When defining the page or a section layout. E.g. A page with navigation, main content and footer areas.

![](https://github.com/primer/brand/assets/912236/76e816de-1ec7-40c2-993f-61fe05f97656)

#### Sub sections

When dividing an area into two areas. E.g. A "Send feedback" sidebar and a form, and the form uses the grid for the form layout itself.

![](https://github.com/primer/brand/assets/912236/d617bfea-0758-4066-9ccc-7853eeb35cf3)

#### Card or pillar grids

When laying out cards, pillars, or similar content-based elements.

![](https://github.com/primer/brand/assets/912236/56dfbcd8-72ff-401c-a530-25f11f671f7f)

### Stack examples

#### Navigation

For the page navigation or a list of links. E.g. Having a logo on the left side and the navigation on the right.

![](https://github.com/primer/brand/assets/912236/022fc146-6286-4074-abc5-7341743da82e)

#### List of actions

For a group of action or buttons, where items are displayed next to each other, and they are distributed horizontally or vertically, depending on the content length and the screen size.

![](https://github.com/primer/brand/assets/912236/10ae15dd-f8f9-4174-9c89-2e9355120204)

#### Form elements

For combinations of input fields with a button next to it.

![](https://github.com/primer/brand/assets/912236/78a81f0e-55d5-4db5-8a8b-3184394fac51)

#### Profile cards

For combinations of an avatar and descriptive content, where the information takes the remaining space from its parent element. This could be applied to any combinations of an icon and text too.

![](https://github.com/primer/brand/assets/912236/c53f2ee7-93f1-416f-8fd5-bd965fd37f86)

[^2]: This section is based on the article [Grid for layout, Flexbox for components](https://ishadeed.com/article/grid-layout-flexbox-components/) by [@shadeed](https://github.com/shadeed)

## Accessibility

By default, the grid assumes that it will be used in a purely decorative fashion and thus sets no roles, ARIA attributes, or keyboard shortcuts. This is equivalent to having a sequence of `<div>` elements on the page by default. Any interactive content within the grid should be given an appropriate accessibility treatment based on the specific workflow of your application.

## Related components

- [Stack](../Stack/index.md): To enable layout of its immediate children along the vertical or horizontal axis.
