Power Your Software Testing with AI Agents and Cloud
The Native AI-Agentic Cloud Platform to Supercharge Quality Engineering. Test Intelligently and Ship Faster.
- TestMu AI (Formerly LambdaTest)
- /
- Learning Hub
- /
- Scroll to Text Fragment: Browser Support, Syntax
Scroll to Text Fragment: Browser Support, Syntax
Scroll to Text Fragment works in Chrome 80+, Edge 83+, Firefox 131+, Safari 16.1+, Opera 67+, and Samsung Internet 13+. See the full browser compatibility.
Published on:
Scroll to Text Fragment is a WICG URL directive that lets a link highlight a specific text snippet on a page through the #:~:text= syntax. It works in Chrome 80+, Edge 83+, Opera 67+, Samsung Internet 13+, Firefox 131+, and Safari 16.1+ on macOS and iOS, while Internet Explorer never added support.
This guide covers what Scroll to Text Fragment is, the browsers that support it, the syntax, how to create a link, the security restrictions, and the known issues.
What is Scroll to Text Fragment?
Scroll to Text Fragment is a Web Incubator Community Group (WICG) URL fragment directive that scrolls a page to and highlights a text snippet specified after #:~:text= in the URL. The browser strips the directive from document.URL after parsing, so the target page cannot read it.
Which browsers does Scroll to Text Fragment support?
Scroll to Text Fragment ships in every modern engine, with Chromium browsers leading the rollout, Safari following on macOS and iOS, and Firefox arriving last. Internet Explorer and Opera Mini never implemented the directive.
Scroll to Text Fragment compatibility in Chrome
Chrome supports Scroll to Text Fragment from Chrome 80 on Windows, macOS, Linux, ChromeOS, and Android. Chrome 74 to 79 had the directive disabled by default behind an Experimental Web Platform Features flag, and Chrome 73 and earlier did not support it.
Scroll to Text Fragment compatibility in Edge
Microsoft Edge supports Scroll to Text Fragment from Edge 83 on Windows, macOS, and Linux through the Chromium engine. Edge 79 to 82 had the directive disabled by default, and Edge Legacy 12 to 18 did not support it.
Scroll to Text Fragment compatibility in Firefox
Firefox supports Scroll to Text Fragment from Firefox 131 on Windows, macOS, Linux, and Android. Firefox recognizes the directive, scrolls to the match, and highlights the range. Firefox 130 and earlier ignore #:~:text= and scroll to the top of the document.
Scroll to Text Fragment compatibility in Safari
Safari supports Scroll to Text Fragment from Safari 16.1 on macOS, iOS, and iPadOS. Safari 18.2 added link generation through the Share menu, so users can copy a text fragment URL directly. Safari 16.0 and earlier on macOS, and the matching iOS Safari builds, ignore the directive.
Scroll to Text Fragment compatibility in Opera
Opera supports Scroll to Text Fragment from Opera 67 on Windows, macOS, and Linux through Blink. Opera 66 had the directive disabled by default behind an experimental flag, and Opera 65 and earlier did not support it. Opera Mini does not implement the feature on any version.
Scroll to Text Fragment compatibility in Samsung Internet
Samsung Internet supports Scroll to Text Fragment from Samsung Internet 13 on Galaxy phones and tablets. Samsung Internet 12 and earlier do not parse the directive and scroll to the top of the page.
Scroll to Text Fragment compatibility in Android Browser
The current Chrome for Android build supports Scroll to Text Fragment from Chrome 80 on Android 5.0 and later. The legacy Android Browser shipped with Android 4.4.4 and earlier did not implement the directive and ignores any #:~:text= value on the URL.
Scroll to Text Fragment compatibility in Internet Explorer
Internet Explorer 5.5 through Internet Explorer 11 never supported Scroll to Text Fragment. Microsoft has retired Internet Explorer, so any legacy intranet that needs deep linking into a specific phrase has to fall back to id-anchor fragments or a server-rendered hash that points at a known DOM node.
Note: Scroll to Text Fragment behaves differently across Safari builds, Firefox versions, and Chromium flag states. Test it on real browsers and OS with TestMu AI. Try TestMu AI free!
What is the syntax of Scroll to Text Fragment?
The directive sits after the regular URL fragment, separated by the :~: delimiter, and the value follows the text= keyword. The browser strips :~: and everything after it from the visible URL once the page loads.
- Single phrase: #:~:text=hello%20world targets the first match of the phrase hello world on the page.
- Range match: #:~:text=start%20here,end%20there highlights every character from the start phrase to the end phrase, including the phrases themselves.
- Prefix and suffix: #:~:text=before-,target,-after lets you disambiguate repeated phrases by anchoring the match to the surrounding context. The prefix and suffix are not highlighted.
- Multiple directives: Chain ranges with an ampersand, for example #:~:text=first&text=second, to highlight several phrases on the same page.
- Reserved character encoding: Encode comma as %2C, hyphen as %2D, ampersand as %26, and space as %20 inside the directive value, otherwise the parser splits on those characters.
- Combined with id fragment: #section-2:~:text=hello tells the browser to find the text inside the section-2 anchor first, then highlight the match.
How do you create a Scroll to Text Fragment link?
Modern browsers ship a built-in command for this; older browsers need an extension or a small script. Either path produces a regular URL you can share like any other link.
- Select the target text: Highlight the phrase you want the link to scroll to. Keep the selection inside one block-level element so the matcher can find it.
- Use the native context menu: In Chrome 90+, Edge 90+, and Safari 18.2+, right-click the selection and choose Copy Link to Highlight. The browser builds the #:~:text= URL and copies it to the clipboard.
- Install an extension on Firefox: Firefox does not yet generate links from the menu, so install the Text Fragment add-on from addons.mozilla.org and use its toolbar button on the highlighted selection.
- Run a bookmarklet on any browser: If extensions are blocked, paste the JavaScript snippet below into the DevTools console after selecting text, and it logs a ready-to-share URL.
- Verify the link in a fresh tab: Paste the copied URL into a new tab. The browser should scroll to the phrase and highlight it. If the page jumps to the top, re-check the encoding and confirm the phrase still exists on the live HTML.
// Build a Scroll to Text Fragment URL from the current text selection.
// Paste this into the DevTools console on any page after selecting some text.
function buildTextFragmentUrl() {
const selection = window.getSelection();
if (!selection || selection.isCollapsed) {
console.log("Select some text on the page first, then run again.");
return null;
}
const phrase = selection.toString().trim();
const encoded = encodeURIComponent(phrase)
.replace(/-/g, "%2D")
.replace(/,/g, "%2C")
.replace(/&/g, "%26");
const url = window.location.origin + window.location.pathname + "#:~:text=" + encoded;
console.log("Open this URL in a new tab to jump back to the highlighted text:");
console.log(url);
return url;
}
buildTextFragmentUrl();What are the security restrictions of Scroll to Text Fragment?
The directive carries side-channel risk because the highlight signal can leak information about page content to the referring origin. The spec and every shipping engine apply four hard restrictions to keep that risk bounded.
- User-initiated navigation only: The browser activates the text directive only on a top-level navigation that started from a click, a tap, or an address-bar entry. Scripted location.assign and history.pushState calls do not trigger the highlight.
- Main frame only: Iframes, AMP frames, and ad slots ignore #:~:text=. The directive is dropped before the embedded document parses the URL, so a sub-frame cannot deep-link into its host.
- Cross-origin opener isolation: A cross-origin link must use rel="noopener" on the anchor or pass noopener to window.open. Without it, Chrome and Edge silently strip the directive to prevent the opener from reading scroll position.
- Stripped from document.URL: The browser hides the :~: portion from JavaScript, so the target page cannot read the fragment, log it, or echo it back to a server through document.URL or window.location.hash.
- Document-Policy opt-out: A site can send Document-Policy: force-load-at-top in its response headers to opt the entire page out of text fragments. The browser then ignores every directive on inbound URLs.
What are the known issues with Scroll to Text Fragment?
The directive is stable on every modern engine, but the matching algorithm and the security boundary still produce predictable failures in production. Most issues trace back to encoding, block-level boundaries, or page mutation after publication.
- Single block boundary: The matched range cannot cross a block-level element. A phrase that spans a paragraph break or a heading falls back to the prefix-only match, and a range across two paragraphs never highlights.
- Stale links after content edits: If the page text changes by even one character, the link no longer matches. Editorial teams that auto-update copy break inbound text fragment links the moment they republish.
- Single-page app navigation: Frameworks that intercept clicks with router-level navigation skip the user-initiated path. The directive then never fires, even though the URL contains it.
- PDFs and non-HTML responses: The directive only applies to HTML documents. PDF viewers, plain text responses, and image responses ignore #:~:text= entirely.
- Encoding traps: Forgetting to escape the comma in a phrase splits the directive into a range, and forgetting to escape the hyphen turns the start phrase into a prefix. Both produce an empty match with no error.
- Highlight color clashes: The default browser highlight color is yellow on Chromium and pink on Safari. Pages with similar background colors render the highlight invisible, and there is no CSS hook to restyle it across engines.
In my experience, the trap that bites teams hardest is shipping text fragment links from a marketing CMS that auto-rewrites apostrophes and dashes to typographic versions on publish, which silently breaks every inbound link the moment the post goes live.
Citations
All Scroll to Text Fragment version numbers and platform notes in this guide come from these primary sources:
- MDN Web Docs - Text fragments: developer.mozilla.org/en-US/docs/Web/URI/Reference/Fragment/Text_fragments
- WICG URL Fragment Text Directives specification: wicg.github.io/scroll-to-text-fragment
- WICG Scroll to Text Fragment proposal repository: github.com/WICG/scroll-to-text-fragment
- Chrome Platform Status - Scroll to Text Fragment: chromestatus.com/feature/4733392803332096
- web.dev - Boldly link where no one has linked before: web.dev/articles/text-fragments
- Mozilla Bugzilla 1753933 - Implement Text Fragments: bugzilla.mozilla.org/show_bug.cgi?id=1753933
- Mozilla Firefox 131 release notes: mozilla.org/en-US/firefox/131.0/releasenotes
- WebKit blog - Scroll to text fragment in Safari: webkit.org/blog/13152/webkit-features-in-safari-16-1
- Apple Developer - Safari 18.2 release notes: developer.apple.com/documentation/safari-release-notes/safari-18_2-release-notes
- Microsoft Learn - Microsoft Edge web platform: learn.microsoft.com/en-us/microsoft-edge/web-platform
- Wikipedia - URI fragment: en.wikipedia.org/wiki/URI_fragment
- WHATWG URL Standard: url.spec.whatwg.org
Author
Prince Dewani is a Community Contributor at TestMu AI specializing in AI agents, software testing, QA, and SEO. He is certified in Selenium, Cypress, Playwright, Appium, Automation Testing, and KaneAI, and presented academic research on AI agents at PBCON-01. At TestMu AI, he has also carried out extensive cross-browser research on the support of modern web technologies such as WebGPU, WebAssembly, WebXR, WebGL2 and other web technologies, validating their compatibility and feature parity across major browsers and rendering engines through rigorous hands-on testing. Prince has hands-on experience building AI agent workflows using Anthropic Claude, Google Antigravity, n8n, LangChain, and other agentic frameworks, and works regularly with MCP and A2A protocols. He shares his work with 5,500+ QA engineers, developers, DevOps experts, tech leaders, and AI agent practitioners on LinkedIn.
Frequently asked questions
Did you find this page helpful?
More Related Blogs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance
- Advanced access controls
- Advanced data retention rules
- Advanced Local Testing
- Premium Support options
- Early access to beta features
- Private Slack Channel
- Unlimited Manual Accessibility DevTools Tests





