Skip to content
Guides

HTML basics for SEO: the elements every page needs

What do the title, meta description, h1, subheadings and alt text do? A beginner's guide with a complete example page and good and bad examples.

What is HTML and why does it matter for SEO?

HTML is the markup language every web page is written in. Its codes, called tags, tell browsers, search engines and tools such as screen readers what each piece of text is: a title, a heading, a paragraph, an image or a link. A visitor only sees the result; a search engine reads the code underneath. The clearer that code, the easier it is to understand what the page is about.

You do not need to be a developer to get this right. In most website builders and content management systems you fill in the page title, the description and the alt text in ordinary form fields, sometimes through an SEO plugin. Choose "Heading 2" in the editor and it becomes an <h2> in the HTML. It does help to know what ends up in the code, so you can check that it is correct.

Google's AI features need no separate HTML. In its guide to generative AI features, Google writes that the usual SEO best practices still apply and that you do not need to create special machine-readable files, markup or Markdown to appear in Search. Perfectly semantic HTML is not required, according to Google, but it is a good idea. See also AI Overviews.

Tags, elements and attributes in one example

<p>Check our <a href="/opening-hours/">opening hours</a> before you visit.</p>
  • <p> is the opening tag and </p> the closing tag. Together with the text between them they form an element, in this case a paragraph.
  • <a> is a link. href="/opening-hours/" is an attribute: extra information about the element, here where the link goes.
  • The text between <a> and </a> is the link text: what the visitor sees and clicks.

What does a simple, well-built page look like?

A page has two parts: the <head>, with information about the page such as the title and the description, and the <body>, with everything the visitor sees. Below is a complete, simplified page for a fictional bakery. Each part is explained further down.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Order sourdough bread in Bristol | Example Bakery</title>
  <meta name="description" content="Fresh sourdough in wholemeal, spelt or rye. Order before 8 pm and collect it the next morning from our shop on Example Street in Bristol.">
  <link rel="canonical" href="https://www.example.com/sourdough/">
</head>
<body>
  <header>
    <a href="/"><img src="/logo.svg" alt="Example Bakery home page"></a>
    <nav>
      <a href="/bread/">Bread</a>
      <a href="/cakes/">Cakes</a>
      <a href="/contact/">Contact</a>
    </nav>
  </header>

  <main>
    <h1>Order sourdough bread</h1>
    <p>Our sourdough rises overnight and goes into the oven fresh every morning.</p>
    <img src="/img/wholemeal-sourdough.jpg" alt="Wholemeal sourdough loaf with a dark crust, sliced on a wooden board">

    <h2>Which kinds of sourdough do we bake?</h2>
    <h3>Wholemeal</h3>
    <p>A hearty loaf made with wholemeal flour and a mildly sour taste.</p>
    <h3>Spelt</h3>
    <p>A little lighter, baked with spelt flour.</p>

    <h2>How do ordering and collection work?</h2>
    <p>Order before 8 pm using the <a href="/order/">bread order form</a> and collect your loaf the next morning.</p>
  </main>

  <footer>
    <p>Example Bakery, 1 Example Street, Bristol</p>
  </footer>
</body>
</html>

At the top is <html lang="en">, which states the language of the page for browsers and screen readers, among others. The head and the body follow.

In the head (not visible on the page):

Part What it does
<meta charset="utf-8"> Makes sure characters such as é and ü display correctly
<meta name="viewport"> Shows the page at the right width on a phone
<title> The title in the browser tab and an important source for the title in Google
<meta name="description"> A short summary that can appear as the text below the title in Google
<link rel="canonical"> The preferred address of the page (canonical URL)

In the body (what the visitor sees):

Part What it does
<header>, <nav>, <main>, <footer> Divide the page into header, menu, main content and footer
<h1> to <h3> The main title and the subheadings
<img alt="..."> An image with a text alternative
<a href="..."> A link to another page

According to the W3C, the regions <header>, <nav>, <main> and <footer> make the layout of the page identifiable for browsers and assistive technologies such as screen readers. The <main> element marks the main content.

A note on language: Google determines the language of a page from its visible text, not from the lang attribute. Always set it correctly anyway, because screen readers use it, for example to read the text with the right pronunciation. See lang attribute.

What goes in the title tag?

The <title> holds a short, specific title that says what this one page is about, optionally with your brand name at the beginning or end. The title does not appear on the page itself but in the browser tab. Google uses it as one of the main sources for the clickable title in search results (documentation).

<!-- Weak: says nothing about the content -->
<title>Home</title>

<!-- Weak: repeats keywords -->
<title>Bread, buy bread, order bread, fresh bread, bread Bristol</title>

<!-- Weak: every page gets the same title -->
<title>Example Bakery</title>

<!-- Better: specific, with the brand name briefly at the end -->
<title>Order sourdough bread in Bristol | Example Bakery</title>

Google's rules of thumb, in short:

  • A unique title for every page. Titles that are (almost) the same across many pages make it hard to tell pages apart.
  • Descriptive and concise. Avoid vague titles such as "Home" or "Profile".
  • No repeated keywords. Mentioning the same word three times does not help.
  • Keep the brand short. Put your site name at the beginning or end, separated by a character such as | or -.
  • Most important first. Google sets no maximum length, but truncates the title in results to what fits on the screen.

Google builds the title in search results automatically and may deviate from your title tag, for example when it is empty, outdated or identical on every page. More in title tag.

What is the meta description and how do you write one?

The meta description is a short summary of the page in the <head>. Visitors do not see it on the page itself, but Google sometimes uses it as the text below the title in search results. According to Google, that text, the snippet, usually comes from the page content. The meta description is used when it describes the page better.

<!-- Weak: a string of keywords -->
<meta name="description" content="bread, sourdough, bakery, Bristol, fresh, order, collect">

<!-- Weak: too short and too general -->
<meta name="description" content="Tasty bread.">

<!-- Better: concrete and specific to this page -->
<meta name="description" content="Fresh sourdough in wholemeal, spelt or rye. Order before 8 pm and collect it the next morning from our shop on Example Street in Bristol.">

What to watch for:

  • Unique per page. The same description on every page helps nobody. Start with the home page and your most visited pages.
  • Facts that matter. For a product, the brand and price; for a shop, the opening hours and location; for an article, the core of the story.
  • No fixed length. There is no maximum, but Google truncates the snippet to fit the screen. One or two sentences is usually enough.
  • Forget the keywords tag. Google Search does not use <meta name="keywords">, according to the SEO Starter Guide.

See also meta description.

Why does every page need one clear h1?

The <h1> is the visible main title on the page: the first thing a visitor reads, and what tells them what the page is about. Google recommends making it clear which text is the main title, for example by putting it in the first visible <h1>, and uses headings such as the <h1> as one of the sources for the title in search results. MDN generally recommends one <h1> per page that describes its content, similar to the <title>. Multiple <h1> elements are technically allowed but are not considered good practice.

<!-- Weak: says nothing about the content -->
<h1>Welcome!</h1>

<!-- Weak: the logo is the h1 on every page -->
<h1><img src="/logo.svg" alt="Example Bakery"></h1>

<!-- Better: the main title of this page -->
<h1>Order sourdough bread</h1>

The title and the h1 may differ. The title often includes the brand name; the h1 can be shorter or a little more personal. Just make sure they cover the same subject.

How do you build a logical heading structure?

Below the h1, divide the text with <h2> headings for the main sections and <h3> headings for parts within them, just like chapters and sections in a table of contents. For the bakery page above, that looks like this:

h1  Order sourdough bread
├── h2  Which kinds of sourdough do we bake?
│   ├── h3  Wholemeal
│   └── h3  Spelt
└── h2  How do ordering and collection work?

Three rules that almost always keep you on track:

  1. Do not skip levels. After an h1 comes an h2, not an h4. MDN writes that otherwise a screen reader user is left wondering where the missing heading is.
  2. Choose a heading for its meaning, not its font size. If you want smaller or larger text, use CSS rather than a different heading level.
  3. Make headings descriptive. "How do ordering and collection work?" says more than "More information". A heading phrased as a question, with a short answer directly below it, works well for readers and for search systems that quote a passage (see AEO).

Why it matters: according to MDN, jumping from heading to heading is a common way for screen reader users to find out what a page contains. Google's SEO Starter Guide says that heading order does not matter for Google Search itself, but that a semantic order is great for screen readers. In its guide to AI features, Google mentions pages organised in paragraphs and sections with headings that provide a clear structure. So you build a good heading structure for people first. See also heading structure.

What goes in an image's alt text?

Alt text describes in a few words what an image shows. Screen readers read it aloud, browsers show it when the image fails to load, and Google uses it to understand the image. Google does this together with computer vision and the content of the page (image guidelines).

<!-- Wrong: no alt attribute and a meaningless file name -->
<img src="IMG00023.jpg">

<!-- Weak: too general -->
<img src="bread.jpg" alt="bread">

<!-- Wrong: stuffed with keywords -->
<img src="bread.jpg" alt="bread sourdough bakery bristol buy bread fresh bread best baker">

<!-- Good: describes what can be seen -->
<img src="wholemeal-sourdough.jpg" alt="Wholemeal sourdough loaf with a dark crust, sliced on a wooden board">

<!-- Good: a purely decorative image gets an empty alt -->
<img src="/img/divider.svg" alt="">

The key rules:

  • Describe what matters for this page, briefly and concretely, as you would explain it to someone over the phone.
  • Decorative? Leave the alt empty (alt=""), but do not leave out the attribute. Without alt, some screen readers read out the file name.
  • Image inside a link or button? Describe where the link goes or what the button does, such as "Example Bakery home page" for a linked logo. Google uses the alt text of a linked image as the link text.
  • No keyword lists. Google calls that a poor experience that may cause your site to be seen as spam.
  • Give the file a descriptive name, such as wholemeal-sourdough.jpg rather than IMG00023.jpg.

More examples and exceptions in alt text.

Use a real <a href="..."> link with link text that says where the link goes. Google can generally only crawl links reliably if they are <a> elements with an href, and it uses the link text to understand what the linked page is about (link best practices).

<!-- Weak: the link text says nothing -->
<a href="/order/">Click here</a> to order.

<!-- Better: the link text describes the destination -->
Order using the <a href="/order/">bread order form</a>.

<!-- Wrong: not a real link, a search engine cannot follow it properly -->
<span onclick="location.href='/order/'">Order</span>

A handy test from Google: read only the link text, out of context. Is it still clear where the link goes? See also internal links.

How do you check the HTML of your own page?

Open the page source and search for <title, name="description", <h1 and alt=, or paste a few lines into your browser's console.

  1. View the page source. In Chrome, Edge or Firefox press Ctrl+U (on a Mac usually Cmd+Option+U) and search with Ctrl+F or Cmd+F. The source shows what the server sends. If you can see a piece of text on screen but not in the source, it is added by JavaScript. In that case, read about server-side rendering.
  2. A quick overview in the console. Open the developer tools with F12, go to the Console tab and paste the code below. Chrome may first ask you to type allow pasting. Only paste code you understand.
console.log("Title:", document.title);
console.log("Description:", document.querySelector('meta[name="description"]')?.content ?? "(none)");
console.table([...document.querySelectorAll("h1, h2, h3, h4, h5, h6")].map((h) => ({ heading: h.tagName, text: h.textContent.trim() })));
console.log("Images without alt:", [...document.querySelectorAll("img:not([alt])")].map((img) => img.src));
  1. Compare with Google. Search for one of your pages and check whether the title and the text below it match what you set. After a change, it can take a few days to a few weeks before Google shows the new version.

Checklist

  • <html lang="en"> (or the language of the page) is at the top.
  • Every page has its own descriptive <title>, with the brand name briefly at the beginning or end.
  • The most important pages have their own meta description with concrete information.
  • There is one visible <h1> that says what the page is about.
  • The text is divided with <h2> and <h3> headings, without skipping levels.
  • Headings are chosen for meaning, not font size.
  • Every informative image has descriptive alt text; decorative images have alt="".
  • Images have descriptive file names.
  • Links are real <a href> links with link text that names the destination.
  • The most important text is in the page source, not only after JavaScript.

Want to know how your own home page is doing? The free scan checks, among other things, the title, the meta description, the lang attribute and whether there is one h1 with subheadings.

Frequently asked questions

Do I need to be able to write HTML to get this right?

No. In most website builders and content management systems you fill in the page title, the meta description and the alt text in ordinary form fields, sometimes through an SEO plugin, and you pick headings in the editor. It does help to know what ends up in the HTML, so you can check in the page source that it is correct.

What is the difference between the title tag and the h1?

The title tag sits in the head and appears in the browser tab; Google uses it as an important source for the title in search results. The h1 is the visible main title on the page itself. They may differ slightly, for example because the brand name only appears in the title, but they should be about the same subject.

Is the meta keywords tag still worth adding?

No. Google's SEO Starter Guide states that Google Search does not use the keywords meta tag. You can leave it out.

Does my HTML have to be flawless for Google or AI assistants?

Google writes that perfectly semantic HTML is not required, partly because the web as a whole is not valid HTML either. Clear HTML with its own title, logical headings and alt text is still a good idea: it helps visitors, screen readers and any system that reads your page.

How many headings should a page have?

There is no fixed number. Google's SEO Starter Guide says there is no ideal amount of headings. Start a new heading where a new topic begins. If it feels like too many, Google says it probably is.

Sources

  1. Google Search Central: SEO Starter Guide
  2. Google Search Central: Influencing your title links in search results
  3. Google Search Central: Control your snippets in search results (meta descriptions)
  4. Google Search Central: Image SEO best practices
  5. Google Search Central: Link best practices for Google
  6. Google Search Central: Optimizing your website for generative AI features on Google Search
  7. Google Search Central: Managing multi-regional and multilingual sites (page language)
  8. MDN: <h1>–<h6> HTML section heading elements
  9. MDN: What's in the head? Web page metadata
  10. W3C WAI: Page Regions

How visible is your website?

Find out for free how you score in Google and in ChatGPT, Gemini and Claude.

Start free scan

Read also