Enables interacting with features using the URL fragment directive, such as text directives (a.k.a. scroll-to-text links, e.g. example.com#:~:text=foo). This new API allows authors to work with text directives (and newly proposed directive types in the future), allowing them to better integrate their pages with "scroll-to-text" highlights and easily generate their own "scroll-to-text" links.


We’ve seen a few use cases crop up for working with text fragments: Being able to attach commentary/UI to a targeted text range Tools that wish to create text directive links of their own find it difficult since the rules around matching text are rather complicated. This API allows such tools/pages to give the browser a Range and receive a text directive string in return. Pages that use a cross-origin iframe to host content and want to enable text highlighting can coordinate between the embedder and embeddee by passing the text directive string to the embeddee and having it set the text directive on itself. The text directive is currently exposed (accidentally) on the performance API which pages can to read to achieve this behavior. An explicit API would allow us to remove the performance API hack which may enable more privacy-sensitive features to use the fragment directive mechanism.

Status in Chromium


Proposed (tracking bug)

Consensus & Standardization

After a feature ships in Chrome, the values listed here are not guaranteed to be up to date.

  • No signal
  • No signal
  • No signals


Search tags

text, scroll, fragment, directive, fragmentDirective, document,

Last updated on 2021-12-23