London Web Factory

SEO Best Practices for Creating XML Sitemaps

An XML sitemap helps search engines discover, crawl and index your website. But a good sitemap should do more than simply list every URL found. Images, videos, redirects, duplicate and non-indexable pages must be handled correctly, while larger sites need careful sitemap structure. This guide explains best practices for creating accurate, search-engine-friendly XML sitemaps.

What Is an XML Sitemap?

A standard XML sitemap contains the URLs of pages that you would like search engines to crawl and index.

At its simplest, it looks like this:

<?xml version="1.0" encoding="UTF-8"?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

    <url>
        <loc>https://example.com/</loc>
    </url>

    <url>
        <loc>https://example.com/services/</loc>
    </url>

    <url>
        <loc>https://example.com/contact/</loc>
    </url>

</urlset>

The <urlset> element contains the sitemap, each <url> represents an individual page, and <loc> specifies its absolute URL.

Only Include URLs You Want Search Engines to Index

One of the most important sitemap principles is that a sitemap should not simply be a list of everything found while crawling a website.

As a general rule, your XML sitemap should contain URLs that are:

  • Canonical
  • Indexable
  • Returning an HTTP 200 response
  • Useful pages that you actually want appearing in search results

This means URLs that redirect, return errors, contain a noindex directive or are duplicates with a different canonical URL should generally not be included.

Think of the sitemap as a clear signal to search engines:

These are the URLs on my website that I consider important and suitable for indexing.

Sending conflicting signals — such as placing a noindex URL in a sitemap — should be avoided.

Don't Treat Images as Normal Page URLs

A common mistake when automatically generating sitemaps from a website crawl is to treat every discovered URL in the same way.

For example:

<url>
    <loc>https://example.com/about/</loc>
</url>

<url>
    <loc>https://example.com/images/team.jpg</loc>
</url>

The image has been treated as though it were another HTML page.

Google supports a dedicated image sitemap extension which allows images to be associated with the page on which they appear.

A better structure is:

<url>
    <loc>https://example.com/about/</loc>

    <image:image>
        <image:loc>https://example.com/images/team.jpg</image:loc>
    </image:image>
</url>

The sitemap therefore describes the relationship:

/about/
    └── /images/team.jpg

rather than presenting both resources as equivalent pages.

Creating an Image Sitemap

To include image information, add Google's image sitemap namespace to the <urlset> element:

<urlset
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">

Images can then be associated with individual pages:

<url>
    <loc>https://example.com/about/</loc>

    <image:image>
        <image:loc>https://example.com/images/team.jpg</image:loc>
    </image:image>

    <image:image>
        <image:loc>https://example.com/images/office.jpg</image:loc>
    </image:image>
</url>

A page containing several important images can therefore have several <image:image> elements.

This gives search engines useful information about the relationship between the page and its images without filling the main sitemap with hundreds or thousands of image URLs masquerading as pages.

Be Careful With Responsive Image Variants

Modern content management systems frequently generate several versions of the same image.

WordPress, for example, might produce:

team.jpg
team-1280x720.jpg
team-980x551.jpg
team-480x270.jpg
team-300x169.jpg

These different files may subsequently be discovered through srcset, responsive layouts and other HTML.

Automatically placing every version into an image sitemap can create unnecessary duplication.

Where possible, a sitemap generator should identify the principal image rather than blindly treating every resized variant as a separate important image.

This is particularly important on large websites where a relatively modest number of original images can result in thousands of generated image files.

Videos Need Their Own Sitemap Information

Google also supports a video sitemap extension.

The namespace is:

xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"

Video information is associated with the page containing the video rather than simply adding the video file as another ordinary page.

For example:

<url>
    <loc>https://example.com/training/</loc>

    <video:video>
        <video:thumbnail_loc>
            https://example.com/images/training-video.jpg
        </video:thumbnail_loc>

        <video:title>
            Introduction to Our Training Course
        </video:title>

        <video:description>
            An introduction to our professional training course.
        </video:description>

        <video:content_loc>
            https://example.com/videos/training.mp4
        </video:content_loc>
    </video:video>
</url>

Video sitemap information can contain considerably more metadata than an image entry because search engines need enough information to understand and present the video appropriately.

Images and Videos Can Be Combined in One Sitemap

You don't necessarily need separate page, image and video sitemap files.

The extensions can be combined.

For example:

<?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"
    xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">

    <url>

        <loc>https://example.com/training/</loc>
        <lastmod>2026-09-11</lastmod>

        <image:image>
            <image:loc>
                https://example.com/images/training.jpg
            </image:loc>
        </image:image>

        <image:image>
            <image:loc>
                https://example.com/images/classroom.jpg
            </image:loc>
        </image:image>

        <video:video>
            <video:thumbnail_loc>
                https://example.com/images/training-video.jpg
            </video:thumbnail_loc>

            <video:title>
                Professional Training Course
            </video:title>

            <video:description>
                An introduction to our professional training course.
            </video:description>

            <video:content_loc>
                https://example.com/videos/training.mp4
            </video:content_loc>
        </video:video>

    </url>

</urlset>

This creates a much richer description of the page:

Page
 ├── URL
 ├── Last modified
 ├── Images
 │    ├── Image 1
 │    └── Image 2
 └── Video
      ├── Thumbnail
      ├── Title
      ├── Description
      └── Video URL

For many websites, this is a cleaner approach than maintaining completely independent sitemaps for each resource type.

Use <lastmod> When You Have Reliable Data

The optional <lastmod> element tells search engines when a page was last significantly modified.

For example:

<url>
    <loc>https://example.com/services/</loc>
    <lastmod>2026-09-10</lastmod>
</url>

It should represent a genuine significant modification to the page rather than simply the date on which the sitemap was generated.

If reliable modification information isn't available, it is better to omit <lastmod> than populate it with misleading dates.

What About <priority> and <changefreq>?

Older sitemap implementations frequently contain elements such as:

<changefreq>weekly</changefreq>
<priority>0.8</priority>

These should not be confused with instructions telling Google how frequently it must crawl a page or how highly it should rank it.

Modern sitemap generation should concentrate on accurate URLs and meaningful modification dates rather than attempting to assign arbitrary priorities to pages.

Don't Put Every Crawled Resource Into the Sitemap

A crawler may discover far more resources than should appear in a search-engine sitemap.

Depending on the purpose of the sitemap, resources that shouldn't normally be added as standard <url> entries include:

Images
CSS files
JavaScript files
Fonts
Video files
Redirecting URLs
404 URLs
Other error URLs
Noindex pages
Non-canonical duplicate URLs

PDFs and other documents need more consideration because they can themselves be indexable search results. Whether they belong in the sitemap should therefore depend upon the purpose of the sitemap and whether those documents are intentionally being promoted for indexing.

The crucial distinction is between URLs discovered by a crawler and URLs suitable for inclusion in an XML sitemap.

They are not necessarily the same thing.

Handle Canonical URLs Correctly

Suppose a crawler encounters:

https://example.com/product?id=123

but the page specifies:

<link rel="canonical" href="https://example.com/products/widget/">

Assuming that canonicalisation is intentional and valid, the sitemap should normally contain:

https://example.com/products/widget/

rather than the duplicate parameterised URL.

This helps ensure that your internal SEO signals are consistent.

Your canonical tags, internal links and XML sitemap should ideally all point search engines towards the same preferred URLs.

Use Sitemap Indexes for Large Websites

XML sitemaps have size limits. A single sitemap can contain a maximum of 50,000 URLs and must not exceed 50 MB when uncompressed.

Larger websites therefore need multiple sitemap files.

These can be organised using a sitemap index:

<?xml version="1.0" encoding="UTF-8"?>

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

    <sitemap>
        <loc>https://example.com/sitemap-1.xml</loc>
    </sitemap>

    <sitemap>
        <loc>https://example.com/sitemap-2.xml</loc>
    </sitemap>

    <sitemap>
        <loc>https://example.com/sitemap-3.xml</loc>
    </sitemap>

</sitemapindex>

This makes XML sitemaps practical even for websites containing hundreds of thousands or millions of indexable URLs.

Make Sure Your XML Is Valid

A sitemap is an XML document, so normal XML rules apply.

URLs and other values must be correctly escaped. For example, an ampersand within a URL must be represented appropriately:

<loc>https://example.com/products/?colour=blue&amp;size=large</loc>

Sitemaps should also use absolute rather than relative URLs.

Use:

https://example.com/services/

rather than:

/services/

Automatically generated sitemaps should ideally be validated before they are published.

A Sitemap Should Reflect Your SEO Strategy

Perhaps the most useful way to think about an XML sitemap is not as a list of everything on a website, but as a structured declaration of the content you want search engines to understand.

A good sitemap generator should therefore be selective.

For every crawled page, it should effectively ask:

Is this URL indexable?
Is it canonical?
Does it return 200?
Should it appear in search results?
Does it contain important images?
Does it contain video?
Do we have a reliable last-modified date?

Only then should the sitemap entry be constructed.

XML Sitemap Best Practice

For most websites, a good sitemap generation process can be summarised as:

Crawl → Analyse → Filter → Associate → Generate

First discover the website's resources. Analyse their indexability and canonicalisation. Filter out URLs that shouldn't be submitted. Associate images and videos with their parent pages. Finally, generate standards-compliant XML.

The resulting sitemap isn't simply an export of everything a crawler found.

It's a clean, structured representation of the website content that you actually want search engines to discover, understand and index.