You've built a great page. Now you want people to find it when they search Google for "binary search explained". Search Engine Optimisation (SEO) is the practice of making pages easy for search engines to find, understand and show to the right people.
A lot of SEO advice online is myths and tricks. In this chapter we'll focus on what actually matters at the HTML level, based on Google's own published guidance: the tags search engines read, how to write them well, and which old tricks to ignore. You'll notice that much of it is the same clean, semantic, accessible HTML you've learned in the previous chapters.
How a Search Engine Works
A search engine handles your page in three stages:
1. CRAWL A program called a crawler (Google's is Googlebot) follows links
and downloads pages: HTML, images, CSS, JavaScript.
│
▼
2. INDEX It reads the page, works out what it's about (title, headings,
text, links, structured data) and stores it in a huge index.
│
▼
3. RANK When someone searches, it picks the most relevant, useful
pages from the index and orders them.HTML affects all three: links let pages be crawled, clear structure helps them be indexed correctly, and good titles and descriptions affect how they look in results and whether people click.
The most important SEO factor is still the content itself: is it helpful, original and trustworthy? HTML can't rescue a bad page, but bad HTML can hide a good one.
A Complete SEO-Friendly Page
Here's a full example. We'll go through each part below.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Binary Search Explained with Examples | CS Notes</title>
<meta name="description"
content="Learn how binary search works step by step, why it runs in O(log n) time, and how to write it in C, Java and Python.">
<link rel="canonical" href="https://example.com/dsa/binary-search">
<!-- Social sharing (Open Graph) -->
<meta property="og:type" content="article">
<meta property="og:title" content="Binary Search Explained with Examples">
<meta property="og:description" content="How binary search works and why it is O(log n).">
<meta property="og:url" content="https://example.com/dsa/binary-search">
<meta property="og:image" content="https://example.com/images/binary-search-cover.png">
<!-- Structured data for search engines -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "Binary Search Explained with Examples",
"author": { "@type": "Person", "name": "Riya Sharma" },
"datePublished": "2026-10-20",
"dateModified": "2026-11-01",
"image": "https://example.com/images/binary-search-cover.png"
}
</script>
</head>
<body>
<header>
<nav aria-label="Main">
<a href="/">Home</a>
<a href="/dsa">Data Structures</a>
</nav>
</header>
<main>
<article>
<h1>Binary Search Explained with Examples</h1>
<p>By Riya Sharma · Updated <time datetime="2026-11-01">1 November 2026</time></p>
<p>Binary search finds an item in a <strong>sorted</strong> array by
repeatedly halving the search range.</p>
<h2>How Binary Search Works</h2>
<p>Compare the target with the middle element ...</p>
<figure>
<img src="/images/binary-search-steps.png" width="800" height="400"
alt="Searching for 23 in a sorted array of 10 numbers takes 3 steps">
<figcaption>Each step discards half of the remaining elements.</figcaption>
</figure>
<h2>Time Complexity of Binary Search</h2>
<p>Each comparison halves the range, so it needs about log₂ n steps.
Compare this with <a href="/dsa/linear-search">linear search</a>,
which may check all n elements.</p>
</article>
</main>
<footer>
<p>© 2026 CS Notes</p>
</footer>
</body>
</html>The <title> Element
The <title> (introduced in The Head Element & Meta Tags chapter) is the single most important SEO tag on the page. Google usually uses it as the clickable blue headline in search results, called the title link.
CS Notes
https://example.com › dsa › binary-search
Binary Search Explained with Examples | CS Notes ← from <title>
Learn how binary search works step by step, why it ← often from the
runs in O(log n) time, and how to write it in C, ... meta descriptionGood titles:
Are unique on every page. Ten pages all called "Home" or "CS Notes" can't be told apart.
Describe the page specifically, with the main topic near the start: "Binary Search Explained with Examples", not "Welcome to my website".
Are reasonably short. Google has no fixed character limit, but it cuts long titles to fit the screen width, so roughly 50 to 60 characters is a sensible target.
Don't stuff keywords. "Binary Search, Binary Search Algorithm, Binary Search C, Binary Search Java" looks spammy; Google may rewrite it.
Google may show a different title link than your <title> if it thinks yours doesn't describe the page well (for example, it might use your <h1>). Writing a clear, accurate title is the best way to keep yours.
The Meta Description
<meta name="description"
content="Learn how binary search works step by step, why it runs in O(log n) time, and how to write it in C, Java and Python.">The meta description is a short summary of the page. Two facts that surprise many people:
It is not a ranking factor for Google. It won't move you up the results.
It can still matter a lot, because Google often shows it as the snippet under the title, and a clear snippet makes people click. (Google may instead pick a passage from your page that better matches the search.)
Write a unique, honest one to two sentence summary for each page, around 150 characters, that tells the reader what they'll get.
Headings and Semantic Structure
Search engines use headings to understand what each part of a page is about, just like screen readers do (see the Accessibility Basics chapter).
h1 Binary Search Explained with Examples ← the main topic
├── h2 How Binary Search Works ← subtopic
└── h2 Time Complexity of Binary Search ← subtopicUse one clear
<h1>that matches the page's main topic. (More than one isn't penalised by Google, but one is clearest for readers.)Use
<h2>–<h6>in order, as an outline, not for font size.Use elements like
<main>,<article>,<nav>and<footer>(from the Semantic HTML chapter) so it's obvious which part is the real content and which is navigation.Put important content in real text, not inside images. Text in an image is much harder for search engines (and impossible for some users) to read.
Links
Links are how crawlers discover pages, and the link text tells them what the target page is about.
Bad | Good |
|---|---|
|
|
|
|
Crawlers follow <a> elements with an href. Navigation built only from JavaScript click handlers may never be discovered.
You can describe your relationship to a linked page with rel:
Value | Use for |
|---|---|
| Paid links, adverts, affiliate links |
| Links inside user-generated content, like comments and forum posts |
| Any other link you don't want to vouch for |
Google treats these as hints, not strict commands.
Images
Images can bring visitors through image search, and they affect page speed. Use what you learned in the Images and Responsive Images chapters:
Descriptive
alttext (search engines use it to understand the image).Meaningful file names:
binary-search-steps.pngrather thanIMG_4521.png.widthandheightattributes, so the browser reserves space and the page doesn't jump while loading.Modern formats and
srcsetto avoid sending huge files to small screens, andloading="lazy"for images further down the page (but not for the main image at the top).
Canonical URLs
The same content often has several URLs:
https://example.com/dsa/binary-search
https://example.com/dsa/binary-search?ref=whatsapp
https://www.example.com/dsa/binary-search
http://example.com/dsa/binary-searchTo a search engine these can look like four duplicate pages. The canonical link tells it which one is the "main" version:
<link rel="canonical" href="https://example.com/dsa/binary-search">Use an absolute URL (with https://). Like rel on links, Google treats canonical as a strong hint, combining it with other signals such as redirects and sitemaps.
Controlling Indexing: the Robots Meta Tag
Sometimes you don't want a page in search results at all, such as a "thank you for registering" page, an admin page or search results within your own site:
<meta name="robots" content="noindex">Value | Meaning |
|---|---|
| Don't show this page in search results |
| Don't follow the links on this page |
| Don't show a text snippet for this page |
The default is "index, follow", so you never need to write <meta name="robots" content="index, follow">.
Don't confuse this with robots.txt, a separate file at the site root that tells crawlers which URLs they may crawl. A common mistake: blocking a page in robots.txt and adding noindex. If the crawler can't fetch the page, it never sees the noindex, and the URL can still appear in results if other sites link to it. Similarly, an XML sitemap lists the URLs you want discovered; it's also a separate file, not HTML.
Structured Data (JSON-LD)
Structured data is machine-readable information about a page, written using the shared Schema.org vocabulary, so search engines know exactly what things on the page are: an article, its author, its publish date, a product's price, and so on.
Google recommends the JSON-LD format, placed in a script tag:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "Binary Search Explained with Examples",
"author": { "@type": "Person", "name": "Riya Sharma" },
"datePublished": "2026-10-20",
"dateModified": "2026-11-01"
}
</script>The browser doesn't run or display this script (its type isn't JavaScript); it's just data. Some types can make your page eligible for rich results, such as star ratings, product prices or event dates shown in the search results.
Two important rules: the structured data must describe content that is visible on the page (here, the headline and author really appear in the article), and it's no guarantee of a rich result. Google also changes which types it supports; for example, in 2025 it stopped showing several rich result types, including Course Info and Estimated Salary. Check Google's Search Gallery for the current list and test your markup with the Rich Results Test.
Social Sharing Tags (Open Graph)
<meta property="og:title" content="Binary Search Explained with Examples">
<meta property="og:description" content="How binary search works and why it is O(log n).">
<meta property="og:image" content="https://example.com/images/binary-search-cover.png">
<meta property="og:url" content="https://example.com/dsa/binary-search">Open Graph tags control the title, description and preview image when your link is shared on WhatsApp, LinkedIn, Facebook and similar apps. They don't affect Google rankings directly, but an attractive preview gets more clicks and shares. Use absolute URLs for og:image.
Mobile-Friendliness and Page Speed
Google indexes the mobile version of pages (mobile-first indexing), so your page must work well on phones. That starts with the viewport meta tag from The Head Element & Meta Tags chapter:
<meta name="viewport" content="width=device-width, initial-scale=1">Google also measures real-user experience with the Core Web Vitals:
Metric | Measures | "Good" threshold | HTML that helps |
|---|---|---|---|
LCP (Largest Contentful Paint) | How fast the main content appears | ≤ 2.5 s | Small optimised images, no lazy loading on the main image, |
INP (Interaction to Next Paint) | How quickly the page responds to clicks and taps | ≤ 200 ms | Less heavy JavaScript; native elements instead of script-built widgets |
CLS (Cumulative Layout Shift) | How much the layout jumps while loading | ≤ 0.1 |
|
(INP replaced the older FID metric in March 2024, so older articles that mention FID are out of date.)
Other Signals and Myths
Claim | Reality |
|---|---|
"Add | Myth. Google ignores the keywords meta tag completely. |
"Repeat your keyword many times" | Harmful. Keyword stuffing is against Google's spam policies. |
"Hide keywords in white text" | Spam. Hidden text can get a page penalised. |
"Set | Good practice for accessibility and browsers; for multiple language versions of a page, use |
"HTTPS matters" | True, as a small signal, and browsers warn users about non-HTTPS pages. |
"Readable URLs help" | Helpful: |
If you have the same page in several languages, link the versions with hreflang:
<link rel="alternate" hreflang="en" href="https://example.com/en/binary-search">
<link rel="alternate" hreflang="hi" href="https://example.com/hi/binary-search">
<link rel="alternate" hreflang="x-default" href="https://example.com/binary-search">And what about AI answers in search, like Google's AI Overviews? Google says the same SEO basics apply: crawlable pages, helpful text content, and accurate structured data. There's no special HTML tag for them.
Common Mistakes
The same
<title>and description on every page (often copied from a template).Important text inside images or inside a canvas.
Links that aren't
<a href>, so crawlers can't follow them.Leaving
noindexon after moving a site from a test server to the live one, which removes the whole site from search.Relative or wrong canonical URLs, or every page pointing its canonical at the home page.
Structured data that doesn't match the page, such as review stars that don't exist.
Spending time on the keywords meta tag, which does nothing.
Interview Questions
Does the meta description affect ranking?
Not directly for Google. It can be used as the snippet in search results, so a good description can improve the click-through rate, but it isn't a ranking factor.
What does rel="canonical" do?
It tells search engines which URL is the preferred version when the same or very similar content is available at several URLs, so ranking signals are combined on one URL and duplicates aren't shown. Search engines treat it as a strong hint, not an absolute rule.
What is the difference between robots.txt and the robots meta tag?
robots.txt controls crawling: which URLs a crawler may fetch. The robots meta tag (for example noindex) controls indexing of a page the crawler has fetched. To keep a page out of results, use noindex and allow it to be crawled, so the crawler can see the tag.
What is structured data and which format does Google recommend?
Machine-readable information about the page's content using the Schema.org vocabulary. Google recommends JSON-LD inside a <script type="application/ld+json"> tag. It can make pages eligible for rich results.
Name the three Core Web Vitals and their "good" thresholds.
LCP (Largest Contentful Paint) ≤ 2.5 seconds, INP (Interaction to Next Paint) ≤ 200 milliseconds, and CLS (Cumulative Layout Shift) ≤ 0.1.
Do Open Graph tags improve Google ranking?
No. They control how links look when shared on social and messaging apps. They can increase clicks and shares, but they aren't a Google ranking factor.
Conclusion
Search engines crawl, index and rank; good HTML helps with all three, but helpful content matters most.
Write a unique, descriptive
<title>and meta description for every page.Use semantic structure: one clear
<h1>, ordered headings, real text, and<a href>links with descriptive text.Use
rel="canonical"for duplicate URLs,noindexfor pages that shouldn't appear in search, and JSON-LD structured data where it fits the visible content.Make pages fast and mobile-friendly (viewport, image dimensions, Core Web Vitals). Ignore myths like the keywords meta tag.
Most of SEO at the HTML level comes down to writing correct, well-structured markup. In the next chapter, HTML Best Practices & Validation, we'll collect the habits that keep your HTML clean and learn how to check it automatically.