Text Fragments Enable Deep Linking on Web Pages

Originally published at: Text Fragments Enable Deep Linking on Web Pages - TidBITS

Wouldn’t it be nice if you could link to specific bits of text on a Web page rather than forcing people following your links to scan the page for whatever piece of information you’re trying to convey? With full support from major browser manufacturers appearing late last year, the Web has finally caught up with hypertext theory from the previous century.

The Long and Winding History of Text Fragment Linking

Sometime in the 1960s, hypertext pioneer Ted Nelson envisioned deep linking to specific pieces of text as a core feature of his proposed Project Xanadu system. (My first exposure to Xanadu came in the 1987 edition of his Computer Lib/Dream Machines from 1974, when I was working on my degree in hypertextual fiction at Cornell University. You can download the book in readable formats from the Internet Archive.)

From the early 1990s until recently, the only way to link to a specific part of a Web page was through a named anchor. If the page author inserted name="subhead1" into an anchor link in their HTML, a URL like https://example.com/#subhead1 would cause browsers to scroll directly to that spot. Although we, as users, could copy those links or examine the HTML source of a document for named anchors that we could use when creating our own links, the vast majority of links point to the top of the destination page.

In 2020, to enable deep linking within pages, Google Chrome introduced the Scroll To Text Fragment (STTF) feature. It allowed URLs with a #:~:text= parameter to link directly to any visible text on a page, so a URL like https://example.com#:~:text=specific%20phrase would highlight and scroll to the text “specific phrase” on the page. The key benefit of the feature was that it didn’t require cooperation from the page author, and Google began using it to enhance the user experience within Google Search results.

Google also built the feature into the open source Chromium code. Over the next few years, that caused most Chromium browsers to adopt the feature, including Arc, Edge, Opera, Vivaldi, and others. Until very recently, Brave was a holdout because its senior privacy researcher believed that STTF introduces some privacy risks, but Brave now supports the feature in development builds. In what I consider a misguided move, Arc’s developers decided to encapsulate the long text fragment links in a custom shortlink redirected by a server at arc.net, perhaps to make the links more readable or increase privacy. Text fragment URLs may be long, but they allow users to preview the hostname of the destination and won’t break if the arc.net redirection service disappears.

Until late 2024, Mozilla and Apple chose not to support STTF due to additional privacy concerns and annoyance with Google’s use of its control over Chromium and Google Search to effectively dictate Web standards via deployment rather than consensus. Eventually, though, Mozilla and Apple bowed to market pressure, with partial support appearing in Firefox 131 in October 2024 and full support showing up in Safari 18.2 in December 2024. Firefox will now recognize text fragment links, scrolling to and highlighting them, though an add-on is necessary to create the links. Safari can both recognize and create links.

Following Text Fragment Links

As I noted, apart from the current version of Brave, all Web browsers that I’m aware of now support following text fragment links. When you click one—and you likely won’t realize that you’re doing so ahead of time—the specified page will load and scroll to the appropriate location, and the text included in the link will be highlighted. (In the current version of Brave, the page loads but doesn’t scroll or highlight any text—the link behaves like a regular link.)

Precisely what the highlight looks like can vary because page authors can style the highlighted text using the ::target-text pseudo-element. It allows changing the color, background-color, text-decoration, text-shadow, stroke-color, fill-color, and stroke-width. However, most of the time, you’ll just see the styling used for the mark HTML element: a purple (Chromium browsers), yellow (Safari), or orange (Firefox) highlight behind the text.

Highlighted text fragment in Safari

If the linked text changes, the highlighting will fail, but the page will still load.

Creating Text Fragment Links

Making your own text fragment links is simple—the hardest part is identifying the correct command in a contextual menu—you won’t find the relevant commands in the Edit menu. First, you select the desired text, then you Control-click and:

  • In Safari, choose Copy Link with Highlight. This command is also available in Safari on the iPhone and iPad, as well as other browsers that use WebKit on these devices.
    Create a text fragment link in Safari
  • In Chromium browsers other than Brave, choose Copy Link to Highlight.
  • In Brave, after you have installed Google’s Link to Text Fragment extension, choose Copy Link to Selected Text.
  • In Firefox or Orion, after you have installed Thomas Steiner’s Link to Text Fragment extension, choose Copy Link to Selected Text. (Firefox also has a hidden configuration tweak to enable native text fragment link creation.)

What if the word you select appears multiple times within the document? How will the browser know which one to highlight? The STTF spec includes prefix and suffix components in the URL—in essence, a few words on either side of the selected text that disambiguate it. In the article in the screenshot above, linking to the word “sidebar” automatically produces this URL, which includes three disambiguation words on either side of the target word:

https://tidbits.com/2025/04/10/new-organizational-features-in-photos-in-macos-15-sequoia/#:~:text=The%20next%20two-,sidebar,-sections%20in%20Photos

It’s not inconceivable that an ambiguous link could still be created, but the worst that would happen is that the browser would highlight the wrong text on the page. You’d have to work pretty hard to make that happen—linking to more than a few words should provide uniqueness.

One final tip. You can highlight multiple portions of a document by editing the text fragment URL and appending additional text= elements, separated by an &. It requires precise work to copy the text= element from one URL and paste it into another, but the result may be worthwhile. Try it with this link below.

https://tidbits.com/2025/04/18/staying-the-course-after-35-years-of-tidbits/#:~:text=I%20believe%20we%20can%20best%20contribute%20by%20modeling%20the%20behavior%20we%20want%20to%20see%20in%20the%20world.&text=It%20means%20practicing%20kindness%2C%20decency%2C%20and%20respect%20whenever%20possible.

Can You Link Inside a PDF?

As welcome as text fragment links are, they aren’t necessary in most Web pages, which tend to be relatively short. However, PDFs are a different story. In “Add Protection from Scammers with Cyber Insurance” (11 April 2025), Glenn Fleishman linked to a Federal Trade Commission report to support his statement that Americans lost $12 billion to fraud in 2024. However, that’s a 92-page PDF, and it took me quite a few minutes to confirm the number during my edit pass.

In an ideal world, Glenn would have been able to use text fragment links to highlight the exact text he was referencing. Unfortunately, text fragment linking does not work in PDFs.

Happily, some research revealed that it is possible to link directly to the sixth page in a document, for instance, by appending #page=6 to its URL. I have updated the link in Glenn’s article to the URL below, which now scrolls to the page containing the data. It doesn’t highlight anything, but ending up on the page is far better than having to search or scroll through a lengthy PDF.

https://www.ftc.gov/system/files/ftc_gov/pdf/csn-annual-data-book-2024.pdf#page=6

Give Deep Linking a Try

Text fragment links represent a small but notable step forward in the evolution of the Web, finally realizing a part of Ted Nelson’s vision for hypertext and enabling precise navigation to specific content. Deep linking makes sharing information more efficient, improves the usability of lengthy documents, and helps readers focus on the most relevant content. I encourage you to start using text fragment links when you share information from the Web—people might not realize why the experience is better, but they’ll appreciate not having to hunt for the information you’re referencing.

15 Likes

Okay, that’s just spectacular. So useful – I’m already thinking about the varying ways to use it.

(What’s the opposite of “enshittification”?)

4 Likes

Oddly, while this link shows up correctly in the browser, in the email version of this article, Apple Mail (14.0, running on Big Sur) stops recognizing it as a link at the encoded space (“%20”) between “the” and “world” at the end of the first fragment, at 194 characters. Any ideas what causes this?

1 Like

Extremely useful! I had no idea that was what was going in Safari. Thank you!

4 Likes

It used to just be called “software development” but it does seem we need another word now for software updates that improve the software.

Seems it’s not just me who assumes that by default software updates these days are probably going to take something useful away rather than add it.

1 Like

Another great article that will be the tipping point for getting me to actually use something I’ve been dimly aware of. Thanks as always.

1 Like

Wow! I will be using this going forward. Thanks.

I’m still using iOS 17 latest, and shared one of these just yesterday, via: Safari > (select text) > Share sheet > Messages > (type recipient name) > Send

It looked like this in Messages, pretty good, though the why/what/how bullet points are no longer visible making it slightly more difficult to read/parse:

Excellent tip @ace !
I’m using Orion Version 0.99.130.2-beta (WebKit 621.1.2.111.4) mostly and when clicking on the “click one” link in ‘Following Text Fragment LInks’, I arrived at the linked page at the top. No text on the page was highlighted and the browser tab became stuck. Won’t go forward or backward or repond to any links on the page.
I thought Orion was derived from Safari (I’m way out of date on how browsers work these days) so am a bit surprised it didn’t work.
Ah well, fyi. Good to know about this though, I’ll keep trying to notice and use these links!

Cool! But the “Copy Link with Highlight” command isn’t shown when I select text and option/click it in OS 14.7.1, Safari 18.1, just “Copy.”

Probably missing something . . .

For macOS you’ll need newer system.

2 Likes

Orion is from Kagi and is focusing on privacy, so perhaps it’s taking the same tack as Brave and refusing to support the feature. Hmm… It seems that it does follow text fragment links and highlight the text appropriately, but doesn’t support creating them natively. I’ll bet one of the extensions will enable that… the Firefox extension does, the Chrome extension does not.

It may also just be that Orion is still a beta.

I’d written a long post this morning on treatment choices in CLL after venetoclax, and I’ve been able to go back and change the links in it to take readers to specific tables in quoted papers. Thanks!

With respect to Orion, I tried my edited text specific link in Orion and it took me to the correct part of the linked page.

So that’s what Copy Link with Highlight does.

When I started reading this article the first thing I thought of was Ted Nelson’s Project Xanadu, and then there it was in the article. :slight_smile:

But, while it is has been a long time since I read about Xanadu (perhaps in BYTE magazine?), I seem to remember one of his goals was link permamence. A link to some piece of content should always work, regardless of changes in site organization or hosting or whatever.

But here we have the opposite of that. If the site owner changes the text even a little bit then the text fragment links break. There’d be no way for the site owner to prevent this because they don’t even know these links are being created.

1 Like

Well, the links degrade, in that they won’t highlight the desired text, but they don’t break, in that they’ll still load the page.

I think it was Managing Immense Storage by Ted Nelson in BYTE, January 1988.

1 Like

Firefox does natively support creating text fragment links with a hidden configuration tweak.
First, type about:config in the address bar, followed by the enter key and continue at the warning prompt. Then search for fragments and tweak the following settings:

  1. Set dom.text_fragments.create_text_fragment.enabled to true by double clicking on it.
  2. The following of text fragment links can be enabled (as is default?) by setting
    dom.text_fragments.enabled to true by double-clicking on it.
  3. There is also a related timeout value, the function of which seems undocumented: dom.text_fragments.create_text_fragment.timeout_seconds (default value 5).
2 Likes

Brave has surrendered! Hooray! In fact, their writeup on Github mentions that Firefox finally agreed, and that Brave was standing alone in its refusal. They’ve acknowledged that the privacy concerns they had (which were far above my understanding) have been partially addressed, and their remaining reservations of imagined exploits would be more easily accomplished by other means. (BTW, I do not object to imagining exploits; that’s key to security going forward, and developers should always try to imagine how their systems can be misused.)

Their version 1.78.84 (which is a beta release as of this post) now supports text fragments for deep linking on web pages. Someone going by MadhaviSeelam has tested it and it works. So it’s coming soon to the release version.

1 Like

It wasn’t working for me in Safari 18.4, but then I realized that StopTheMadness Pro has a “stop scroll to text fragment” rule. I had to turn that off.

2 Likes

@ace, MacRumors apparently read your advice. :+1:
But credit it, they don’t. :frowning:

From today (posted less than an hour ago):

3 Likes