Deutsch
URLs & domains

Fragment identifier

Also known as: URL fragment, hash, anchor

A fragment identifier is the last part of a URL, starting with the # character. It points to a specific part of a resource, such as a section of a page or a position in a video.

How does a fragment work?

The browser processes the fragment after it has loaded the resource. The fragment is never sent to the server (MDN). Common uses are:

  • Scroll to an element. #syntax scrolls to the element with id="syntax".
  • Text fragments. #:~:text=word highlights a piece of text.
  • Media fragments. #t=10,20 plays audio or video from second 10 to 20.

RFC 3986 defines the fragment as an indirect reference to a secondary resource, with semantics set by the media type of the retrieved content. When URIs are compared, fragments are left out, since they reference content within one resource.

Anatomy of a URLThe example URL https://shop.example.de/shoes/sneakers/?color=red&page=2#reviews broken into parts: scheme https, host shop.example.de with subdomain shop, domain example.de and top-level domain de, path /shoes/sneakers/ with a trailing slash, query string with two parameters color=red and page=2, fragment reviews. The fragment is not sent to the server.Trailing slashhttps://shop.example.de/shoes/sneakers/?color=red&page=2#reviewsSchemeHostPathQuery stringFragmentSubdomainDomainParameterParameterTLDcountry code: ccTLDstays in the browser, is notsent to the serverSchematic. Scheme, host, path, query and fragment are components defined in RFC 3986.Subdomain, domain and TLD split the host by DNS level. Without a port, https uses port 443.
A URL broken into its parts. RFC 3986 defines scheme, host, path, query and fragment. Only the browser evaluates the fragment after #, it is not sent to the server. Sources: RFC 3986: Uniform Resource Identifier (URI), Generic Syntax; MDN: What is a URL?; MDN Glossary: TLD.

What does Google say about fragments?

Google states that its Search generally does not support URL fragments. It advises against using fragments to change the content of a page and against using fragment identifiers for page numbers in a collection, because Google ignores them. For JavaScript apps, Google points to the History API as the way to give each view its own URL.

For filters on large catalogs, Google’s faceted navigation page lists fragments as one option for keeping filter URLs out of the crawl, since the fragment does not create a new URL for crawling.

Example

Text
https://example.com/guide?lang=en#faq

Here ?lang=en is the query string. #faq scrolls to the element with the ID faq.

Sources

  1. URI fragment – MDN Web Docsdeveloper.mozilla.org
  2. RFC 3986, section 3.5 Fragment – IETFrfc-editor.org
  3. URL structure best practices for Google Search – Google Search Centraldevelopers.google.com
  4. Pagination and incremental page loading – Google Search Centraldevelopers.google.com

Last updated: