Course

Web Development
  • 1.1 Introduction to the Web
  • 2.1 HTML Basics
  • 2.2 Text & Content
  • 2.3 Layout & Grouping
  • 2.4 Lists & Tables
  • 2.5 Media & Embedding
  • 2.6 Forms
  • 2.7 Semantic HTML
  • 2.8 Accessibility & SEO
  • 3.1 CSS Introduction
  • 3.2 CSS Syntax
  • 3.3 CSS Selectors
  • 3.4 Typography
  • 3.5 Colors & Backgrounds
  • 3.6 Text Styling
  • 3.7 Box Model
  • 3.8 Units
  • 3.9 Display & Positioning
  • 3.10 Layout Systems
  • 3.11 Responsive Design
  • 3.12 Animations
  • 3.13 Modern CSS
  • 3.14 Performance & Accessibility
  • 3.15 Tailwind CSS Basics
  • 4.1 Introduction to JavaScript
  • 4.2 Variables & Scope
  • 4.3 Data Types
  • 4.4 Type Conversion
  • 4.5 Operators
  • 4.6 Control Flow
  • 4.7 Loops
  • 4.8 Functions
  • 4.9 Advanced Functions
  • 4.10 Objects & Arrays
  • 4.11 The this Keyword

3.10 Layout Systems

Updated Jul 12, 2026

3.10 Layout Systems

Updated Jul 12, 2026

Layout Systems

Layout systems control how elements are arranged on a webpage.

Modern websites use layout systems to build navigation bars, dashboards, galleries, landing pages, and responsive layouts.

CSS provides several layout systems:

  • Flow Layout
  • Float Layout
  • Multi-column Layout
  • Flexbox
  • CSS Grid

Flow Layout

Flow Layout is the default layout system in CSS.

Elements appear in the same order they are written in the HTML document.

Example:

<h1>Heading</h1>

<p>Paragraph 1</p>

<p>Paragraph 2</p>

Output:

Heading

Paragraph 1

Paragraph 2

Block elements appear vertically.

<div></div>

<p></p>

<section></section>

Inline elements appear on the same line.

<span>Hello</span>
<span>World</span>

Output:

Hello World

Flow Layout is:

  • Default layout system
  • Easy to understand
  • Good for simple pages
  • Limited for complex layouts

Float Layout

Before Flexbox and Grid, layouts were commonly built using floats.

The float property moves elements to the left or right.

float: left;

or

float: right;

Example:

.box {

    float: left;

    width: 200px;

}
<div class="box">Box 1</div>
<div class="box">Box 2</div>

Output:

[Box 1][Box 2]

Floats are still useful for wrapping text around images.

img {

    float: left;

    margin-right: 20px;

}

To stop floating elements, use:

clear: both;

Example:

.footer {

    clear: both;

}

Floats have several drawbacks:

  • Difficult alignment
  • Layout bugs
  • Requires clearfix techniques

Modern layouts usually use Flexbox or Grid instead.


Multi-column Layout

CSS can automatically split text into multiple columns.

Useful for articles, blogs, and magazines.

Example:

.article {

    column-count: 2;

}

Three columns:

.article {

    column-count: 3;

}

Spacing between columns:

column-gap: 40px;

Column divider:

column-rule: 1px solid #ddd;

Example:

.article {

    column-count: 2;

    column-gap: 40px;

    column-rule: 1px solid #ddd;

}

Flexbox

Flexbox is a one-dimensional layout system.

It arranges items in either rows or columns.

Create a flex container:

.container {

    display: flex;

}

Example:

<div class="container">

    <div>1</div>

    <div>2</div>

    <div>3</div>

</div>

Output:

1  2  3

Flex Direction

Controls the main axis.

Row (default):

flex-direction: row;

Output:

1 2 3

Column:

flex-direction: column;

Output:

1
2
3

Justify Content

Aligns items along the main axis.

Center:

justify-content: center;

Space Between:

justify-content: space-between;

Space Around:

justify-content: space-around;

Space Evenly:

justify-content: space-evenly;

Align Items

Aligns items along the cross axis.

align-items: center;
align-items: flex-start;
align-items: flex-end;

Gap

Adds spacing between flex items.

gap: 20px;

Example:

.container {

    display: flex;

    gap: 20px;

}

Flex Wrap

Allows items to move onto multiple lines.

.container {

    display: flex;

    flex-wrap: wrap;

}

Complete Flexbox Example

.container {

    display: flex;

    justify-content: center;

    align-items: center;

    gap: 20px;

}

Common uses include:

  • Navigation bars
  • Cards
  • Buttons
  • Forms
  • Toolbars

CSS Grid

CSS Grid is a two-dimensional layout system.

Unlike Flexbox, Grid controls both rows and columns.

Create a grid container:

.container {

    display: grid;

}

Grid Columns

Create columns using grid-template-columns.

.container {

    display: grid;

    grid-template-columns: 1fr 1fr 1fr;

}

Output:

+----+----+----+
| 1  | 2  | 3  |
+----+----+----+

Fraction Unit (fr)

Grid introduces the fr unit.

grid-template-columns: 1fr 2fr;

The second column receives twice as much space as the first.


Grid Gap

Spacing between rows and columns.

gap: 20px;

Grid Rows

grid-template-rows: 100px 100px;

Repeat Function

Instead of:

grid-template-columns:
1fr 1fr 1fr 1fr;

Use:

grid-template-columns:
repeat(4, 1fr);

Grid Item Placement

Items can span multiple columns.

.item {

    grid-column: 1 / 3;

}

Example:

.container {

    display: grid;

    grid-template-columns:
    repeat(3, 1fr);

    gap: 20px;

}

Common uses include:

  • Dashboards
  • Gallery layouts
  • Admin panels
  • Landing pages

Flexbox vs Grid

Flexbox Grid
One-dimensional Two-dimensional
Rows or Columns Rows and Columns
Component Layouts Page Layouts
Simpler More Powerful

When to Use Flexbox

Flexbox works well for:

  • Navigation bars
  • Card rows
  • Buttons
  • Toolbars
  • Centering content

Example:

.navbar {

    display: flex;

    justify-content: space-between;

}

When to Use Grid

Grid is better for:

  • Dashboards
  • Gallery layouts
  • Admin panels
  • Full page layouts

Example:

.dashboard {

    display: grid;

    grid-template-columns:
    250px 1fr;

}

Complete Example

.container {

    display: grid;

    grid-template-columns:
    repeat(3, 1fr);

    gap: 20px;

}

Best Practices

  • Use Flow Layout for simple documents.
  • Use Flexbox for one-dimensional component layouts.
  • Use Grid for two-dimensional page layouts.
  • Use Multi-column Layout for long text content.
  • Avoid using floats for page layouts.

Key Takeaway

Modern websites primarily use Flexbox and CSS Grid for layouts.

/* Component Layout */

display: flex;
/* Page Layout */

display: grid;

Typical use cases:

  • Flow Layout → Simple documents
  • Float → Text wrapping
  • Multi-column → Articles
  • Flexbox → Navigation, cards, forms
  • Grid → Dashboards, galleries, page layouts
3.9 Display & Positioning3.11 Responsive Design