What is sitemap.xml?
A sitemap.xml file is a file that lists all the pages and content on a website that a search engine may need to know about. It is used by search engines like Google, Bing, Yahoo, and others to crawl and index a website’s content. A sitemap.xml file typically includes information such as the URLs of each page, the date it was last modified, how frequently it is updated, and the page’s importance with the other pages on the website. By providing this information to search engines, website owners can help ensure their website’s content is indexed and displayed in search results.
Important elements of XML sitemap
There are 6 important elements of XML sitemap while creating sitemap.xml text file are :
- urlset: This is the root element of the sitemap file that defines the XML namespace and version.
- url: This element represents a single URL on the website that should be indexed by the search engines. Each URL should be enclosed within the urlset element.
- loc: This element represents the URL of the page that is being referenced.
- lastmod: This element represents the date and time that the URL was last modified.
- changefreq: This element represents how frequently the URL is likely to change. It can have values such as “always”, “hourly”, “daily”, “weekly”, “monthly”, “yearly”, and “never”.
- priority: This element represents the importance of the URL relative to other URLs on the site. It can have values between 0.0 and 1.0.
There are 3 types of XML sitemaps can be combined to create a sitemap.xml file for a small website that provides search engines with important information about the pages on a website. For a large or complex website, it is recommended to create image sitemap, video sitemap, or news sitemap separately.
XML Header – Optional
<?xml version="1.0" encoding="UTF-8"?>
First elements of XML sitemap. XML declaration that appears at the beginning of an XML document. It indicates that the document is an XML file and specifies the version of the XML specification used (in this case, version 1.0) and the character encoding used to represent the text (in this case, UTF-8).
The XML declaration is not strictly necessary, but it is recommended as it helps ensure that the XML document is correctly interpreted by search engine bots that read it. Usually, it instructs search engine spiders what they can get from the sitemap.xml file.
urlset – Required
Another mandatory tag among the elements of sitemap.xml. The urlset tells which version of the XML sitemap standard is used, supported by Google, Yahoo, Microsoft and other search engine algorithms.
urlset is an XML element used in the XML Sitemap format to group a set of url elements. The urlset element is the top-level element in an XML Sitemap file and contains information about the urls used in the file.
Each url element within the urlset represents a specific page on the website for which the Sitemap is being created. The url element can include additional information about the page, such as the last modified date, the page’s priority relative to other pages on the site, and how frequently the page is expected to change.
url – Required
<url> <loc> https://www.example.com/webpage1/ </loc> <lastmod> 2017-10-10 </lastmod> <changefreq> weekly </changefreq> <priority> 0.8 </priority> </url>
<url> tag represents a URL on the website for which the sitemap is being created. Each <url> tag provides information about a specific page on the website and helps search engines understand the structure and content of the website. <url> tag includes many other elements of XML sitemap.
The sitemap.xml file can contain multiple <url> tags, each <url> tag representing a unique URL on the website. By including all the website’s important pages in the sitemap, search engines can better understand the website’s structure and index it more efficiently.
xhtml:link – Optional
In a sitemap, the <xhtml:link> tag is used to specify alternative versions of the same page, such as a mobile version or a version in a different language.
Here’s an example of how you might use the <xhtml:link> tag in a sitemap to specify a mobile version of a page:
<url> <loc>http://www.example.com/page1.html</loc> <xhtml:link rel="alternate" media="only screen and (max-width: 640px)" href="http://m.example.com/page1.html"/> </url>
In this example, the <url> tag specifies the URL of the page, and the <xhtml:link> tag defines the URL of the mobile version of the page, with the rel=”alternate” attribute indicating that this is an alternate version of the current page, and media=”only screen and (max-width: 640px)” indicating that this version is intended for mobile devices with a maximum screen width of 640 pixels.
Note that the <xhtml:link> tag should be used within the <url> tag to specify the alternate version(s) of the page.
loc – Required
<url> <loc>https://www.example.com/page1.html</loc> </url>
The <loc> tag specifies the URL of a page on the website where the sitemap is being created. The <loc> tag is used within the <url> tag to provide information about a specific page on the website.
<loc> tag within the <url> tag specifies the URL of the page on the website that this <url> tag represents. The URL must be fully qualified, including the protocol (e.g. “https://”), domain name, and path to the page.
The <loc> tag is a required element within the <url> tag, as it provides the essential information for search engines to understand the website’s structure and crawl its pages.
lastmod – Optional
<url> <loc>https://www.example.com/page1.html</loc> <lastmod>2022-03-01</lastmod> </url>
<lastmod> tag is used to specify the date when a page on the website was last modified. The <lastmod> tag is used within the <url> tag to provide information about a specific page on the website.
The <lastmod> tag is an optional element within the <url> tag, as not all pages on a website may have a last modified date that needs to be specified. However, including the <lastmod> tag for important pages on the website can help search engines understand how frequently the website is being updated and prioritize the crawling and indexing of the most recently modified pages.
A sitemap.xml file can contain multiple <url> tags, each with its own <lastmod> tag indicating the last modified date of the corresponding page on the website.
changefreq – Optional
<url> <loc> https://www.example.com/webpage1/ </loc> <changefreq> weekly </changefreq> </url>
The <changefreq> tag in a sitemap.xml file indicates how frequently a web page will likely change. This information can help search engine crawlers determine how often they should revisit a page to ensure that their index is up to date.
The <changefreq> tag accepts a limited set of values, including always, hourly, daily, weekly, monthly, yearly, and never.
The <changefreq> tag is typically used with the <lastmod> tag, which indicates the date when the page was last modified. Together, these tags provide important information to search engines about the frequency and timing of updates to a website’s content.
priority – Optional
<url> <loc> https://www.example.com/webpage1/ </loc> <priority> 0.8 </priority> </url>
The <priority> tag in a sitemap.xml file indicates the relative priority of a particular web page on a website. This information can help search engines understand which pages are most important or relevant to a user’s search query.
The <priority> tag accepts a value between 0.0 and 1.0, with 1.0 indicating the highest priority.
Benefits Of Using XML Sitemap Elements
Using sitemap.xml elements can have several benefits for website owners, such as:
- Improved crawlability: By providing a sitemap.xml file to search engines, website owners can ensure that all of their website’s pages are discovered and crawled by search engine bots. This can help to improve the overall visibility of the website in search engine results.
- Better indexing: Sitemap.xml files can provide search engines with important information about the content on a website, such as how frequently pages are updated and their relative importance. This can help search engines to more effectively index and rank the pages on the site.
- Faster indexing: Sitemap.xml files can help search engines to quickly find new pages or changes to existing pages on a website, which can lead to faster indexing of the website’s content.
- Improved user experience: Sitemap.xml files can also be used to help users navigate a website more easily by providing a clear structure of the website’s content and organization.
Overall, using sitemap.xml elements can be an effective way for website owners to improve the visibility, indexing, and user experience of their website in search engine results.