Sub topic 6
Writing the h1
This chapter covers the h1 element: what it is for, how it differs from the title tag, how to write one around a target keyword, and the edge cases that cause trouble in real pages. It assumes you know basic HTML structure (head, body, common tags). It also assumes you have seen a search results page and know what a keyword or search query is. Earlier chapters covered the title tag and its display limits. Later chapters cover the full heading hierarchy, so this chapter stays on the top-level heading.
What the h1 is for
The h1 is the main heading of the page. It tells a visitor, in one line, what the page is about. A reader who clicked a search result looks for the h1 first to confirm they landed in the right place.
The h1 and the title element do related jobs in different places:
| Aspect | `title` element | `h1` element |
|---|---|---|
| Where it appears | Browser tab, search results, bookmarks | Visible at the top of the page content |
| Who reads it first | Someone deciding whether to click | Someone who has already arrived |
| Style of writing | Compact, may include a site name or qualifier | Natural headline, usually without a site name |
| Length pressure | Truncated in search results | No fixed display limit, but short is easier to scan |
Search engines read both. The h1 gives them a second, in-page statement of the topic. When the title and h1 agree on the topic, the signal is consistent. When they disagree, the page looks unclear to both readers and crawlers.
How the h1 relates to the target keyword
You pick one primary target keyword per page, based on the search intent behind it. The h1 should make it obvious that the page answers that intent. For the snake plant example used in this tutorial, the keyword is "repot a snake plant", and the intent is practical: the searcher wants steps.
Here is the pair from the tutorial's running example:
<head>
<title>How to Repot a Snake Plant: Step-by-Step Guide</title>
<meta name="description" content="Learn when and how to repot a snake plant, which pot and soil to use, and how to avoid root damage.">
</head>
<body>
<h1>How to Repot a Snake Plant</h1>
</body>The two lines share the keyword but are not identical. The title adds "Step-by-Step Guide" as a qualifier that helps in search results. The h1 is the plain headline a reader expects at the top of an article.
Should the h1 match the title exactly?
It does not have to. Both of these are acceptable:
- Identical text. This is simple and consistent. It is common on small sites and in templates that fill both fields from one value.
- Close but different text. The title is tuned for the results page, and the
h1is tuned for reading on the page.
Avoid two extremes. Do not make them identical just because a template forces it, if the title would then carry a long site name that reads badly as a headline. Do not make them so different that they seem to describe different pages. A reasonable test is whether a visitor who clicked the title would feel the h1 confirms their choice.
Writing an effective h1
Follow these steps for each page.
- State the target keyword's topic in natural language. Put the keyword, or a close form of it, in the first few words if the sentence stays readable.
- Match the intent. A how-to query suits "How to ...". A comparison query suits a headline that names the options. A buying query suits a product or category name.
- Keep it specific. "Snake Plant" says what the subject is. "How to Repot a Snake Plant" says what the page does with it.
- Write for a person. Read it aloud. If it sounds like a list of search terms, rewrite it.
- Leave out the site name, taglines, and separators like
|. Those belong in the title, if anywhere.
Before and after
The tutorial's weak example has a vague h1:
<!-- Weak: repeated keyword, skipped level, vague headings -->
<title>Snake plant | snake plant repotting | repot snake plant | best snake plant</title>
<h1>Snake Plant</h1>
<h4>Snake plant repotting tips snake plant</h4>
<h2>More</h2>The h1 "Snake Plant" names a subject but not what the page offers. It could be a care guide, a shop page, or a species profile. Search engines and readers both have to guess. The rewrite states the task:
<h1>How to Repot a Snake Plant</h1>The new h1 carries the keyword, matches the how-to intent, and reads as a normal headline.
How many h1 elements per page
The practical recommendation is one h1 per page, describing the page's main topic. This keeps the outline clear for readers, for assistive technology, and for anyone maintaining the page.
The history here is worth knowing, because you will meet conflicting advice:
- HTML5 introduced an outline algorithm that allowed an
h1inside each sectioning element (article,section) to be treated as a lower-level heading. Browsers never implemented it, so a secondh1was never demoted in practice. - Search engines have said that multiple
h1elements are not an error and do not by themselves cause a penalty. Pages with severalh1elements can still rank. - Even so, a single
h1is the clearest structure, and every page-level tool and style guide assumes it.
Treat one h1 as the default. If a template produces two, such as a site logo wrapped in an h1 plus the article headline, fix it by making the logo a link or a div, and keep the article headline as the h1.
Common h1 problems
These are the patterns you will find most often when reviewing pages.
Missing h1
Some pages have no h1 because a theme uses styled div or p elements for the visual headline. Crawlers and screen readers get no heading at all. Fix it by changing the element to an h1 and controlling its size with CSS.
h1 hidden or used only for the logo
When the h1 wraps the site logo on every page, every page has the same h1. This tells nobody what the page is about. The logo should be an image link, and the page topic should be the h1.
Duplicate h1 across pages
If many pages share the same h1, such as "Blog" or "Products", search engines see little difference between them. Each page needs an h1 that is unique within the site and specific to its topic.
Keyword-stuffed h1
Repeating the keyword, or listing variants, makes the headline hard to read:
<h1>Snake Plant Repotting: Repot Snake Plant, Snake Plant Repotting Tips</h1>This helps no one. One natural use of the keyword is enough. Related terms belong in the h2 and h3 headings below, which a later chapter covers.
h1 that is an image only
If the headline is a graphic with no text, there is no heading text to read. If you must use an image, give it meaningful alt text inside the h1. A text h1 is still better, because it scales, translates, and is selectable.
h1 that does not match the content
An h1 that promises more than the page delivers, such as "The Complete Guide to Plant Care" over a short repotting note, raises bounce rates and misleads crawlers. Describe what the page actually contains.
Length and style
There is no official character limit for an h1. In practice, aim for a headline that fits on one or two lines on a phone. Roughly 20 to 70 characters covers most good headlines. Longer headlines are not forbidden, but they dilute the keyword and tire the reader.
Use sentence case or title case consistently with the rest of the site. Capitalisation has no effect on how the keyword is matched.
Where the h1 sits in the document
Place the h1 early in the main content, before the first h2. Keep it inside the main content area, not inside navigation or a sidebar:
<body>
<header>
<a href="/"><img src="logo.png" alt="Leafwise home"></a>
<nav>...</nav>
</header>
<main>
<h1>How to Repot a Snake Plant</h1>
<p>Repot a snake plant every two to five years, or when roots crowd the pot.</p>
<h2>When to repot</h2>
</main>
</body>Here the logo is an image link, so the only h1 is the page topic. The main element also helps assistive technology jump straight to the content.
Dynamic and generated h1 elements
Sites built from templates or JavaScript frameworks add a few risks.
- Client-side rendering. If the
h1is inserted by JavaScript after load, crawlers that render the page will usually see it, but it may be delayed. Where you can, include theh1in the server-rendered HTML. - Template variables. When a template builds the
h1from a field such as a product name, check what happens when the field is empty. An emptyh1is worse than a missing one in some tools, and a fallback like "Untitled" is a duplicate waiting to happen. - Pagination. Page 2 of a category often reuses the same
h1. Adding "Page 2" to theh1or title helps tell the pages apart, though some teams prefer to leave theh1unchanged and vary only the title.
Checking your h1
You can audit an h1 with a short script. This one fetches a page and reports how many h1 elements it has and what they say. It uses only Python's standard library.
import sys
from html.parser import HTMLParser
from urllib.request import urlopen
class H1Collector(HTMLParser):
def __init__(self):
super().__init__()
self.in_h1 = False
self.current = []
self.found = []
def handle_starttag(self, tag, attrs):
if tag == "h1":
self.in_h1 = True
self.current = []
elif tag == "img" and self.in_h1:
alt = dict(attrs).get("alt", "")
self.current.append(alt)
def handle_endtag(self, tag):
if tag == "h1" and self.in_h1:
self.in_h1 = False
self.found.append(" ".join("".join(self.current).split()))
def handle_data(self, data):
if self.in_h1:
self.current.append(data)
def audit(url):
html = urlopen(url).read().decode("utf-8", errors="replace")
parser = H1Collector()
parser.feed(html)
if not parser.found:
print("Problem: no h1 found")
elif len(parser.found) > 1:
print(f"Warning: {len(parser.found)} h1 elements")
for text in parser.found:
if not text:
print("Problem: empty h1")
else:
print(f"h1 ({len(text)} chars): {text}")
if __name__ == "__main__":
audit(sys.argv[1])Run it with python audit_h1.py https://example.com/page. Run it over a list of URLs and compare the output to spot duplicates across pages.
The h1 decision flow
Summary of rules
- One
h1per page, in the main content. - Name the page's task or subject, using the target keyword once and naturally.
- Match the search intent and agree with the title without copying site names or separators.
- Make it unique across the site.
- Prefer real text over an image.
- Keep it short enough to scan, with no stuffing.
Exercise
A product page template wraps the site logo in an h1 on every page, and the product name sits in a styled div. The target keyword is "waterproof hiking boots". Describe the changes you would make to the markup and write the new h1 and title.
Show answer
Change the logo to a plain image link (for example an a element containing an img with alt text) so it is no longer an h1. Change the product name div into the h1 so the page has exactly one h1 that names its topic, and use CSS to keep the visual style. A suitable h1 is "Waterproof Hiking Boots" followed by the product's specific name if there is one, for example "TrailMaster Waterproof Hiking Boots". A suitable title is "TrailMaster Waterproof Hiking Boots | Brand Name", which keeps the keyword near the start and puts the site name last. The h1 omits the site name, and both lines describe the same product.
Exercise
Rewrite this h1 so it is natural and not stuffed, and explain where the removed keyword variants should go: <h1>Snake Plant Repotting: Repot Snake Plant, Snake Plant Repotting Tips</h1>
Show answer
Use <h1>How to Repot a Snake Plant</h1>. It uses the keyword once, matches the how-to intent, and reads as a normal headline. The variants such as "repotting tips" or "when to repot" can appear in h2 and h3 headings and in the body text, where they describe real sections, for example <h2>Repotting tips</h2>.