HTML SEO Basics
Before you learn any single tag, it helps to see the whole picture. What does a search engine actually receive when it visits your page, and what in that HTML helps it make sense of it?
This lesson is your map. It covers the basics that every page needs, with a quick look at each. The next lessons zoom in on the big ones: titles, descriptions, headings, semantics, canonical links, robots, structured data, and sharing.
What You Will Learnβ
- What a search engine receives when it visits your page
- The head essentials every page needs
- Writing real text, headings, and links that crawlers can use
- How to treat images and URLs
- Mobile and speed basics that live in your HTML
- How JavaScript can hide content from crawlers
- Why status codes, sitemaps, and robots.txt matter
- How to check a page
The Big Ideaβ
- HTML Code
- Crawler's View Lab
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Rye Bread Recipe: Easy No-Knead Loaf | The Bread Bin</title>
<meta name="description" content="Bake a crusty rye loaf at home with five simple ingredients.">
<link rel="canonical" href="https://thebreadbin.example/recipes/rye-bread">
</head>
<body>
<header>
<nav aria-label="Main">
<a href="/recipes">Recipes</a>
<a href="/about">About</a>
</nav>
</header>
<main>
<h1>Easy No-Knead Rye Bread</h1>
<p>Bake a crusty rye loaf with five simple ingredients.</p>
<img src="/img/rye-bread.jpg" alt="A rye loaf cooling on a wooden board" width="800" height="600">
<h2>Ingredients</h2>
<ul>
<li>500 g rye flour</li>
<li>350 ml warm water</li>
</ul>
<p><a href="/recipes/rye-bread/steps">Read the step-by-step method</a></p>
</main>
<footer>...</footer>
</body>
</html>
For each part of a page, choose how it is built. Then see what a crawler reading the raw HTML finds.
Your HTML:
<span onclick="go('/recipes')">Recipes</span>
<div class="big-text">Rye Bread</div>
<img src="description.png">
<p id="time"></p>
<script>/* fills #time later */</script>
What a crawler reading the raw HTML finds:
- A menu link: Just the word "Recipes". There is no href, so there is no link to follow.
- The page heading: Plain text in a div. It looks big, but nothing says it is the main heading.
- The description: An image with no alt text. The words in it cannot be read as text.
- The cooking time: An empty paragraph. Search engines may run the script, but it can be delayed, and some crawlers do not run scripts at all.
0 of 4 parts are built in a search-friendly way.
This is a simplified picture. Modern search engines can run JavaScript and understand many layouts, but plain HTML is the most reliable, and it also works better for people, screen readers, and slow connections.
Switch each part from the risky choice to plain HTML, and watch what the crawler can suddenly find. Nothing here is clever. It is just meaningful HTML.
What a Search Engine Receivesβ
When a crawler visits your page, it first downloads the raw HTML from your server. It looks for:
- The head: title, description, canonical, robots, language.
- The text in the body, and how it is organised into headings and sections.
- The links, to find more pages.
- The images, with their alt text.
- Any structured data.
Many search engines can then also run your JavaScript to see the final page, but that step can be slower, can be limited, and does not happen with every crawler. So the safest rule is: put the important things in the HTML itself.
Right-click your page and choose View page source. This shows the raw HTML the server sent, before any scripts ran. If your key text, headings, and links are missing there, they may be missing for crawlers too. (The browser's Elements panel in developer tools shows the page after scripts have run, which is different.)
The Head Essentialsβ
| Tag | Why it matters |
|---|---|
<!doctype html> | Tells browsers to use standards mode |
<html lang="en"> | Says what language the page is in |
<meta charset="utf-8"> | Makes sure characters display correctly |
<meta name="viewport" ...> | Makes the page scale properly on phones |
<title> | Names the page in results and tabs |
<meta name="description"> | Offers a summary for the result snippet |
<link rel="canonical"> | Names the main address of the page |
You can read the basics of the first few in Title, Viewport, and Charset. The next lessons cover title, description, and canonical in an SEO light.
The Body: Real Text, Real Structureβ
Search engines are built to read text. Help them:
- Put your content in real text, not in images. If you must use an image of text, add alt text that repeats the words.
- Use one
h1that says what the page is about, andh2toh6for sections. See Headings and SEO. - Use semantic elements such as
main,nav,article,section, andfooter. See Semantic HTML and SEO. - Use lists and tables for lists and data. They carry meaning.
- Write one clear topic per page, answering a real question. If you cover two different topics, make two pages.
- Write for people. Repeating a keyword over and over helps no one.
Links Search Engines Can Followβ
Crawlers discover your site by following links. A link is only a link if it is a real a element with an href.
<!-- Good: a crawler can follow it, and so can a keyboard -->
<a href="/recipes/rye-bread">Rye bread recipe</a>
<!-- Poor: no href, so no link -->
<a onclick="go('/recipes/rye-bread')">Rye bread recipe</a>
<span onclick="go('/recipes/rye-bread')">Rye bread recipe</span>
- Write descriptive link text. "Rye bread recipe" says far more than "click here." It helps people, screen readers, and crawlers. See also Accessible Links.
- Link between your own pages, so no page is an "orphan" with nothing pointing at it. See Internal Links.
- Choose
relvalues for outside links when it matters:rel="nofollow"for links you do not want to vouch for,rel="sponsored"for paid links, andrel="ugc"for links in user comments. See External Links.
Imagesβ
- Add useful alt text that describes what the image shows. It helps accessibility and image search. See Alt Text.
- Give images clear file names, such as
rye-bread-loaf.jpgrather thanIMG_0042.jpg. - Set
widthandheight, so the page does not jump while images load. - Use the right size and format. Huge images slow the page. See Responsive Images.
- Lazy-load images below the fold with
loading="lazy", but not your main image at the top. See Lazy Loading.
Clean URLsβ
An address is part of the experience. People see it, share it, and sometimes read it aloud. Try the checker:
6 things to improve.
- Improve: Uses http. Prefer https.
- Improve: Has capital letters. Paths can be case sensitive, so lowercase is safer.
- Improve: Contains spaces. Use hyphens.
- Improve: Has underscores. Hyphens are easier to read as word breaks.
- Improve: 3 query parameters. Many parameters can create endless duplicate pages.
- OK: A reasonable length (25 characters).
- OK: Has readable words.
- Improve: Contains a session id. This is private data and creates duplicate pages.
These are friendly guidelines, not laws. Search engines can handle many kinds of addresses. Clear, stable, readable ones are simply easier for people, and less likely to cause problems.
Some friendly habits:
- Use words that describe the page:
/recipes/rye-bread. - Use lowercase and hyphens, not spaces or underscores.
- Keep them short and stable. If an address must change, redirect the old one to the new one with a permanent redirect (301).
- Avoid long strings of parameters and anything private, such as session ids or emails.
- Use https everywhere.
Mobile and Speed Basicsβ
Most searches today happen on phones, and search engines largely look at the mobile version of your page. A page that is slow or hard to use on a phone is hard to love. Several basics live in your HTML:
- The viewport meta tag, so the page scales to the device.
- Responsive layouts, which are covered in your CSS lessons.
widthandheighton images, to avoid layout jumps.deferorasyncon scripts, so they do not block the page. See Script.- Small, compressed images and few heavy third-party scripts.
- Large tap targets and readable text.
Speed and page experience are only part of ranking, but slow pages also lose visitors, whatever the ranking.
JavaScript and SEOβ
Many modern sites build pages in the browser with JavaScript. That can work, but it adds risk:
- The crawler may see an empty page at first, and fill in the content later.
- Some search engines, social apps, and other bots do not run scripts.
- Content that only loads after a click or scroll may never be seen.
- Links created without
hrefare not followed.
How to stay safe:
- Send the important content in the first HTML (server-side rendering or static generation). Docusaurus, which powers this site, builds static HTML pages for exactly this reason.
- Use real links for navigation, even in a single-page app.
- Give each page its own address, title, and description.
- Test with "view source" and with Search Console's URL inspection tool.
Status Codes, Sitemaps, and robots.txtβ
A few things sit outside your HTML, but they affect everything:
- Status codes. A working page returns 200. A moved page returns a redirect (301 for permanent). A missing page should return 404. A page that says "not found" but returns 200 is called a soft 404, and confuses search engines.
- A sitemap (usually
sitemap.xml) lists the pages you want found. It helps, but it does not guarantee they are indexed. - robots.txt is a file at the top of your site that asks crawlers which paths to avoid. It controls crawling, not whether a page can appear in results. The
robotsmeta tag is covered in Robots Meta.
Check Your Pageβ
Run the checker on the messy page. Fix every problem in the box, and then try the fixed page.
- HTML Code
- Basics Checker
<!-- Things the checker looks for -->
<title>Home</title> <!-- too generic -->
<h1>Welcome</h1> <!-- vague, and there are two -->
<a>Recipes</a> <!-- no href -->
<a href="/more">click here</a> <!-- vague link text -->
<img src="IMG_0042.jpg"> <!-- no alt, no size, bad file name -->
<meta name="robots" content="noindex"> <!-- is this on purpose? -->
Check it by handβ
- View the page source. Is your content in there?
- Search for your own page with
site:yourdomain.comin a search engine, to see what is listed. - Use Google Search Console (or Bing Webmaster Tools) and its URL inspection tool, to see how a search engine saw your page.
- Run Lighthouse in Chrome DevTools for a basic SEO, speed, and accessibility check.
- Try your page on a phone, on a slow connection if you can.
Good Habitsβ
- Put the important content in the HTML.
- Give each page one purpose, a unique title, and a description.
- Use real links with descriptive text.
- Describe images, and give them sizes.
- Keep addresses clean and stable, with redirects when they change.
- Test on mobile, and on slow connections.
- Check with "view source" and Search Console.
- Be patient. SEO takes time.
SEO Basics Checklistβ
-
doctype,lang,charset, andviewportare set - The title is unique and descriptive
- There is a meta description
- There is one
h1, and headings follow an outline - Main content is real text inside
main - Links are real
aelements withhref, and descriptive text - Images have alt text, clear names, and width and height
- Addresses are clean, lowercase, and stable, and use https
- Old addresses redirect with 301
- Missing pages return 404
- Important content appears in "view source"
- A sitemap exists, and robots.txt does not block what you want found
Security and Privacy Notesβ
- Do not put private information in URLs. Emails, tokens, and session ids in an address end up in browser history, logs, and shared links, and can be indexed.
- Check what is public. Staging sites, test pages, backups, and admin screens can be found by crawlers if they are reachable. Protect them with a login, and not only with
noindexor robots.txt. robots.txtis public. Anyone can read it, so do not list secret paths in it.- Use https. It protects visitors, and search engines prefer it.
- Watch out for hidden text and cloaking, showing crawlers something different from what people see. It is against search guidelines, and it can look like a security problem.
- Use
rel="ugc"orrel="nofollow"on links added by visitors, and moderate comments, to limit spam. - Respect privacy laws if you add analytics or tracking. This is not legal advice, so check the rules that apply to you.
Global Audience Notesβ
- Set
langcorrectly, and write each page in one main language. See International SEO. - Use UTF-8 so names and scripts from any language display correctly.
- Addresses can contain non-English words. Many sites keep addresses in a simple form (transliterated or English) for easier sharing. Whatever you choose, be consistent.
- Mobile and slow networks matter most in many regions. Test on modest phones.
- Search engines differ by country. Check the guidelines of the ones your readers use.
- Date, currency, and units should match your readers' region.
Common Mistakes to Avoidβ
- Hiding content in scripts, so "view source" shows an empty page.
- Links with no
href, or buttons used as links. - Text inside images with no alt text.
- Generic titles such as "Home" on every page.
- No
h1, or several of them, or headings used only for style. - Link text like "click here."
- Messy, long, changing addresses, with no redirects.
- Missing viewport tag, so phones show a tiny page.
- Large, unsized images.
- Using
noindexby accident, often left over from testing. - Soft 404 pages that say "not found" but return 200.
- Never checking what search engines actually see.
Practice Timeβ
Try these in your browser and your editor:
- Use the crawler's view lab. Which risky choice would you be most likely to make by accident?
- Use the URL checker on three addresses from your own projects.
- Run the basics checker on the messy page, fix every problem, and run it again.
- Open a page you built, and choose View page source. Is your main content there?
- Search for
site:and your domain. How many of your pages are listed? - Find a "click here" link in one of your pages, and rewrite it.
- Add
widthandheightto every image in a page. - Add a meta description and a canonical link to a page.
- Run Lighthouse on a page, and fix one SEO item it reports.
- Bonus: build a three-page site where every page is linked from at least one other page, and has a unique title and description.
Quick Recapβ
Click a question to check your answer.
1. What does a crawler first receive from your page?
The raw HTML from the server. It reads the head, the text and structure, the links, the images, and any structured data. Running JavaScript is a later, less certain step.
2. What are the head essentials?
The doctype, the lang attribute, the charset, the viewport meta tag, a title, a meta description, and, when needed, a canonical link.
3. What makes a link something a crawler can follow?
It must be an <a> element with an href. Click handlers on other elements are not links.
4. Why set width and height on images?
So the browser can reserve space for them, and the page does not jump around while images load.
5. How can JavaScript hurt SEO?
Content that only appears after scripts run can be missed or delayed, and some crawlers do not run scripts. Send important content in the HTML, and use real links.
6. What is a soft 404?
A page that tells people "not found" but returns a 200 (success) status code. Return a real 404 for missing pages.
Key Takeawaysβ
- Put the important content in the HTML. "View source" shows what a crawler gets first.
- Every page needs the head essentials, a unique title, and a description.
- Use real text, headings, and semantic elements so the structure is clear.
- Real links with descriptive text help crawlers, people, and screen readers.
- Describe images, give them sizes, and name them clearly.
- Keep addresses clean and stable, and redirect when they change.
- Mobile, speed, and JavaScript choices can help or hurt.
- Check your pages, and be patient.
Next, learn how to write a title that people and search engines both understand, in Title (SEO).