Box & Layout

CSS Box & Layout Cheat Sheet

Box Model

Box Model Properties

/* Content box (default) */
.box {
    box-sizing: content-box;
    width: 300px;        /* Content width only */
    height: 200px;       /* Content height only */
    padding: 20px;       /* Adds to width/height */
    border: 2px solid;   /* Adds to width/height */
    margin: 10px;        /* Outside spacing */
}

/* Border box (recommended) */
.box {
    box-sizing: border-box;
    width: 300px;        /* Total width including padding/border */
    height: 200px;       /* Total height including padding/border */
    padding: 20px;       /* Inside spacing */
    border: 2px solid;   /* Border */
    margin: 10px;        /* Outside spacing */
}

/* Universal border-box */
* {
    box-sizing: border-box;
}

Width and Height

Padding

Border

Margin

Display Properties

Display Types

Visibility

Positioning

Position Types

Z-Index

Flexbox

Flex Container

Flex Container Alignment

Flex Items

CSS Grid

Grid Container

Grid Lines and Gaps

Grid Items

Layout Techniques

Centering

Responsive Layouts

Holy Grail Layout

Masonry-like Layout

Last updated