HomeArticlesHow ToCreate a sitemap.xml
HOW TO

How to Create a sitemap.xml

Learn how to create and submit a sitemap.xml file — with the correct XML format, priority and changefreq tags, image sitemaps, and Search Console submission.

Updated 2026-06-26

Free calculators used in this guide

Sitemap.xml GeneratorSitemap Validator

A sitemap.xml file is the most direct way to tell search engines which pages on your site exist, which ones matter, and when they were last updated. Done right, it eliminates guesswork from Google's crawl discovery process. Done wrong — wrong format, wrong content, stale dates — it actively misleads crawlers and wastes crawl budget. This guide walks through creating a correct, production-ready sitemap from scratch.

Overview

The Sitemaps protocol was jointly developed by Google, Yahoo, and Microsoft in 2006 and is now maintained at sitemaps.org. It defines an XML format that any web crawler can consume to discover URLs and metadata about pages on a domain.

A sitemap is most valuable when you have pages that are poorly linked internally, a new site that search engines have not yet crawled thoroughly, or more than a few hundred pages that need consistent indexing. Use the Sitemap Generator to create a sitemap automatically, and the Sitemap Validator to check an existing one.

What You Need

  • A list of all the URLs you want indexed (your canonical, indexable pages only)
  • Last-modification dates for those pages (from your CMS or deployment system)
  • FTP/SFTP access or a deployment workflow to place the sitemap at your domain root
  • A Google Search Console account to submit and monitor the sitemap

Step 1: Understand the sitemap.xml Format

A sitemap is a valid XML file using the http://www.sitemaps.org/schemas/sitemap/0.9 namespace. The structure is:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://example.com/</loc>
    <lastmod>2026-06-26</lastmod>
    <changefreq>monthly</changefreq>
    <priority>1.0</priority>
  </url>
</urlset>

The four URL-level tags:

Tag Required Description
<loc> Yes The full URL, including https:// and trailing slash if used
<lastmod> No Date page was last modified (W3C Datetime: YYYY-MM-DD)
<changefreq> No Hint for crawl frequency (Google largely ignores this)
<priority> No Relative priority 0.0–1.0 (Google largely ignores this)

Critical rules:

  • All URLs must begin with the protocol (https:// or http://)
  • URLs must be consistently formatted — if your site uses trailing slashes, every <loc> must have one
  • The <loc> URL must match the canonical version of the page exactly
  • Special characters in URLs must be XML-escaped: &&amp;, <&lt;, >&gt;, "&quot;, '&apos;

Step 2: Choose a Generation Method

For most sites, do not write sitemaps by hand. The exception is a very small site (under 20 pages) where manual maintenance is feasible.

Framework or CMS plugins (recommended):

  • WordPress: Yoast SEO or Rank Math automatically generate and update sitemaps at /sitemap_index.xml
  • Next.js: next-sitemap npm package generates static sitemaps during build; Next.js 13.3+ has built-in sitemap support via app/sitemap.ts
  • Shopify: auto-generates at /sitemap.xml — no configuration needed
  • Hugo: built-in sitemap generation with the --theme flag

Online generators: Use the Sitemap Generator for small to medium static sites — enter your domain, crawl depth, and any URL patterns to exclude.

Dynamic server-side generation: For large sites or sites where content changes frequently, generate sitemaps programmatically — either on every request (with caching) or as a build step that runs on content publish. Dynamic generation ensures <lastmod> dates are always accurate.

Manual creation: Appropriate only for sites under 20 pages. Create a text file, save it as sitemap.xml, and edit it each time pages are added or changed.

Step 3: Write the XML Structure

A complete sitemap example with multiple URL types and all optional tags:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

  <!-- Homepage — highest priority -->
  <url>
    <loc>https://example.com/</loc>
    <lastmod>2026-06-26</lastmod>
    <changefreq>weekly</changefreq>
    <priority>1.0</priority>
  </url>

  <!-- Main product page -->
  <url>
    <loc>https://example.com/products/</loc>
    <lastmod>2026-06-20</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.9</priority>
  </url>

  <!-- Individual product -->
  <url>
    <loc>https://example.com/products/widget-pro/</loc>
    <lastmod>2026-05-15</lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.8</priority>
  </url>

  <!-- Blog post -->
  <url>
    <loc>https://example.com/blog/getting-started-guide/</loc>
    <lastmod>2026-04-10</lastmod>
    <changefreq>yearly</changefreq>
    <priority>0.6</priority>
  </url>

  <!-- Contact page — lower priority, rarely changes -->
  <url>
    <loc>https://example.com/contact/</loc>
    <lastmod>2025-11-01</lastmod>
    <changefreq>yearly</changefreq>
    <priority>0.3</priority>
  </url>

</urlset>

Priority guidelines (these are relative signals within your own site, not comparisons to other sites):

  • 1.0 — Homepage, most important category pages
  • 0.8–0.9 — Core content pages, important product pages
  • 0.6–0.7 — Blog posts, articles, individual product pages
  • 0.3–0.5 — Tag pages, author pages, less important static pages
  • 0.0–0.2 — Rarely-updated utility pages (about, legal, contact)

Step 4: Add Image and Video Sitemaps

For media-heavy sites, extend your sitemap with image or video metadata so search engines can index your media content.

Image sitemap extension:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
  <url>
    <loc>https://example.com/gallery/mountain-collection/</loc>
    <image:image>
      <image:loc>https://example.com/images/mountain-peak.jpg</image:loc>
      <image:title>Snow-capped Mountain Peak at Sunrise</image:title>
      <image:caption>Photograph taken at 4,200m altitude in the Himalayas</image:caption>
    </image:image>
    <image:image>
      <image:loc>https://example.com/images/valley-view.jpg</image:loc>
      <image:title>Valley View from Base Camp</image:title>
    </image:image>
  </url>
</urlset>

Video sitemap extension:

<?xml version="1.0" encoding="UTF-8"?>
<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/tutorials/calculator-guide/</loc>
    <video:video>
      <video:thumbnail_loc>https://example.com/thumbs/calc-guide.jpg</video:thumbnail_loc>
      <video:title>How to Use the SIP Calculator</video:title>
      <video:description>Step-by-step walkthrough of calculating SIP returns over 20 years.</video:description>
      <video:content_loc>https://example.com/videos/calc-guide.mp4</video:content_loc>
      <video:duration>312</video:duration>
    </video:video>
  </url>
</urlset>

Sitemap index for large sites (50,000+ URLs):

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>https://example.com/sitemap-pages.xml</loc>
    <lastmod>2026-06-26</lastmod>
  </sitemap>
  <sitemap>
    <loc>https://example.com/sitemap-products.xml</loc>
    <lastmod>2026-06-25</lastmod>
  </sitemap>
  <sitemap>
    <loc>https://example.com/sitemap-blog.xml</loc>
    <lastmod>2026-06-26</lastmod>
  </sitemap>
</sitemapindex>

Submit the sitemap index URL to Search Console — Google will discover and process all the referenced sitemaps automatically.

Step 5: Submit to Google Search Console and Bing Webmaster Tools

Google Search Console:

  1. Go to Google Search Console and select your property
  2. Navigate to Indexing → Sitemaps in the left menu
  3. In the "Add a new sitemap" field, enter your sitemap path (e.g., sitemap.xml)
  4. Click Submit
  5. The status column will show: Pending → Success (with URL count) or Has errors (with details)

Bing Webmaster Tools:

  1. Log into Bing Webmaster Tools
  2. Select your site and go to Sitemaps
  3. Click Submit sitemap and enter the full sitemap URL
  4. Bing processes the submission within 24–48 hours

Add Sitemap directive to robots.txt:

Sitemap: https://example.com/sitemap.xml

This passively notifies any crawler that discovers your robots.txt file about your sitemap — no manual submission required for them.

Common Mistakes to Avoid

Wrong Content-Type header: Your sitemap must be served with Content-Type: application/xml or Content-Type: text/xml. Servers that serve XML files as text/plain or application/octet-stream will cause parsing failures in some crawlers. Check with curl -I https://example.com/sitemap.xml and inspect the Content-Type header.

Incorrect date format for <lastmod>: The Sitemaps protocol requires W3C Datetime format — YYYY-MM-DD or YYYY-MM-DDThh:mm:ssZ. Common wrong formats: 26/06/2026, June 26 2026, Unix timestamps (1751000000). These cause validation failures. Google also recommends only updating <lastmod> when content genuinely changes — updating it artificially on every crawl trains Google to ignore it entirely.

Including noindex pages in your sitemap: Pages with <meta name="robots" content="noindex"> or a noindex response header should not appear in your sitemap. Including them sends contradictory signals. Audit your sitemap against your noindex pages before submitting.

Incorrect URL format (missing protocol, inconsistent trailing slashes): Every <loc> must be the full canonical URL including https://. If your site uses trailing slashes (https://example.com/about/), every sitemap entry must include them. If you use no trailing slashes (https://example.com/about), be consistent. Mixing these within a sitemap can cause Google to treat the same page as two different URLs.

Not updating sitemap after publishing new content: A sitemap submitted once and never updated is progressively less useful. New pages not in the sitemap rely on link discovery alone. Automate sitemap regeneration as part of your content publish workflow, or schedule regular regeneration if automation is not feasible.

Formula & Methodology

The Sitemaps protocol is defined at sitemaps.org and built on standard XML. The complete formal structure:

sitemap.xml
├── XML declaration: <?xml version="1.0" encoding="UTF-8"?>
├── Root element: <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
│   └── For each URL: <url>
│       ├── <loc>       Required. Full URL. Max 2,048 characters.
│       ├── <lastmod>   Optional. W3C Datetime.
│       ├── <changefreq> Optional. always|hourly|daily|weekly|monthly|yearly|never
│       └── <priority>  Optional. 0.0 to 1.0 (default: 0.5)

File size constraints:

  • Maximum 50,000 URLs per sitemap file
  • Maximum 50MB per sitemap file (uncompressed)
  • Gzip compression is accepted and recommended — a 50MB sitemap compresses to roughly 5–10MB
  • Sitemap index files follow the same limits: max 50,000 sitemap references, max 50MB

Crawl budget implications: A clean sitemap with accurate <lastmod> dates helps Google allocate crawl budget efficiently — pages with recent <lastmod> dates receive crawl priority. Pages excluded from the sitemap are crawled based on link signals alone. For sites over 10,000 pages, carefully curating what appears in the sitemap (excluding low-value pages, near-duplicates, and thin content) can meaningfully improve how quickly new and updated content gets indexed.

Use the Sitemap Validator to verify your sitemap against the protocol spec before submission.

Frequently Asked Questions

A sitemap.xml is an XML file that lists the URLs on your website along with optional metadata about each page — when it was last updated, how often it changes, and its relative priority. Search engines like Google and Bing use sitemaps to discover and crawl pages more efficiently, particularly pages that may not be well-linked from elsewhere on the site. While Google can find your pages without a sitemap through link discovery, a sitemap guarantees that important pages are submitted for crawling — especially on new sites, large sites, or sites with pages that are not heavily interlinked.
A single sitemap file can contain a maximum of 50,000 URLs and must not exceed 50MB when uncompressed. These are the limits defined by the Sitemaps protocol at sitemaps.org. If your site has more than 50,000 URLs, you need to split your content across multiple sitemap files and create a sitemap index file that lists all of them. The sitemap index file itself can reference up to 50,000 individual sitemap files, allowing a maximum of 2.5 billion URLs per index — well above any realistic website size.
Only the <loc> tag (the URL) is required within each <url> entry. The <lastmod>, <changefreq>, and <priority> tags are all optional. The enclosing <urlset> root element is required, and each URL must be wrapped in a <url> element. The XML declaration at the top (<?xml version='1.0' encoding='UTF-8'?>) and the XML namespace on <urlset> are required for the file to validate correctly. In practice, Google has stated publicly that it largely ignores <changefreq> and <priority> values when deciding crawl behaviour.
The <lastmod> value must follow W3C Datetime format as specified in the Sitemaps protocol. The accepted formats are: YYYY-MM-DD (e.g., 2026-06-26), YYYY-MM-DDThh:mm:ss+00:00, or YYYY-MM-DDThh:mm:ssZ (both include time and timezone). The most common format used in static sitemaps is YYYY-MM-DD. Using incorrect date formats (like DD/MM/YYYY or Unix timestamps) will cause validation errors. Google recommends only updating <lastmod> when the page content actually changes — artificially updating it on every crawl trains Google to distrust it.
A sitemap index file is a special XML file that lists multiple sitemap files rather than individual URLs. You need one when your site exceeds 50,000 URLs (the per-sitemap limit), when you want to organise sitemaps by content type (posts, products, images, videos), or when your CMS generates separate sitemaps for different sections. The sitemap index file uses <sitemapindex> as the root element (instead of <urlset>) and contains <sitemap> entries each with a <loc> pointing to an individual sitemap file and an optional <lastmod>. The index file itself must also stay under 50MB and 50,000 entries.
No. Including a noindex page in your sitemap sends a contradictory signal to Google — you are simultaneously asking it to index the page (by including it in the sitemap) and not to index it (via the noindex tag). Google's guidelines explicitly state that you should not include pages marked noindex in your sitemap. Similarly, exclude pages that redirect (301 or 302), pages blocked by robots.txt, error pages (404, 500), duplicate pages (canonicalise instead), and session-ID or filter URLs that produce near-duplicate content.
Log into Google Search Console, select your property, and navigate to Indexing → Sitemaps in the left sidebar. Enter the URL of your sitemap (e.g., https://example.com/sitemap.xml) and click Submit. Google will attempt to fetch and parse the sitemap and show you the status (Success, Has errors, etc.) and how many URLs were discovered. Resubmit whenever you make significant changes to your sitemap — though Google also recrawls sitemaps periodically. Also add a Sitemap: directive to your robots.txt file for passive discovery by all crawlers.
The <priority> tag (values 0.0 to 1.0) and <changefreq> tag (always, hourly, daily, weekly, monthly, yearly, never) were originally intended to signal crawl priority and frequency to search engines. In practice, Google has publicly stated that it largely ignores both fields when making crawl decisions — it uses its own signals to determine how often to crawl and which pages to prioritise. Bing also gives them minimal weight. You can include them for completeness, but do not rely on them to influence crawl behaviour. The <loc> and <lastmod> tags are far more impactful.
Yes. The Sitemaps protocol includes extensions for images and videos. For images, add an <image:image> element inside each <url> entry containing <image:loc> (the image URL) and optionally <image:title>, <image:caption>, and <image:geo_location>. For videos, use <video:video> with <video:thumbnail_loc>, <video:title>, <video:description>, and <video:content_loc>. These extensions help search engines discover media that may not be crawlable through HTML links alone, and are particularly valuable for image-heavy sites like portfolios, e-commerce, and news publishers. Use the correct XML namespace declarations for each extension.
For small, well-linked sites with fewer than 500 pages, a sitemap is less critical but still recommended as a best practice — it takes minutes to generate and provides a clear record of which URLs you consider canonical and indexable. Sitemaps become significantly more impactful as site size grows, when pages have few internal links pointing to them, when you publish new content frequently (news, blog), or when you have recently launched and are not yet well-indexed. There is no downside to having a valid sitemap, and Google recommends it for all sites regardless of size.
Your sitemap.xml should be served with a Content-Type header of application/xml or text/xml. Most web servers automatically assign the correct MIME type for .xml files, but misconfigured servers sometimes serve them as text/plain or application/octet-stream, which causes parsing failures in some crawlers. If you are generating your sitemap dynamically (e.g., a server-side script), explicitly set the Content-Type header in your response. You can verify the header using browser developer tools (Network tab → select the sitemap request → check Response Headers) or a tool like curl -I https://example.com/sitemap.xml.
Update your sitemap whenever the content of your site changes — new pages added, pages removed, or significant content changes that update the <lastmod> date. For high-frequency publishers (daily blog posts, news sites), sitemaps should update automatically on each new publication, ideally triggered by the CMS. For mostly static sites, manual or scheduled weekly regeneration is sufficient. Resubmit to Google Search Console after major changes; for routine updates, adding the Sitemap: directive to robots.txt means Google picks up changes during its regular robots.txt crawl without manual resubmission.

Related Articles

GUIDE

SEO Technical Checklist — robots.txt, Sitemap & Meta Tags

HOW TO

How to Generate a UUID

HOW TO

How to Use Cron Expressions

HOW TO

How to Write a robots.txt File

COMPARISON

Regex vs String Methods — When to Use Which