How to Create XML Sitemap: Complete Guide 2026

Most guides make creating the XML file sound like the difficult part. It isn't. The difficult part is deciding which URLs deserve to be discovered, keeping those URLs canonical and live, and maintaining the file as the site changes. A perfectly formatted sitemap filled with redirects, duplicate URLs, or stale entries still gives search engines a poor indexation signal.

This guide treats an XML sitemap as a living indexation control. You'll learn how to create one for common platforms, understand the tags that matter, validate and submit the file, and diagnose the indexing problems a sitemap can't solve. The protocol itself has been stable for decades, with Google introducing Sitemaps 0.84 in June 2005 and Google, Yahoo, and Microsoft announcing joint support in November 2006, as documented in this history of XML sitemap best practices.

Why Your Sitemap Matters More Than the File Itself

Generating sitemap.xml is usually a routine task. The strategic question is different: which URLs should search engines treat as your preferred, indexable inventory? A sitemap gives crawlers a machine-readable list of URLs you want them to discover, crawl, and consider for indexing. It doesn't force indexing, override a noindex directive, or turn a weak page into a valuable result.

That distinction changes the workflow. Your sitemap should contain the canonical version of important pages, including revenue-generating service pages, useful location pages, editorial content, and eligible product URLs. It shouldn't become an export of every URL the CMS happens to generate. Parameter variations, internal search results, staging pages, thin archives, and confirmation pages generally don't belong in that inventory.

A sitemap also isn't a ranking factor by itself. It complements the signals that help search engines understand your site, especially internal links and canonical tags. A well-linked page can be discovered without a sitemap, while an isolated page may be discovered through one but still fail to earn a place in the index if its content, canonical status, or technical accessibility is poor.

Practical rule: Use the sitemap to declare your preferred URL set, not to compensate for weak navigation or unresolved duplicate content.

Discovery is only one part of the process

Search engines use links, feeds, redirects, and other signals to discover URLs. The sitemap adds a direct, structured source of discovery, which becomes especially useful for new sites, large catalogs, frequently updated content, and pages that aren't well connected through navigation. It helps search engines compare the URLs you submitted with what they encountered during crawling.

That comparison can expose operational problems. If important canonical pages are missing, the sitemap is incomplete. If the file contains many redirects or URLs from the wrong host, the sitemap is inaccurate. If submitted URLs remain excluded, the issue probably lies beyond sitemap syntax.

Before publishing, pair sitemap review with a broader checklist for spotting SEO issues. Site structure deserves equal attention, because your sitemap should reinforce a logical hierarchy rather than act as the only route to important pages. Review site structure for SEO alongside the submitted URL set, internal links, and canonical declarations.

Anatomy of an XML Sitemap File

An XML sitemap is a text file with a defined structure. Open one in a browser and you'll usually see an XML declaration followed by a root element, then a series of URL records. You don't need to be a developer to inspect it, but you do need to recognize which parts identify the file, the page, and optional freshness information.

A diagram illustrating the hierarchical structure of an XML sitemap file with definitions for each tag.

The page-level structure

The root element is <urlset>. It tells a parser that the file contains URL entries and identifies the sitemap protocol namespace. Each page then sits inside its own <url> element.

The most important child is <loc>. It holds the absolute URL you want search engines to discover, including the protocol and host. For a small five-page business site, the entries might represent the homepage, services page, about page, contact page, and one location page.

<lastmod> is optional and should describe the last meaningful content update. A template rebuild, tracking change, or automatic timestamp refresh isn't a meaningful editorial update. If your platform can't maintain this value accurately, leaving it out is safer than publishing dates that don't reflect reality.

The protocol also supports <changefreq> and <priority>. They may appear in older files, but Google ignores both, so they shouldn't receive maintenance effort. The practical value of the file comes from accurate URLs and honest freshness information, not decorative metadata.

The sitemap index pattern

A sitemap index is a wrapper for multiple sitemap files. Instead of placing page entries directly inside <urlset>, it uses <sitemapindex>, with each <sitemap> element pointing to another sitemap through <loc>. You might separate products, blog posts, pages, or regional inventories to make ownership and monitoring clearer.

The index doesn't replace the individual files. It connects them. Submit the index when your platform generates multiple child sitemaps, then inspect each child file when diagnosing coverage or validation issues.

For a more accessible explanation of the creation process, this guide to create sitemap for business is useful for owners who want to understand the file before handing it to a developer.

Creating a Sitemap for Your Platform

A sitemap is not a file you generate once and forget. Its value depends on whether the URLs still match your canonical indexation plan, remain accessible, and belong to the correct host. Before creating anything, check whether your platform already publishes a sitemap or sitemap index. A second file can create confusion without improving discovery.

Open the likely sitemap location on your domain and review the URLs it contains. Common outputs include a single sitemap.xml, a platform-generated sitemap, or an index that points to several child files. Compare that inventory with your canonical URL list before submitting a new file. Pay close attention to protocol, hostname, trailing-slash rules, redirects, and non-canonical variants. A technically valid sitemap can still send weak signals if it lists the wrong versions.

Static sites and custom applications

Manual creation works for a small, stable site. Create sitemap.xml, declare UTF-8 encoding, add the sitemap namespace, include one <url> element for each canonical page, and upload the file at a publicly accessible location. Use absolute URLs and escape special characters correctly.

A growing site should generate the file during its build process. A script can read an approved route inventory, exclude private and non-indexable paths, and write a fresh XML file with each deployment. An open-source generator may also be suitable, but inspect its output before publishing it. Automated discovery can collect parameter combinations, alternate routes, preview pages, or application paths that should not enter the indexation inventory.

Keep an authoritative source list of canonical routes. Do not convert every technically reachable route into a sitemap entry, especially when JavaScript creates filtered states, query parameters, or duplicate paths. The sitemap should reflect the URLs you want indexed, not every URL the application can produce.

CMS sites

CMS sites often provide a native sitemap feature or allow a popular SEO plugin to generate sitemap files or an index. These systems can exclude selected content types and update entries as content changes. Automation saves maintenance time, but it does not decide whether every archive, author page, taxonomy, or media URL deserves inclusion.

Review the rendered output after changing content settings. Remove low-value sections through the platform controls, then confirm that the remaining entries use canonical URLs and the intended host. If the CMS exposes an index instead of a single file, inspect its child sitemaps as well. A generator can keep XML current while preserving a poor indexation choice.

Commerce stores

Commerce platforms commonly generate a sitemap automatically from products, collections, pages, and blog content. Review the result instead of assuming that every commercially useful URL appears exactly as intended.

Give special attention to product variants, filtered collection states, discontinued items, and platform-controlled URL behavior. Do not add alternate parameter URLs just because they exist. If a required page or content type is missing from the native output, fix the underlying configuration or use an approved extension approach. A hand-edited file is fragile when automation will overwrite it.

For broader technical review, the Sibley Digital technical SEO resource provides useful context for treating sitemap work as part of crawlability and site-quality operations.

Platform type Recommended method Typical output URL Notes
Static site Build-time script or controlled manual file /sitemap.xml Maintain an approved canonical route inventory
CMS Native feature or SEO plugin /sitemap.xml or an index path Review content types, archives, and exclusions
Commerce platform Native automated generation /sitemap.xml Audit products, collections, pages, blogs, and variants
Custom application Build or deployment generation /sitemap.xml or an application route Exclude non-indexable paths and tie output to canonical URLs

Validating and Submitting Your Sitemap

A generated sitemap is only a draft until it passes two checks: crawlers can fetch it, and its URL set contains pages worth processing. Treat it as a living indexation control. Revalidate it after releases, URL changes, migrations, and content removals, because automation can keep publishing redirects, non-canonical URLs, or stale entries.

Validate the file and its URL set

Open the sitemap URL in a browser or request it directly. Confirm that the response is the expected XML, not an HTML error page, login screen, redirect, or blocked response. If it is an index, inspect each child sitemap too.

Run the XML through a validator or crawling application, then review the inventory separately. Check for:

  • Parse errors: Elements must open and close correctly.
  • Escaped characters: Special characters in URLs need valid XML escaping.
  • Reachable locations: Each <loc> should resolve to the intended page.
  • Indexation suitability: Remove URLs that redirect, return errors, are retired, or are intentionally excluded from search.
  • Host consistency: A migration or staging hostname can slip into automated output. Confirm that every entry belongs to the property being submitted and matches the site's current URL setup.
  • Fresh metadata: Keep <lastmod> only when the date reflects a meaningful content or page change.

A browser view confirms that the file opens. It does not confirm that the listed pages are useful indexation candidates. A technical SEO overview provides broader context for checking the crawl and indexation systems around the file.

Submit through search tools

In Google Search Console, select the verified property, open Sitemaps, enter the sitemap path, and select Submit. Submit the index when one exists. Use the processing report to find fetch failures and review whether the submitted URL set is producing the expected indexing signals. Acceptance of the file does not guarantee that every URL will be indexed.

Use the equivalent sitemap submission area in Bing Webmaster Tools. You can also reference the file in robots.txt with a line such as Sitemap: https://example.com/sitemap.xml. Use a fully qualified URL, and ensure that robots.txt is publicly reachable.

Submit the sitemap URL, then inspect the URL set. A successful submission means the file was accepted for processing, not that every listed page earned indexation.

After a major structural change, a large content release, or a substantial cleanup, resubmit the same sitemap location. Keep monitoring the output afterward, because the next automated build can reintroduce URLs you removed manually.

Sitemap Limits and the Tags Google Actually Uses

Sitemap architecture has hard protocol limits and softer conventions. Confusing them leads teams to spend time adjusting tags that Google doesn't use while overlooking file size, encoding, or URL quality.

A single sitemap file can contain 50,000 URLs and can be 50 MB when uncompressed, according to Google's sitemap construction documentation. The file must use UTF-8 encoding, and each URL must be written as an absolute path. If the file exceeds either limit, split the URL inventory and connect the child files with a sitemap index.

An infographic showing Google sitemap limits including 50,000 URL cap and 50MB maximum file size.

Separate required signals from ignored ones

<loc> is the core field because it identifies the URL. <lastmod> can help communicate meaningful change, but only when the value is accurate and maintained consistently. A date that changes every time a template renders doesn't tell a crawler that the content itself changed.

Google's guidance ignores <changefreq> and <priority>, so removing them often simplifies maintenance without losing a useful Google signal. Don't rank your URLs inside the sitemap by assigning arbitrary priority values. Use internal links, page architecture, content quality, and canonical signals for that work.

The practical hierarchy looks like this:

  • Required structure: Valid XML, the correct namespace, and a functioning URL set.
  • URL quality: Canonical, indexable pages that resolve correctly.
  • Freshness: Honest <lastmod> values tied to substantive changes.
  • Scale management: Multiple child sitemaps and an index when the limits require them.
  • Compression: Gzip can reduce transfer size, but the uncompressed limit still governs the protocol threshold.

A sitemap index can organize a large inventory by content type or business unit even before one file reaches its limit. That makes monitoring clearer, but segmentation doesn't excuse duplicate, redirected, or non-canonical entries.

Troubleshooting the Indexing Problems Sitemaps Cannot Fix

The most damaging sitemap failures often aren't XML failures. A file can parse perfectly while listing URLs that Google shouldn't index, can't reach, or doesn't consider the preferred version.

A list of five common indexing problems that cannot be resolved solely by submitting an XML sitemap.

Audit the submitted URL set

Start with canonicalization. Remove parameter variants, session URLs, internal search results, tag pages with no standalone value, and duplicate host or protocol versions. The sitemap should reinforce the canonical tag and redirect strategy, not contradict them.

Then check response behavior. A URL that returns a redirect shouldn't remain in the sitemap after the destination is known. Remove 404s, soft 404s, server-error URLs, and pages that return an empty or misleading response. A sitemap can tell Google a URL exists, but it can't repair the destination.

Host mismatches create a quieter problem. If the site consistently uses one host but the sitemap lists another, search engines must reconcile conflicting signals. Standardize the protocol, hostname, trailing-slash convention, and canonical declarations before regenerating the file.

Treat freshness as a trust signal

Stale <lastmod> values make the sitemap less useful as a change signal. Update the field when the page's meaningful content changes, not when a deployment touches unrelated code. If a CMS rewrites every date automatically, disable that behavior or omit <lastmod> until you can make it reliable.

Use Search Console to compare submitted URLs with indexing and coverage results. A gap doesn't automatically identify one cause, but it tells you where to investigate. Check page-level canonical selection, indexing directives, internal links, content quality, and server accessibility rather than resubmitting the same flawed file repeatedly.

A sitemap is an invitation to crawl, not an indexing command.

This is also why fixing broken links belongs in the same technical review. Broken internal paths can isolate important pages, while a sitemap may list those pages without providing the contextual links that help crawlers and users reach them.

For a visual audit reminder, review the common failure pattern below.

A durable sitemap process has a simple rhythm: generate from a trusted URL inventory, validate the rendered file, submit it, inspect coverage, and update the inventory whenever the site changes. MD TECH TEAM helps businesses connect sitemap setup with responsive web development, technical SEO, hosting, security monitoring, and ongoing website optimization. Visit MD TECH TEAM to discuss a sitemap and indexation workflow built around your actual CMS, site structure, and business goals.

Share the Post:

Related Posts