HOME

TheInfoList



OR:

In computer
hypertext Hypertext is text displayed on a computer display or other electronic devices with references (hyperlinks) to other text that the reader can immediately access. Hypertext documents are interconnected by hyperlinks, which are typically ac ...
, a URI fragment is a
string String or strings may refer to: * String (structure), a long flexible structure made from threads twisted together, which is used to tie, bind, or hang other objects Arts, entertainment, and media Films * ''Strings'' (1991 film), a Canadian ani ...
of characters that refers to a
resource Resource refers to all the materials available in our environment which are technologically accessible, economically feasible and culturally sustainable and help us to satisfy our needs and wants. Resources can broadly be classified upon their ...
that is subordinate to another, primary resource. The primary resource is identified by a
Uniform Resource Identifier A Uniform Resource Identifier (URI) is a unique sequence of characters that identifies a logical or physical resource used by web technologies. URIs may be used to identify anything, including real-world objects, such as people and places, conc ...
(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
URL A Uniform Resource Locator (URL), colloquially termed as a web address, is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it. A URL is a specific type of Uniform Resource Identifi ...
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 is not part of the fragment Identifier


Basics

In URIs, a hash mark # 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
MIME type A media type (also known as a MIME type) is a two-part identifier for file formats and format contents transmitted on the Internet. The Internet Assigned Numbers Authority (IANA) is the official authority for the standardization and publication ...
and are evaluated by the client (
web browser A web browser is application software for accessing websites. When a user requests a web page from a particular website, the browser retrieves its files from a web server and then displays the page on the user's screen. Browsers are used on ...
). 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 The Hypertext Transfer Protocol (HTTP) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, w ...
redirections. A URI ending with # is permitted by the generic syntax and is 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 to the rest of the URI: its processing is exclusively
client-side Client-side refers to operations that are performed by the client in a client–server relationship in a computer network. General concepts Typically, a client is a computer application, such as a web browser, that runs on a user's local com ...
d with no participation from the
web server A web server is computer software and underlying hardware that accepts requests via HTTP (the network protocol created to distribute web content) or its secure variant HTTPS. A user agent, commonly a web browser or web crawler, initiate ...
, though the server typically helps to determine the MIME type, and the MIME type determines the processing of fragments. When an
agent Agent may refer to: Espionage, investigation, and law *, spies or intelligence officers * Law of agency, laws involving a person authorized to act on behalf of another ** Agent of record, a person with a contractual agreement with an insuranc ...
(such as a web browser) requests a
web resource A web resource is any identifiable resource (digital, physical, or abstract) present on or connected to the World Wide Web.< ...
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. In an HTML web page, the agent will look for an anchor identified with an HTML tag that includes an id= or name= attribute equal to the fragment identifier.


Examples

* In URIs for MIME text/html pages such as http://www.example.org/foo.html#bar the fragment refers to the element with id="bar". ** Graphical Web browsers typically scroll to 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 A permalink or permanent link is a URL that is intended to remain unchanged for many years into the future, yielding a hyperlink that is less susceptible to link rot. Permalinks are often rendered simply, that is, as clean URLs, to be easier to ...
s. ** The appearance of the identified element can be changed through the :target CSS pseudoclass;
Wikipedia Wikipedia is a multilingual free online encyclopedia written and maintained by a community of volunteers, known as Wikipedians, through open collaboration and using a wiki-based editing system. Wikipedia is the largest and most-read referenc ...
uses this to highlight the selected reference. Notably CSS display: block can be used to show content only if it is the target, and otherwise hidden by display: none. ** The deprecated name attribute (allowed only for some elements) had a similar purpose in now obsolete browsers. If present name and id must be identical. * In all XML document types including
XHTML Extensible HyperText Markup Language (XHTML) is part of the family of XML markup languages. It mirrors or extends versions of the widely used HyperText Markup Language (HTML), the language in which Web pages are formulated. While HTML, prior ...
fragments corresponding to an xml:id or similar id attributes follow the Name-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 XHTML id has to be used, because XHTML was specified before xml:id existed. * In XML applications, fragment identifiers in a certain syntax can be
XPointer XPointer is a system for addressing components of XML-based Internet media. It is divided among four specifications: a " framework" that forms the basis for identifying XML fragments, a positional element addressing scheme, a scheme for namespace ...
s; for example, the fragment identifier in the URI http://www.example.org/foo.xml#xpointer(//Rube) refers to all XML elements named "Rube" in the document identified by the URI 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 RDF vocabularies, such as
RDFS RDF Schema (Resource Description Framework Schema, variously abbreviated as RDFS, , RDF-S, or RDF/S) is a set of classes with certain properties using the RDF extensible knowledge representation data model, providing basic elements for the descr ...
,
OWL Owls are birds from the order Strigiformes (), which includes over 200 species of mostly solitary and nocturnal birds of prey typified by an upright stance, a large, broad head, binocular vision, binaural hearing, sharp talons, and feathers a ...
, or
SKOS Simple Knowledge Organization System (SKOS) is a W3C recommendation designed for representation of thesauri, classification schemes, taxonomies, subject-heading systems, or any other type of structured controlled vocabulary. SKOS is part of the ...
, fragment identifiers are used to identify resources in the same
XML Namespace XML namespaces are used for providing uniquely named elements and attributes in an XML document. They are defined in a W3C recommendation. An XML instance may contain element or attribute names from more than one XML vocabulary. If each vocabular ...
, but are not necessarily corresponding to a specific part of a document. For example, http://www.w3.org/2004/02/skos/core#broader identifies the concept "broader" in SKOS Core vocabulary, but it does not refer to a specific part of the resource identified by http://www.w3.org/2004/02/skos/core, a complete RDF file in which semantics of this specific concept is declared, along with other concepts in the same vocabulary. * In URIs for MIME
text/plain A text file (sometimes spelled textfile; an old alternative name is flatfile) is a kind of computer file that is structured as a sequence of lines of electronic text. A text file exists stored as data within a computer file system. In operati ...
documents RFC 5147 specifies a fragment identifier for the character and line positions and ranges within the document using the keywords "char" and "line". Browser support seems lacking. The following example identifies lines 11 through 20 of a text document: **http://example.com/document.txt#line=10,20 * In URIs for MIME
text/csv A comma-separated values (CSV) file is a delimited text file that uses a comma to separate values. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. The use of the comma as a field separato ...
documents, RFC 7111 specifies a fragment identifier as a selector for rows, columns, and cells using the keywords "row" , "col", and "cell", for example: ** http://example.com/data.csv#row=4 – Selects the 4th row. ** http://example.com/data.csv#col=2 – Selects 2nd column. ** http://example.com/data.csv#row=5-7 – Selects three consecutive rows starting with 5th row. ** http://example.com/data.csv#row=5-* – Selects all rows starting with 5th row. ** http://example.com/data.csv#cell=4,1-6,2 – Selects a region that starts at the 4th row and the 1st column and ends at the 6th row and the 2nd column. * In URIs for MIME audio/*, image/*, video/* documents, very few have defined fragments or fragment semantics. The Media Fragments URI 1.0 (basic) syntax supports addressing a media resource along two dimensions (temporal and spatial) using the keywords t and xywh. Therefore, one can use the following media fragments URI in the src attribute of the audio or video
HTML5 HTML5 is a markup language used for structuring and presenting content on the World Wide Web. It is the fifth and final major HTML version that is a World Wide Web Consortium (W3C) recommendation. The current specification is known as the HTML ...
element: ** http://example.com/foo.mp4#t=10,20 ** http://example.com/bar.webm#t=40,80&xywh=160,120,320,240 ** Other websites use the fragment part to pass some extra information to scripts running on them – for example,
Google Video Google Video was a free video hosting service launched by the multinational technology company Google on January 25, 2005. Similar to YouTube, this platform allowed video clips to be hosted on Google servers and embedded on to other websites ...
understands permalinks in the format of #01h25m30s to start playing at the specified position, and
YouTube YouTube is a global online video sharing and social media platform headquartered in San Bruno, California. It was launched on February 14, 2005, by Steve Chen, Chad Hurley, and Jawed Karim. It is owned by Google, and is the second most vis ...
uses similar code such as #t=3m25s. * In
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, often ...
, the fragment identifier of the current HTML or XHTML page can be accessed in the "hash" property location.hash – note that Javascript can be also used with other document types. With the rise of
AJAX Ajax may refer to: Greek mythology and tragedy * Ajax the Great, a Greek mythological hero, son of King Telamon and Periboea * Ajax the Lesser, a Greek mythological hero, son of Oileus, the king of Locris * ''Ajax'' (play), by the ancient Greek ...
, 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,
Gmail Gmail is a free email service provided by Google. As of 2019, it had 1.5 billion active users worldwide. A user typically accesses Gmail in a web browser or the official mobile app. Google also supports the use of email clients via the POP an ...
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 Flash Adobe Flash (formerly Macromedia Flash and FutureSplash) is a multimedia Computing platform, software platform used for production of Flash animation, animations, rich web applications, application software, desktop applications, mobile apps, mo ...
websites can use the fragment part to inform the user about the state of the website or web application, and to facilitate
deep linking In the context of the World Wide Web, deep linking is the use of a hyperlink that links to a specific, generally searchable or indexed, piece of web content on a website (e.g. "http://example.com/path/page"), rather than the website's home page (e ...
, commonly with the help of the SWFAddress JavaScript library. * A URI that links to a
JSON JSON (JavaScript Object Notation, pronounced ; also ) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (or other se ...
document can specify a pointer to a specific value. ** For example, a URL ending in #/foo could be used to extract the value from a key-value pair in a document beginning with * In URIs for MIME application/pdf documents PDF viewers recognize a number of fragment identifiers. For instance, a URL ending in .pdf#page=35 will cause most readers 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. * In SVG, fragments are allowed to specify arguments such as viewBox(), preserveAspectRatio(), and transform().


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 September 2012 the Media Fragments URI 1.0 (basic) is a
W3C The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. Founded in 1994 and led by Tim Berners-Lee, the consortium is made up of member organizations that maintain full-time staff working t ...
Recommendation. *Chrome versions 80 and above implement
W3C The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. Founded in 1994 and led by Tim Berners-Lee, the consortium is made up of member organizations that maintain full-time staff working t ...
'
WICG
''Text Fragments,'' so #:~:text=foo will cause the browser to search for foo, highlight the matching text, and scroll to it. Besides the start and end, the snippet can also specify a context: text that must precede or follow foo but won't be highlighted ( example that searches for 'vision' preceded by 'night'). * The
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pr ...
Package Index appends the MD5 hash of a file to the URL as a fragment identifier. If MD5 were unbroken (it is a broken hash function), it could be used to ensure the
integrity Integrity is the practice of being honest and showing a consistent and uncompromising adherence to strong moral and ethical principles and values. In ethics, integrity is regarded as the honesty and truthfulness or accuracy of one's actions. Inte ...
of the package. *: https://pypi.python.org ... zodbbrowser-0.3.1.tar.gz#md5=38dc89f294b24691d3f0d893ed3c119c * A hash-bang fragment is a fragment starting with an exclamation mark !. It was used in a now-deprecated approach to index dynamic
single-page application A single-page application (SPA) is a web application or website that interacts with the user by dynamically rewriting the current web page with new data from the web server, instead of the default method of a web browser loading entire new pages. ...
s. An
exclamation mark The exclamation mark, , or exclamation point (American English), is a punctuation mark usually used after an interjection or exclamation to indicate strong feelings or to show emphasis. The exclamation mark often marks the end of a sentence, f ...
is illegal in
HTML4 The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScript ...
, XHTML, and XML identifiers, granting certain degree of separation from that functionality. However, it is allowed in
HTML5 HTML5 is a markup language used for structuring and presenting content on the World Wide Web. It is the fifth and final major HTML version that is a World Wide Web Consortium (W3C) recommendation. The current specification is known as the HTML ...
. ** Between 2009 and 2015, Google Webmaster Central proposed and then recommended an "AJAX crawling scheme" using an initial exclamation mark in fragment identifiers for stateful
AJAX Ajax may refer to: Greek mythology and tragedy * Ajax the Great, a Greek mythological hero, son of King Telamon and Periboea * Ajax the Lesser, a Greek mythological hero, son of Oileus, the king of Locris * ''Ajax'' (play), by the ancient Greek ...
pages: http://example.com/page?query#!state ** Another implementation has been the replacement of #! with ?_escaped_fragment_= ** Hash-bang URIs have been considered problematic by a number of writers including Jeni Tennison at the W3C because they make pages inaccessible to those who do not have
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, often ...
activated in their browser. They also break HTTP referer headers as browsers are not allowed to send the fragment identifier in the Referer header. ** In 2015, Google deprecated their hash-bang AJAX crawling proposal, recommending instead the use of
progressive enhancement Progressive enhancement is a strategy in web design that puts emphasis on web content first, allowing everyone to access the basic content and functionality of a web page, whilst users with additional browser features or faster Internet access r ...
and
HTML5 HTML5 is a markup language used for structuring and presenting content on the World Wide Web. It is the fifth and final major HTML version that is a World Wide Web Consortium (W3C) recommendation. The current specification is known as the HTML ...
's history.pushState() method. **
Mozilla Foundation The Mozilla Foundation (stylized as moz://a) is an American non-profit organization that exists to support and collectively lead the open source Mozilla project. Founded in July 2003, the organization sets the policies that govern development, ...
employee Gervase Markham has proposed a fragment identifier for searching, of the form #!s!search terms. Adding a number after the s (#!s10!) indicates that the browser should search for the ''n''th occurrence of the search term. A negative number (#!s-3!) starts searching backwards from the end of the document. A
Greasemonkey Greasemonkey is a userscript manager made available as a Mozilla Firefox extension. It enables users to install scripts that make on-the-fly changes to web page content after or before the page is loaded in the browser (also known as augm ...
script is available to add this functionality to compatible browsers. **: http://example.com/index.html#!s3!search terms * Erik Wilde and Marcel Baschnagel of the
ETH Zurich (colloquially) , former_name = eidgenössische polytechnische Schule , image = ETHZ.JPG , image_size = , established = , type = Public , budget = CHF 1.896 billion (2021) , rector = Günther Dissertori , president = Joël Mesot , aca ...
extend this to also identify fragments in plain text documents using
regular expressions A regular expression (shortened as regex or regexp; sometimes referred to as rational expression) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or ...
, with the keyword "match". They also describe a prototype implementation as an extension for the
Firefox Mozilla Firefox, or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and its subsidiary, the Mozilla Corporation. It uses the Gecko rendering engine to display web pages, which implements current and ...
browser. For example, the following would find the case-insensitive text "RFC" anywhere in the document: *: http://example.com/document.txt#match= RfF] C/nowiki> * K. Yee of the
Foresight Institute The Foresight Institute (Foresight) is a San Francisco-based research non-profit that promotes the development of nanotechnology and other emerging technologies, such as safe AGI, biotech and longevity. Foresight runs four cross-disciplinary ...
proposes "extended fragment identifiers" delimited with colons and a keyword to differentiate them from anchor identifiers. A text search fragment identifier with "fragment specification scheme" id "words" is the first proposal in this scheme. The following example would search a document for the first occurrence of the string "some context for a search term" and then highlight the words "search term": *: http://example.com/index.html#:words:some-context-for-a-(search-term) ** Text Fragments was proposed as a Draft Community Group Report in December 2021. This scheme uses the directive :~:text= to introduce the search term. **: https://en.wikipedia.org/wiki/History_of_computing#:~:text=The%20first%20recorded,Williams ** The above scheme was implemented in Chrome version 80. * The LiveURLs project proposed a fragment identifier format for referring to a region of text within a page, of the form #FWS+C, where ''F'' is the length of the first word (up to five characters), ''W'' is the first word itself, ''S'' is the length of the selected text and ''C'' is a 32-bit CRC of the selected text. They implemented a variant of this scheme as an extension for the Firefox browser, using the form #LFWS+C, where ''L'' is the length of the fragment itself, in two hex digits. Linking to the word "Fragment" using the implemented variant would yield: *: http://example.com/index.html#115Fragm8+-52f89c4c * Up until Firefox 5, Firefox supported XPath links such as #xpath:/html/body/div which could be used in conjunction with a bookmarklet such as http://antimatter15.com/wp/2009/11/xpath-bookmark-bookmarklet/ to link within HTML documents that lacked proper IDs. This feature was removed as part of a code cleanup in https://bugzilla.mozilla.org/show_bug.cgi?id=457102 *In
ePub EPUB is an e-book file format that uses the ".epub" file extension. The term is short for ''electronic publication'' and is sometimes styled ''ePub''. EPUB is supported by many e-readers, and compatible software is available for most smartphones ...
electronic book format, the EPUB Canonical Fragment Identifier (epubcfi, 2011-2017) defines a
W3C The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. Founded in 1994 and led by Tim Berners-Lee, the consortium is made up of member organizations that maintain full-time staff working t ...
/ IDPF-standardized method for referencing arbitrary content using fragment identifiers to locate non-anchored text ranges via document structure and pattern matching. These dynamic deep links assist in locating content after text is updated and are used, for example, in
Apple Books Apple Books (formerly known as iBooks between January 2010 and September 2018) is an e-book reading and store application by Apple Inc. for its iOS and macOS operating systems and List of iOS devices, devices. It was announced, under the name i ...
.


See also

*
URL normalization URI normalization is the process by which URIs are modified and standardized in a consistent manner. The goal of the normalization process is to transform a URI into a normalized URI so it is possible to determine if two syntactically differen ...
*
Uniform Resource Locator A Uniform Resource Locator (URL), colloquially termed as a web address, is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it. A URL is a specific type of Uniform Resource Identifie ...


References

{{reflist


External links

* W3
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) * MediaMixe
Community Portal
collects presentations, tutorials, use cases and demonstrators related to use of Media Fragment technology URI schemes Identifiers Hypertext