goer.org | HTML Tutorial : Basic : Headings

Table of Contents

About
Introduction
Diving In
Structure
Tinkering
Tags
Attributes
Browser Tools
Basic
Paragraph Breaks
Headings
Font Styles
Colors
Links
Images
Lists
Intermediate
Style Sheets
Classes and IDs
Div and Span
Font Control
Borders
Margins and Padding
Align and Indent
Advanced
Tables
Miscellany
SHTML

Headings

So far we've covered paragraphs and line breaks... but in a long document, we probably want more structure than that. How do we create section headings?

The <H> Tags

There are six levels of heading tags: <h1>, <h2>, <h3>, <h4>, <h5>, and <h6>. These block tags tell the browser to set off the heading from the rest of the text. The <h1> heading level is the most important heading, while the <h6> level is the least important.

Most browsers display headings in bold, with <h1> the largest and <h6> the smallest.

Headings (source)

<h1>Heading 1</h1>

<h2>Heading 2</h2>

<h3>Heading 3</h3>

<h4>Heading 4</h4>

<h5>Heading 5</h5>

<h6>Heading 6</h6>

What are the results?

Headings (Results)

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Like the paragraph tag (<p>), the heading tags are block tags: they delineate a block of text. Each matched set of heading tags creates a new block, automatically separated from other blocks with line breaks.

Mangled Headings

In the section on paragraphs, we discussed the consequences of failing to close your <p> tags. This is even more important for heading tags.

Mangled Heading and Text

(source)
<h3>Chapter 1

Robert Cohn was once middleweight 
boxing champion of Princeton.  Do not think I 
am very much impressed with that as a boxing
title, but it meant a lot to Cohn.

The results are not quite what we wanted...

Mangled Heading and Text (Results)

Chapter 1 Robert Cohn was once middleweight boxing champion of Princeton. Do not think I am very much impressed with that as a boxing title, but it meant a lot to Cohn.

The sensible thing to do is to close the <h3> tag. We'll put the text in its own HTML paragraph for good measure:

Proper Heading and Text (source)

<h3>Chapter 1</h3>
<p>
  Robert Cohn was once middleweight 
  boxing champion of Princeton.  Do not think I 
  am very much impressed with that as a boxing
  title, but it meant a lot to Cohn.
</p>

Which results in:

Proper Heading and Text (Results)

Chapter 1

Robert Cohn was once middleweight boxing champion of Princeton. Do not think I am very much impressed with that as a boxing title, but it meant a lot to Cohn.

The heading and paragraph are now properly separated.