Text fragments let you create links that highlight specific text on a webpage. This feature is especially useful for sharing or referencing specific parts of a webpage, as it works without requiring the webpage owner to modify the site. When someone clicks your link, their browser will automatically scroll to the target text and highlight it, making it easy to draw attention to the exact content you want to share.
Create and use text fragment URLs in Firefox
Creating text fragment URLs involves selecting the text you want to highlight and adding the right parameters to the URL. Here’s how you can do it step by step.
- Find the specific text on the webpage that you want to highlight
- Add a text fragment to the webpage URL using the following syntax:
[base-URL]#:~:text=[highlighted-text]
For example:
- https://support.mozilla.org/en-US/kb/firefox-dns-over-https#:~:text=address%20bar (scrolls to and highlights the first instance of the text address bar in the Firefox DNS over HTTPS document.)
Explanation of syntax
-
#:~:
Indicates the start of the text fragment in the URL. -
text=
Specifies the exact text to highlight.
Optional parameters
To improve precision or handle ambiguous matches, use additional parameters:
-
textStart
Defines the start of the highlighted text. -
textEnd
Defines the end of the highlighted text. -
prefix-
Text that immediately precedes the highlighted range. -
-suffix
Text that immediately follows the highlighted range.
Example with additional parameters:
Practical examples
- Highlight a single word:
- Highlights the word “example”.
- Highlight a range of text:
- Highlights the text “Text Fragments are useful”.
- Add context for ambiguous matches:
- Ensures the specific phrase is highlighted, even if similar text exists on the page.
Common questions
What happens if the text I’m linking to changes?
If the text on the webpage is removed or significantly altered, the text fragment may no longer work. To make your link more reliable, consider using additional parameters like prefix or suffix to provide context for the browser. If no match is found, the link will default to scrolling to the top of the page or to a specified fallback fragment (if included).
Do text fragments work in all browsers?
Text fragments are supported by most modern browsers, including Firefox, Chrome, Edge, Safari, and Opera. However, users of older browsers or incompatible versions may not see the highlighted text. Make sure your recipients are using a supported browser for the best experience.
Can I use text fragments for non-text elements like images or videos?
No, text fragments only work with selectable text on a webpage. They cannot highlight or link to non-text elements such as images, videos, or interactive content.