XML Sitemaps
An XML sitemap lists the URLs you want indexed, helping search engines discover new and updated pages faster.
On this page · 5 min · Intermediate
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Intermediate
- Updated
- Oct 29, 2026
Learning objectives#
- Write a valid XML sitemap
- Choose which URLs to include
- Use lastmod correctly
- Generate and submit sitemaps
Explanation#
A sitemap is an XML file of <url> entries with <loc> (full canonical URL) and optionally <lastmod> (last significant change).
Include only canonical, indexable, 200-status pages. Exclude redirects, noindex pages and duplicates.
Limits: 50,000 URLs or 50 MB per file; larger sites use a sitemap index file.
Generate it automatically at build time, reference it in robots.txt and submit it in Search Console.
Code example: A small sitemap#
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://techiebabaji.com/</loc>
<lastmod>2026-10-29</lastmod>
</url>
<url>
<loc>https://techiebabaji.com/tutorials/react/usestate-hook</loc>
<lastmod>2026-10-27</lastmod>
</url>
<url>
<loc>https://techiebabaji.com/tutorials/sql-server/inner-join</loc>
<lastmod>2026-10-20</lastmod>
</url>
</urlset>
Search Console shows “Success” for the sitemap and the number of discovered URLs.
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- The urlset uses the sitemaps.org namespace.
- Each loc is a full canonical URL.
- lastmod reflects real content updates.
- The file is linked from robots.txt.
Real-world use case#
This site’s build script generates sitemap.xml from every route, so new lessons are listed the moment they are deployed.
Common mistakes#
Mixed signals waste crawl effort. List only canonical, indexable URLs.
Search engines learn to ignore it. Use the real change date.
Best practices#
- Generate automatically
- Only canonical 200 URLs
- Accurate lastmod
- Submit in Search Console
Remember this#
loc = full canonical URL.
Only indexable pages.
50,000 URLs per file, then an index.
Practice exercise#
Your task: Write a sitemap index referencing two sitemaps.
Show solution
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>https://example.com/sitemap-tutorials.xml</loc></sitemap>
<sitemap><loc>https://example.com/sitemap-interview.xml</loc></sitemap>
</sitemapindex>
Mini quiz#
Which URLs belong in a sitemap?
Want more? Practise all SEO MCQs · SEO interview questions
My notes#
Saved in this browser.