sitemap.xml Reference

Complete specification and implementation guide for XML sitemaps. Learn how to structure, validate, and optimize your sitemap for maximum search engine coverage.

A sitemap.xml file is an XML document that helps search engines discover, crawl, and index your website's content. By providing metadata about each URL, you ensure critical pages are processed efficiently and new content gets indexed faster.

✓ Recommended

Always place your sitemap in the root directory at https://example.com/sitemap.xml and reference it in robots.txt.

Basic Structure

Every sitemap must follow the official Sitemap Protocol schema. Below is a minimal valid example:

sitemap.xml
<!-- Minimal valid sitemap --> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>https://example.com/</loc> <lastmod>2024-12-15</lastmod> <changefreq>weekly</changefreq> <priority>1.0</priority> </url> <url> <loc>https://example.com/about</loc> <lastmod>2024-11-20</lastmod> </url> </urlset>

Size & URL Limits

Search engines enforce strict limits on individual sitemap files:

  • Maximum URLs: 50,000 per file
  • Maximum file size: 50 MB uncompressed
  • Compression: Must be gzipped if exceeding limits (use sitemap.xml.gz)
⚠️ Important

If your site exceeds these limits, split into multiple sitemaps and use an index sitemap at sitemap_index.xml.

Tag Reference

Element Required Description
<urlset> Required Root element. Must include the xmlns namespace declaration.
<url> Required Wrapper for individual URL entries. Max 50,000 per file.
<loc> Required Absolute URL of the page. Must be fully qualified (include protocol & path).
<lastmod> Optional Last modification date. Format: YYYY-MM-DD or W3C datetime.
<changefreq> Optional How often content changes. Values: always, hourly, daily, weekly, monthly, yearly, never.
<priority> Optional Relative importance vs other URLs. Range: 0.0 to 1.0. Default: 0.5.

Video Sitemaps

Add the video namespace to promote video content to video search engines:

sitemap_videos.xml
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"> <url> <loc>https://example.com/video-page</loc> <video:video> <video:thumbnail_loc>https://example.com/thumb.jpg</video:thumbnail_loc> <video:title>How to Optimize Sitemaps</video:title> <video:description>Complete guide...</video:description> <video:content_loc>https://example.com/video.mp4</video:content_loc> </video:video> </url> </urlset>

Image Sitemaps

Include images directly in your standard sitemap using the image:image namespace:

image-entry.xml
<url> <loc>https://example.com/gallery</loc> <image:image> <image:loc>https://example.com/photos/img1.jpg</image:loc> <image:caption>Summer collection 2024</image:caption> </image:image> </url>

News Sitemaps

For time-sensitive news articles, use the Google News namespace. Requires manual approval and strict formatting:

  • Articles must be published within last 30 days
  • Include <news:publication> and <news:title>
  • Date format: YYYY-MM-DD

Validation & Testing

Before submitting your sitemap, validate it against the official XSD schema:

bash
# Validate against official schema xmllint --schema sitemaps.xsd --noout sitemap.xml # Check file size and URL count wc -l sitemap.xml ls -lh sitemap.xml

Use tools like Google Search Console or XML Sitemap Validator to catch common errors like malformed dates, missing namespaces, or duplicate <loc> entries.

Best Practices

  • Use absolute URLs with trailing slashes (if applicable) for consistency
  • Exclude canonical duplicates, redirects, and soft 404s
  • Update <lastmod> accurately; never fake timestamps
  • Compress large sitemaps with gzip to reduce bandwidth
  • Reference your sitemap in robots.txt: Sitemap: https://example.com/sitemap.xml
  • Resubmit via Search Console after major content updates

Troubleshooting

IssueCauseSolution
<loc> not found Missing required element Add <loc> to every <url> entry
Invalid date format <lastmod> not W3C compliant Use YYYY-MM-DD or ISO 8601 datetime
Namespace error Missing xmlns declaration Add xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
404 on submission Server blocking XML requests Check .htaccess/firewall rules for text/xml MIME type