Skip to main content

HTML Layout Elements and Techniques

Websites often show content in multiple columns, like a magazine or newspaper.


HTML Layout Elements

HTML has several semantic elements that mark out the parts of a page: <header> (a header for a document or section), <nav> (a set of navigation links), <section> (a section), <article> (independent, self-contained content), <aside> (content to the side, like a sidebar), <footer> (a footer), <details> (extra details the user can open and close), and <summary> (a heading for the <details>). You can read more in the HTML Semantics chapter.


HTML Layout Techniques

There are four common ways to make multi-column layouts, each with pros and cons: CSS frameworks, the CSS float property, CSS flexbox, and CSS grid.


CSS Frameworks

To build a layout quickly, you can use a CSS framework like Bootstrap.


CSS Float Layout

You can build whole layouts with the CSS float property. Float is easy to learn; you just need to know how float and clear work. Disadvantage: floated elements are tied to the document flow, which can reduce flexibility.

Example

A multi-column layout built with float.

Prompt
A multi-column page layout built with the CSS float property: a header, a left navigation column listing London, Paris and Tokyo, a main content area about London, and a footer that clears the floats.
Output: complete HTML page

CSS Flexbox Layout

Flexbox makes elements behave predictably when the layout has to fit different screen sizes and devices.

Example

The same layout built with flexbox.

Prompt
The same Cities page layout built with CSS flexbox: a flex container holding a navigation column and a main content area about London, with a header above and a footer below.
Output: complete HTML page

CSS Grid Layout

The CSS Grid layout module gives a grid-based system of rows and columns, making it easier to design pages without floats or positioning. You can learn more in the CSS Grid chapter.