---
category: Layout
created: '2019-11-22'
description: Create a simple grid with CSS flexbox
keywords: css flexbox, css flexbox grid, css grid, css layout
thumbnail: /assets/css-layout/thumbnails/simple-grid.png
title: Simple grid
---

## HTML

```html index.html
<!-- Row -->
<div class="simple-grid">
    <!--Cell with given width. Replace 25% with whatever you want -->
    <div class="simple-grid__cell simple-grid__cell--1/4">25%</div>

    <!-- Cell that takes remaining width -->
    <div class="simple-grid__cell simple-grid__cell--fill">...</div>
</div>
```

## CSS

```css styles.css
.simple-grid {
    display: flex;

    margin-left: -0.25rem;
    margin-right: -0.25rem;
}

.simple-grid__cell {
    padding-left: 0.25rem;
    padding-right: 0.25rem;
}

.simple-grid__cell--fill {
    flex: 1;
}

/* Cell with given width */
.simple-grid__cell--1\/2 {
    flex: 0 0 50%;
}
.simple-grid__cell--1\/3 {
    flex: 0 0 33.3333333%;
}
.simple-grid__cell--1\/4 {
    flex: 0 0 25%;
}
```

<Playground>
```css placeholders.css hidden
.rectangle {
    background: #d1d5db;
    border-radius: 0.25rem;
    height: var(--rectangle-height);
    width: var(--rectangle-width);
}
.rectangle--hor.rectangle--20 {
    --rectangle-width: 20%;
}
.rectangle--hor.rectangle--40 {
    --rectangle-width: 40%;
}
.rectangle--hor.rectangle--60 {
    --rectangle-width: 60%;
}
.rectangle--hor.rectangle--80 {
    --rectangle-width: 80%;
}
.rectangle--hor.rectangle--100 {
    --rectangle-width: 100%;
}
.rectangle--hor.rectangle--sm {
    --rectangle-height: 0.5rem;
}
.rectangle--hor.rectangle--md {
    --rectangle-height: 2rem;
}
.rectangle--hor.rectangle--lg {
    --rectangle-height: 4rem;
}
.rectangle--ver.rectangle--20 {
    --rectangle-height: 20%;
}
.rectangle--ver.rectangle--40 {
    --rectangle-height: 40%;
}
.rectangle--ver.rectangle--60 {
    --rectangle-height: 60%;
}
.rectangle--ver.rectangle--80 {
    --rectangle-height: 80%;
}
.rectangle--ver.rectangle--100 {
    --rectangle-height: 100%;
}
.rectangle--ver.rectangle--sm {
    --rectangle-width: 0.5rem;
}
.rectangle--ver.rectangle--md {
    --rectangle-width: 2rem;
}
.rectangle--ver.rectangle--lg {
    --rectangle-width: 4rem;
}
```

```css styles.css hidden
.simple-grid {
    display: flex;

    margin-left: -0.25rem;
    margin-right: -0.25rem;

    /* Demo */
    margin-bottom: 0.25em;
    margin-top: 0.25em;
    height: 4rem;
    width: 100%;
}

.simple-grid__cell {
    padding-left: 0.25rem;
    padding-right: 0.25rem;
}

/* Cell with given width */
.simple-grid__cell--1\/2 {
    flex: 0 0 50%;
}
.simple-grid__cell--1\/3 {
    flex: 0 0 33.3333333%;
}
.simple-grid__cell--1\/4 {
    flex: 0 0 25%;
}

.simple-grid__cell--fill {
    flex: 1;
}
```

```html index.html hidden
<div class="simple-grid">
    <div class="simple-grid__cell simple-grid__cell--1/4"><div class="rectangle rectangle--hor rectangle--md rectangle--100"></div></div>
    <div class="simple-grid__cell simple-grid__cell--fill"><div class="rectangle rectangle--hor rectangle--md rectangle--100"></div></div>
</div>
<div class="simple-grid">
    <div class="simple-grid__cell simple-grid__cell--1/3"><div class="rectangle rectangle--hor rectangle--md rectangle--100"></div></div>
    <div class="simple-grid__cell simple-grid__cell--1/3"><div class="rectangle rectangle--hor rectangle--md rectangle--100"></div></div>
    <div class="simple-grid__cell simple-grid__cell--1/3"><div class="rectangle rectangle--hor rectangle--md rectangle--100"></div></div>
</div>
<div class="simple-grid">
    <div class="simple-grid__cell simple-grid__cell--1/4"><div class="rectangle rectangle--hor rectangle--md rectangle--100"></div></div>
    <div class="simple-grid__cell simple-grid__cell--1/4"><div class="rectangle rectangle--hor rectangle--md rectangle--100"></div></div>
    <div class="simple-grid__cell simple-grid__cell--1/4"><div class="rectangle rectangle--hor rectangle--md rectangle--100"></div></div>
    <div class="simple-grid__cell simple-grid__cell--1/4"><div class="rectangle rectangle--hor rectangle--md rectangle--100"></div></div>
</div>
```
</Playground>
