TExcelTAD
Home › HTML › HTML Page Title

HTML Page Title

Every HTML document should have a title. It's a short piece of text that names the page, defined with the <title> element inside <head>. Although it never appears in the page body, it shows up in many important places.

html
<!DOCTYPE html>
<html>
<head>
  <title>Chocolate Chip Cookies – Easy Recipe | Baking Corner</title>
</head>
<body>
  <h1>Chocolate Chip Cookies</h1>
</body>
</html>

Where the title appears

Place How the title is used
Browser tab The text next to the favicon
Bookmarks / favorites The default name when someone saves the page
Browser history How the page is listed
Search engine results Usually the big clickable headline
Social media shares Often used when no special share title is set
Screen readers Announced first when the page loads

Because the title is the first thing people see in search results and the first thing screen reader users hear, it has a big effect on whether people find and understand your page.

Rules for the title element

  • There must be only one <title> per document.
  • It must be inside <head>.
  • It contains text only — any tags inside are shown literally, not rendered.
  • It is required for a valid HTML document.

Reading and changing the title with JavaScript

The title is available to scripts as document.title. The example below reads it and lets you change it. (Inside this tutorial the example runs in a frame, so your browser tab won't change — but the value really is updated.)

html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <title>Original title</title>
</head>
<body>
  <p>Current title: <strong id="out"></strong></p>
  <input id="newTitle" value="Hello from the playground">
  <button id="btn">Change title</button>
  <script>
    const out = document.getElementById('out');
    out.textContent = document.title;
    document.getElementById('btn').addEventListener('click', () => {
      document.title = document.getElementById('newTitle').value;
      out.textContent = document.title;
    });
  </script>
</body>
</html>

Sites use this trick to show notifications in the tab, for example "(3) Inbox – Mail".

Writing a good title

A good title is specific, concise and unique to each page.

Weak title Better title
Home Riverside Bikes – Repairs and Rentals in Portland
Page 2 Opening Hours – Riverside Bikes
Untitled Document How to Fix a Flat Tire in 5 Steps
Welcome to our website!!! Contact Us – Riverside Bikes

Tips:

  • Put the most important words first. Tabs and search results cut long titles off.
  • Aim for roughly 50–60 characters.
  • A common pattern is Page topic – Site name.
  • Don't stuff it with repeated keywords; write for humans.

Title vs. the main heading

The <title> and the page's <h1> are related but not the same thing:

  • <title> lives in the head and describes the page from the outside (tabs, search results).
  • <h1> lives in the body and is the visible heading on the page.

They are often similar, but the title usually includes the site name and the <h1> does not.

html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <title>Fix a Flat Tire – Riverside Bikes</title>
  <style>
    body { font-family: sans-serif; }
    .tab { background: #eef; padding: 6px 10px; border-radius: 6px 6px 0 0; display: inline-block; font-size: 13px; }
  </style>
</head>
<body>
  <div class="tab" id="tab"></div>
  <h1>How to Fix a Flat Tire</h1>
  <p>The tab label above is filled in from <code>document.title</code>, while this heading is the <code>&lt;h1&gt;</code>.</p>
  <script>
    document.getElementById('tab').textContent = '🚲 ' + document.title;
  </script>
</body>
</html>

Tip: Screen reader users often switch between open tabs by listening to their titles. Unique, descriptive titles make that fast and painless.

Test yourself

Where must the <title> element be placed?

  1. Inside <body>
  2. Inside <head>
  3. Before <!DOCTYPE html>
  4. Inside <h1>

How many <title> elements can a document have?

  1. None
  2. Exactly one
  3. One per section
  4. As many as you like

Which JavaScript property reads or changes the page title?

  1. window.title
  2. document.head.title
  3. document.title
  4. page.title