Grids

Fully customizable and responsive CSS grids.

Introduction to Pure Grids

Pure Grids are easy to work with, and very powerful. There are a few simple concepts to keep in mind:

Grid classes vs. unit classes
Pure Grids consist of two types of classes: the grid class (pure-g) and unit classes (pure-u or pure-u-*)
The widths of the units are fractions
Units have various class names that represent their widths. For example, pure-u-1-2 has a width of 50%, whereas pure-u-1-5 would have a width of 20%.
All child elements of a grid must be units
Child elements contained within an element with a pure-g classname must be a grid unit with a pure-u or pure-u-* classname.
Content goes inside grid units
All content which is visible to people needs to be contained inside a grid unit. This ensures that the content will be rendered properly.

Let's start with a simple example. Here's a grid with three columns:

<div class="pure-g">
    <div class="pure-u-1-3"><p>Thirds</p></div>
    <div class="pure-u-1-3"><p>Thirds</p></div>
    <div class="pure-u-1-3"><p>Thirds</p></div>
</div>

Grids Units Sizes

Pure ships with both a 5ths and 24ths based grid. Depicted below are the available units that can be appended to the pure-u-* classname where * is one of the unit fractions listed below. For example the unit classname for 50% width is: pure-u-1-2.

5ths-Based Units

1-5
2-5
3-5
4-5
1
1-1
5-5

24ths-Based Units

1-24
1-12
2-24
3-24
1-8
4-24
1-6
5-24
1-4
6-24
7-24
1-3
8-24
3-8
9-24
5-12
10-24
11-24
1-2
12-24
13-24
7-12
14-24
5-8
15-24
2-3
16-24
17-24
3-4
18-24
19-24
5-6
20-24
7-8
21-24
11-12
22-24
23-24
1
1-1
24-24

Custom Unit Sizes

We are working on building tools to allow people to customize Pure Grids. The first low-level tools, the Pure Grids Rework Plugin, is available to use today—we use this tool to generate Pure's built-in unit sizes.

Pure Responsive Grids

Pure has a mobile-first responsive grid system that can be used declaratively through CSS class names. It's a robust and flexible grid that builds on top of the default grid.

Including on Your Page

Since media queries cannot be over-written, we do not include the grid system as part of pure.css. You'll have to pull it in as a separate CSS file. You can do this by adding the following <link> tag to your page.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/purecss@3.0.0/build/grids-responsive-min.css" />

Pure's Regular Grid vs. Responsive Grid

The best way to understand the difference between Pure's regular grid and a responsive grid is through an example.The snippet below shows how regular Pure Grids are written. These grids are unresponsive. They'll always be width: 33.33%, irrespective of the width of the screen.

<div class="pure-g">
    <div class="pure-u-1-3"> ... </div>
    <div class="pure-u-1-3"> ... </div>
    <div class="pure-u-1-3"> ... </div>
</div>

Next, let's look at a responsive grid. Elements within this grid will be width: 100% on small screens, but will shrink to become width: 33.33% on medium-sized screens and above.

<div class="pure-g">
    <div class="pure-u-1 pure-u-md-1-3"> ... </div>
    <div class="pure-u-1 pure-u-md-1-3"> ... </div>
    <div class="pure-u-1 pure-u-md-1-3"> ... </div>
</div>

Default Media Queries

When using Responsive Grids, you can control how the grid behaves at specific breakpoints by adding class names. Pure's default responsive grids comes with the following class names and media query breakpoints.

KeyCSS Media QueryAppliesClassname
NoneNoneAlways.pure-u-*
sm@media screen and (min-width: 35.5em)568px.pure-u-sm-*
md@media screen and (min-width: 48em)768px.pure-u-md-*
lg@media screen and (min-width: 64em)1024px.pure-u-lg-*
xl@media screen and (min-width: 80em)1280px.pure-u-xl-*
xxl@media screen and (min-width: 120em)1920px.pure-u-xxl-*
xxxl@media screen and (min-width: 160em)2560px.pure-u-xxxl-*
x4k@media screen and (min-width: 240em)3840px.pure-u-x4k-*

Using Relative Units for Widths

You may have noticed that we use em for our default CSS Media Query widths instead of px. This was a conscious decision since it allows the Media Queries to respond appropriately when people zoom the webpage. Check out this article by Brad Frost for some background information on using relative units within Media Queries.

If you do want to use units other than em, you can always modify the default Media Queries on the Get Started page. Converting from em to px is pretty simple:

1em == 16px *

* The em to px conversion is based on the browser's default font size, which is generally 16px, but can be overridden by a user in their browser settings.

An Example of Pure Responsive Grids

The example below leverages Pure's Responsive Grid to create a row with four columns. The columns stack on small screens, take up width: 50% on medium-sized screens, and width: 25% on large screens.

This is done by adding the .pure-u-1 class for small screens, .pure-u-md-1-2 for medium-sized screens, and .pure-u-lg-1-4 for large screens. Resize the page to see the grid respond to the screen size.

Lorem Ipsum

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.

Dolor Sit Amet

Quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse.

Proident laborum

In culpa qui officia deserunt mollit anim id est laborum. incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.

Praesent consectetur

Integer vitae lectus accumsan, egestas dui eget, ullamcorper urn. In feugiat tortor at turpis rhoncus tincidunt. Duis sed porttitor ante, eget venenatis lectus.

By Sylwia Bartyzel from unsplash.com

Two-Fifth Column

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur fermentum dui turpis.

Three-Fifth Column

Quisque ac magna eget est porta varius ut eget quam. Curabitur tincidunt gravida nisl.

Fusce accumsan, sem vitae tempus tempor, nulla lectus interdum felis, eget molestie urna mauris vel elit. Curabitur vel ipsum nulla.

Grids on Mobile

Pure's default grid system is mobile-first. If you want to have a grid on small screens, just use the pure-u-* classnames on your elements.

Thirds

This cell will be 1/3 width all the time.

Thirds

This cell will be 1/3 width all the time.

Thirds

This cell will be 1/3 width all the time.

Responsive Images

When using Responsive Grids, you'll want your images to be fluid as well so they grow and shrink with the content, while maintaining the correct ratio. To do this, just add the .pure-img class on them. Check out the example below.

Peyto Lake
Train
T-Shirt Store
Mountain
Miami
BCE Place, Toronto
Banff
Boston North Point Park

Applying Padding and Borders to Grid Units

To add borders and padding to Pure Grids, you have two options. The first option is to nest a <div> inside each Grid unit and style the child container:

<style>
    .l-box {
        padding: 1em;
    }
</style>

...

<div class="pure-g">
    <div class="pure-u-1-2">
        <div class="l-box"> ... </div>
    </div>
    <div class="pure-u-1-2">
        <div class="l-box"> ... </div>
    </div>
</div>

The second option is to add borders and padding directly to a grid unit. This would ordinarily risk breaking the layout, but you can easily avoid this problem by augmenting the behavior of the grid itself with a box-sizing: border-box rule:

<style>
    .pure-g > div {
        box-sizing: border-box;
    }
    .l-box {
        padding: 1em;
    }
</style>

...

<div class="pure-g">
    <div class="pure-u-1-2 l-box"> ... </div>
    <div class="pure-u-1-2 l-box"> ... </div>
</div>

Using box-sizing: border-box keeps your markup cleaner, but has one minor drawback. Setting this property on all grid units makes it harder to override or unset the value later on. As an unopinionated library, Pure lets box-sizing remain at the default value of content-box and leaves the choice up to you.

Want to just use Grids?

Grids is part of the Pure CSS file. However, if you just want Grids and not the other modules, you can pull it down separately. Just include these <link> elements in your <head>.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/purecss@3.0.0/build/base-min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/purecss@3.0.0/build/grids-min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/purecss@3.0.0/build/grids-responsive-min.css">