Fragment identifier
Encyclopedia
In computer hypertext
, a fragment identifier is a short string of character
s that refers to a resource
that is subordinate to another, primary resource. The primary resource is identified by a Uniform Resource Identifier
(URI), and the fragment identifier points to the subordinate resource.
The fragment identifier introduced by a hash mark
for a document. It is typically used to identify a portion of that document. The generic syntax is specified in RFC 3986. The hash mark
separator in URIs does not belong to the fragment identifier.
type and are evaluated by the client (Web browser
). Clients are not supposed to send URI-fragments to servers when they retrieve a document, and without help from a local application (see below) fragments do not participate in HTTP
redirections.
An URI ending with
The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side
with no participation from the server
— of course the server typically helps to determine the MIME type, and the MIME type determines the processing of fragments. When an agent
(such as a Web browser) requests a resource
from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the document type and fragment value.
Hypertext
Hypertext is text displayed on a computer or other electronic device with references to other text that the reader can immediately access, usually by a mouse click or keypress sequence. Apart from running text, hypertext may contain tables, images and other presentational devices. Hypertext is the...
, a fragment identifier is a short string of character
Character (computing)
In computer and machine-based telecommunications terminology, a character is a unit of information that roughly corresponds to a grapheme, grapheme-like unit, or symbol, such as in an alphabet or syllabary in the written form of a natural language....
s that refers to a resource
Resource (computer science)
A resource, or system resource, is any physical or virtual component of limited availability within a computer system. Every device connected to a computer system is a resource. Every internal system component is a resource...
that is subordinate to another, primary resource. The primary resource is identified by a Uniform Resource Identifier
Uniform Resource Identifier
In computing, a uniform resource identifier is a string of characters used to identify a name or a resource on the Internet. Such identification enables interaction with representations of the resource over a network using specific protocols...
(URI), and the fragment identifier points to the subordinate resource.
The fragment identifier introduced by a hash mark
#
is the optional last part of a URLUniform Resource Locator
In computing, a uniform resource locator or universal resource locator is a specific character string that constitutes a reference to an Internet resource....
for a document. It is typically used to identify a portion of that document. The generic syntax is specified in RFC 3986. The hash mark
Number sign
Number sign is a name for the symbol #, which is used for a variety of purposes including, in some countries, the designation of a number...
separator in URIs does not belong to the fragment identifier.
Basics
In URIs a hashmark#
introduces the optional fragment near the end of the URL. The generic RFC 3986 syntax for URIs also allows an optional query part introduced by a question mark ?
. In URIs with a query and a fragment the fragment follows the query. Query parts depend on the URI scheme and are evaluated by the server — e.g., http:
supports queries unlike ftp:
. Fragments depend on the document MIMEMIME
Multipurpose Internet Mail Extensions is an Internet standard that extends the format of email to support:* Text in character sets other than ASCII* Non-text attachments* Message bodies with multiple parts...
type and are evaluated by the client (Web browser
Web browser
A web browser is a software application for retrieving, presenting, and traversing information resources on the World Wide Web. An information resource is identified by a Uniform Resource Identifier and may be a web page, image, video, or other piece of content...
). Clients are not supposed to send URI-fragments to servers when they retrieve a document, and without help from a local application (see below) fragments do not participate in HTTP
Hypertext Transfer Protocol
The Hypertext Transfer Protocol is a networking protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web....
redirections.
An URI ending with
#
is permitted by the generic syntax, this could be considered as a kind of empty fragment. In MIME document types such as text/html
or any XML type, empty identifiers to match this syntactically legal construct are not permitted. Web browsers typically display the top of the document for an empty fragment.The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side
Client (computing)
A client is an application or system that accesses a service made available by a server. The server is often on another computer system, in which case the client accesses the service by way of a network....
with no participation from the server
Web server
Web server can refer to either the hardware or the software that helps to deliver content that can be accessed through the Internet....
— of course the server typically helps to determine the MIME type, and the MIME type determines the processing of fragments. When an agent
User agent
In computing, a user agent is a client application implementing a network protocol used in communications within a client–server distributed computing system...
(such as a Web browser) requests a resource
Resource (Web)
The concept of resource is primitive in the Web architecture, and is used in the definition of its fundamental elements. The term was first introduced to refer to targets of Uniform Resource Locators , but its definition has been further extended to include the referent of any Uniform Resource...
from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the document type and fragment value.
Examples
- In URIs for MIME
text/html
pages such as
the fragment refers to the element withhttp://www.example.org/foo.html #barid="bar"
.- Graphical Web browsers typically position pages so that the top of the element identified by the fragment id is aligned with the top of the viewport; thus fragment identifiers are often used in tables of content and in permalinkPermalinkA permalink is a URL that points to a specific blog or forum entry after it has passed from the front page to the archives. Because a permalink remains unchanged indefinitely, it is less susceptible to link rot. Most modern weblogging and content-syndication software systems support such links...
s. - The appearance of the identified element can be changed through the
:target
CSSCSS-Computing:*Cascading Style Sheets, a language used to describe the style of document presentations in web development*Central Structure Store in the PHIGS 3D API*Closed source software, software that is not distributed with source code...
pseudoclass; WikipediaWikipediaWikipedia is a free, web-based, collaborative, multilingual encyclopedia project supported by the non-profit Wikimedia Foundation. Its 20 million articles have been written collaboratively by volunteers around the world. Almost all of its articles can be edited by anyone with access to the site,...
uses this to highlight the selected reference. Notably CSSdisplay: block
can be used to show content only if it is the target, and otherwise hidden bydisplay: none
. - The deprecated
name
attribute (allowed only for some elements) had a similar purpose in now obsolete browsers. If presentname
andid
must be identical.
- Graphical Web browsers typically position pages so that the top of the element identified by the fragment id is aligned with the top of the viewport; thus fragment identifiers are often used in tables of content and in permalink
- In all XMLXMLExtensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
document types including XHTMLXHTMLXHTML is a family of XML markup languages that mirror or extend versions of the widely-used Hypertext Markup Language , the language in which web pages are written....
fragments corresponding to anxml:id
or similarid
attributes follow theName
-syntax and begin with a letter, underscore, or colon. Notably they cannot begin with a digit or hyphen.xml:id
is one of the few generic XML attributes, e.g.,xml:lang
, which can be used without explicitly declaring a namespace. In XHTMLid
has to be used, because XHTML was specified beforexml:id
existed.
- In XML applications, fragment identifiers in a certain syntax can be XPointerXPointerXPointer is a system for addressing components of XML based internet media.XPointer is divided among four specifications: a "framework" which forms the basis for identifying XML fragments, a positional element addressing scheme, a scheme for namespaces, and a scheme for XPath-based addressing...
s; for example, the fragment identifier in the URI
refers to all XML elements named "Rube" in the document identified by the URIhttp://www.example.org/foo.xml #xpointer(//Rube)http://www.example.org/foo.xml . An XPointer processor, given that URI, would obtain a representation of the document (such as by requesting it from the Internet) and would return a representation of the document's "Rube" elements. - In RDFResource Description FrameworkThe Resource Description Framework is a family of World Wide Web Consortium specifications originally designed as a metadata data model...
vocabularies, such as RDFSRDF SchemaRDF Schema is a set of classes with certain properties using the RDF extensible knowledge representation language, providing basic elements for the description of ontologies, otherwise called RDF vocabularies, intended to structure RDF resources...
, OWLWeb Ontology LanguageThe Web Ontology Language is a family of knowledge representation languages for authoring ontologies.The languages are characterised by formal semantics and RDF/XML-based serializations for the Semantic Web...
, or SKOSSKOSSimple Knowledge Organization System is a family of formal languages designed for representation of thesauri, classification schemes, taxonomies, subject-heading systems, or any other type of structured controlled vocabulary. SKOS is built upon RDF and RDFS, and its main objective is to enable...
, fragment identifiers are used to identify resources in the same XML Namespace, but are not necessarily corresponding to a specific part of a document. For example
identifies the concept "broader" in SKOS Core vocabulary, but it does not refer to a specific part of the resource identified byhttp://www.w3.org/2004/02/skos/core #broader
, a complete RDF file in which semantics of this specific concept is declared, along with other concepts in the same vocabulary.http://www.w3.org/2004/02/skos/core - In URIs for MIME
text/plain
documents RFC 5147 specifies a fragment identifier for the character and line positions and ranges within the document using the keywords "char
" and "line
". Some popular browsers do not yet support RFC 5147. The following example identifies lines 11 through 20 of a text document:-
http://example.com/document.txt#line=10,20
-
- In JavaScriptJavaScriptJavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....
, the fragment identifier of the current HTML or XHTML page can be accessed in the "hash" propertylocation.hash
— note that Javascript can be also used with other document types. With the rise of AJAXAjax- Mythology :* Ajax , son of Telamon, ruler of Salamis and a hero in the Trojan War, also known as "Ajax the Great"* Ajax the Lesser, son of Oileus, ruler of Locris and the leader of the Locrian contingent during the Trojan War.- People :...
, some websites use fragment identifiers to emulate the back button behavior of browsers for page changes that do not require a reload, or to emulate subpages.- For example, GmailGmailGmail is a free, advertising-supported email service provided by Google. Users may access Gmail as secure webmail, as well via POP3 or IMAP protocols. Gmail was launched as an invitation-only beta release on April 1, 2004 and it became available to the general public on February 7, 2007, though...
uses a single URL for almost every interface – mail boxes, individual mails, search results, settings – the fragment is used to make these interfaces directly linkable. - Adobe FlashAdobe FlashAdobe Flash is a multimedia platform used to add animation, video, and interactivity to web pages. Flash is frequently used for advertisements, games and flash animations for broadcast...
websites can use the fragment part to inform the user about the state of the website or web application, and to facilitate deep linkingDeep linkingOn the World Wide Web, deep linking is making a hyperlink that points to a specific page or image on a website, instead of that website's main or home page. Such links are called deep links.-Example:...
, commonly with the help of the SWFAddressSWFAddressSWFAddress is an open-source JavaScript library that enables Adobe Flash/Flex and JavaScript/AJAX websites and web applications to support deep linking, a practice that enables users to link to a specific section or page of the content....
JavaScript library. - Other websites use the fragment part to pass some extra information to scripts running on them – for example, Google VideoGoogle VideoGoogle Videos is a video search engine, and formerly a free video sharing website, from Google Inc. Before removing user-uploaded content, the service allowed selected videos to be remotely embedded on other websites and provided the necessary HTML code alongside the media, similar to YouTube...
understands permalinks in the format of#01h25m30s
to start playing at the specified position, and YouTubeYouTubeYouTube is a video-sharing website, created by three former PayPal employees in February 2005, on which users can upload, view and share videos....
uses similar code such as#t=3m25s
. A format of#t=10,20
for a section of media from 10 to 20 seconds is proposed in the Media Fragments URI 1.0 W3C Working Draft.
- For example, Gmail
- In URIs for MIME
application/pdf
documents Adobe PDF viewers recognize a number of fragment identifiers. For instance, a URL ending inPortable Document FormatPortable Document Format is an open standard for document exchange. This file format, created by Adobe Systems in 1993, is used for representing documents in a manner independent of application software, hardware, and operating systems.....pdf#page=35
will cause Adobe Reader to open the PDF and scroll to page 35. Several other parameters are possible, including#nameddest=
(similar to HTML anchors),#search="word1 word2"
,#zoom=
, etc. Multiple parameters can be combined with ampersands:-
.http://example.org/doc.pdf#view=fitb&nameddest=Chapter3
-
Proposals
Several proposals have been made for fragment identifiers for use with plain text documents (which cannot store anchor metadata), or to refer to locations within HTML documents in which the author has not used anchor tags:- As of 2011 the W3C Media Fragments URI 1.0 Working Draft is in second last call.
- The Python Package Index appends the MD5MD5The MD5 Message-Digest Algorithm is a widely used cryptographic hash function that produces a 128-bit hash value. Specified in RFC 1321, MD5 has been employed in a wide variety of security applications, and is also commonly used to check data integrity...
hash of a file to the URL as a fragment identifier, so the integrity of the file can be checked automatically.-
http://pypi.python.org ... zodbbrowser-0.3.1.tar.gz#md5=38dc89f294b24691d3f0d893ed3c119c
-
- A hash-bang fragment is a fragment starting with an exclamation mark
!
. An exclamation markExclamation markThe exclamation mark, exclamation point, or bang, or "dembanger" is a punctuation mark usually used after an interjection or exclamation to indicate strong feelings or high volume , and often marks the end of a sentence. Example: “Watch out!” The character is encoded in Unicode at...
is illegal in HTML, XHTML, and XML identifiers, ensuring separation from that functionality.- Google Webmaster CentralGoogle Webmaster ToolsGoogle Webmaster Tools is a no-charge web service by Google for webmasters. It allows webmasters to check indexing status and optimize visibility of their websites.It has tools that let the webmasters:* Submit and check a sitemap...
has proposed using an initial exclamation mark in fragment identifiers for stateful AJAXAjax- Mythology :* Ajax , son of Telamon, ruler of Salamis and a hero in the Trojan War, also known as "Ajax the Great"* Ajax the Lesser, son of Oileus, ruler of Locris and the leader of the Locrian contingent during the Trojan War.- People :...
pages:http://example.com/page?query#!state
- Google Webmaster Central
External links
- W3C Media Fragments Working Group, establishing a URI syntax and semantics to address media fragments in audiovisual material (such as a region in an image or a sub-clip of a video)