Skip to content

Tools

Text Fragment Links Explained

Text fragments are the web standard that lets a link highlight words on a page the link author does not control. This is the reference: how the browser matches, the full syntax, what is and is not sent to the server, and why some links fail.

Anatomy of a text fragment linkexample.org/article#:~:text=the%20one%20linethe browser scrolls here and marks the text
Four highlighter pens lined up beside a paper bookmark, two paper clips and a card with one yellow stroke

For twenty years the only way to link into the middle of a page was an anchor the author had placed there, an id attribute you could hang a #section on. Text fragments, specified by the Web Incubator Community Group and shipped in Chrome 80 in early 2020, let the reader choose the target instead. The link carries a few words; the browser searches the page for them, scrolls there and highlights the match. Safari adopted it in 16.1 (2022) and Firefox in 131 (2024), which makes it the first universal, server-free way to share a highlight.

The syntax

A text directive lives in the fragment part of a URL (after #), introduced by the delimiter :~:. The general form is:

Grammar

#:~:text=[prefix-,]textStart[,textEnd][,-suffix]

Each part is percent-encoded; commas, hyphens and ampersands inside a part must be encoded so they are not read as separators.
PartRequiredMeaningHighlighted
textStartYesThe phrase to find, or the start of a rangeYes
textEndNoIf present, the match extends from textStart to the first textEnd after itYes (the whole range)
prefix-NoText that must appear immediately before the match (trailing hyphen)No
-suffixNoText that must appear immediately after the match (leading hyphen)No

Multiple directives are joined with &: #:~:text=first%20phrase&text=second%20phrase highlights both. Matching is case-insensitive and ignores differences in whitespace, and it only considers text the user could see and select (not hidden elements, not the contents of form fields). Word boundaries matter: a directive does not match in the middle of a word.

How the browser finds the passage

  1. The browser loads the page and, once the document is ready, looks for the directive in the fragment.
  2. It walks the visible text looking for the first occurrence of textStart that satisfies the prefix and suffix, if given.
  3. If textEnd is present, it extends the match to the first following occurrence of textEnd.
  4. It scrolls the match into view and applies a highlight (yellow or purple depending on the browser and version) using the ::target-text pseudo-element, which page authors can style.
  5. If nothing matches, or if the text arrives too late (some browsers stop searching after a short window), the page opens at the top as if the fragment were not there.

Privacy properties

The fragment part of a URL is not sent in the HTTP request, so the website cannot know which words you highlighted or that you used a text fragment at all. The browser also refuses to process text directives in situations where they could be used to test whether hidden text exists on a page (cross-origin frames, some scripted navigations), and it only activates them on a full navigation triggered by the user. Page authors can opt a page out entirely with the header Document-Policy: force-load-at-top. In practice, a text fragment link is as private as a plain link.

Styling highlights on your own pages

If you publish pages, you can control how incoming highlights look with a few lines of CSS. Only colour properties are allowed:

CSS

::target-text { background: #f5c400; color: #1c1b17; }

Known limits and how to work around them

Every failure falls back to a normal link to the page.
LimitWhyWork-around
Text that loads later is not foundThe browser searches once the document is ready and stops waiting after a momentUse the bookmarklet from inside the loaded page; or link to a static or print version
Edited text breaks the linkMatching is exact on the wordsKeep highlights short; quote the passage in your message too
Common phrases match the wrong placeThe first match winsAdd a prefix or suffix, or lengthen the phrase
Highlight disappears when the reader clicksSome browsers clear the highlight on interactionExpected behaviour; the reader has already found the passage
Not supported in PDFs, images or inside iframesThe standard covers HTML documents on the top-level pageUse PDF page links (#page=N) or the viewer's own highlighter
Very old browsersNo support before Chrome 80, Safari 16.1, Firefox 131The link still opens the page at the top

Where this came from

Sharing a highlighted passage used to require a service in the middle. The original Awesome Highlighter (2008) saved a copy of the page with your highlights and gave you a short link to it, and dozens of similar services did the same. That worked until the service closed, at which point every link died; our shared highlights archive page is the record of that. Text fragments move the highlight into the link itself, so it depends on nothing but the page it points to. It is the same idea, finally standardised.

Text fragments are the standard behind several tools compared elsewhere in the highlighter tools section: extensions increasingly use them for sharing (see our extension comparison), and the bookmarklet explainer shows how a one-click script builds them. They are also the most precise way to cite evidence, which is why quote tracing ends with one.

Common questions

What does #:~:text= mean in a URL?

It is a text fragment directive. The browser searches the page for the words after text=, scrolls to them and highlights them. The part after # is never sent to the website.

How do I make a text fragment link?

Select the text in Chrome or Edge and choose Copy link to highlight, or use the highlight link generator on this site, which encodes the phrase and optional prefix, suffix and range for you.

Why does my text fragment link not highlight anything?

The words changed, the text loads after the page appears, the phrase occurs earlier on the page, or the reader's browser is too old. Shorten the phrase, add context, or use the bookmarklet inside the loaded page.

Can I highlight a range of text rather than one phrase?

Yes. Use text=start,end. The browser highlights from the start phrase to the first end phrase after it.

Can a website block text fragment highlights?

Yes, with the Document-Policy: force-load-at-top response header. Few sites do.

Are text fragments part of an official standard?

They are specified by the WICG (URL Fragment Text Directives) and implemented by all major browsers. The specification is on a path toward full standardisation through the WHATWG URL and HTML work.

Sources

  • WICG: URL Fragment Text Directives, editor's draft
  • MDN Web Docs: Text fragments and ::target-text
  • Chrome 80 release notes (February 2020); WebKit Safari 16.1 release notes; Firefox 131 release notes