---
title: "Jumping to the Matching Text from Search Results"
description: "Search results in your Knowledge Base now open articles at the sentence that matched, highlighted, so readers land on the answer instead of the top of the page."
url: "https://support.helpdocs.io/article/5mj1r5mlz2-jumping-to-the-matching-text-from-search-results"
category: "Managing Content"
updated_at: "2026-10-21T17:27:24Z"
---

# Jumping to the Matching Text from Search Results

Long articles are great for covering a topic properly, but not so great when a reader only needs one sentence of it. Now when someone clicks a search result, the article opens scrolled to the passage that matched their search, with it highlighted, so they land right on the answer. ✨

There's nothing to switch on. It works automatically in every built-in template.

### Where It Works

Results link to the matching text in:

- The full search results page
- The search dropdown that appears as you type
- Instant search
- Suggested articles in the contact form

[Ask AI](/article/2igy0wvoj4-understanding-ask-ai) sources and the [Lighthouse](/article/cgz4k4miyd-understanding-lighthouse) widget still open articles at the top.

### How It Works

When a search matches an article, we pick the sentence that best matches what the reader typed and add a [text fragment](https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Fragment/Text_fragments) to the end of the result's link. It looks something like this:

```bash
/article/abc123-custom-domains#:~:text=Add%20a%20CNAME%20record
```

The reader's browser uses that to scroll to the sentence and highlight it. Your article URLs themselves don't change, so anything that links to your articles keeps working exactly as before.

A few things are worth knowing:

- **Title matches open at the top.** If an article's title already contains everything the reader searched for, the whole article is the answer, so it opens at the top as normal.
- **Sentences with variables are skipped.** If a sentence contains a [variable](/article/0ass9d069f-understanding-variables), we pick a different one, since the text on the page won't match what's in the search index.
- **If the text can't be found, nothing breaks.** The article simply opens at the top, just as it did before.

### Browser Support

Text fragments work in Chrome, Edge, Safari 16.1 and later, and Firefox 131 and later. Readers on other browsers get a regular link to the article.

Adding it to a custom template

If you use a [custom HTML template](/article/l8q1fmsnx7-getting-started-with-a-custom-html-template), your search results won't change until you opt in. Each search result has a `text_fragment` property. Add it straight after `relative_url` in your result links.

In `search.hbs`:

```html
<a href="{{this.relative_url}}{{this.text_fragment}}">{{this.title}}</a>
```

If you override the instant search result template in `default.hbs`, escape the braces like the rest of that template:

```html
<a href="\{\{relative_url\}\}\{\{text_fragment\}\}">\{\{title\}\}</a>
```

Always put `text_fragment` at the very end of the link. It starts with `#`, so anything added after it, like a query string, will stop it working.

`text_fragment` is empty when there's no good sentence to link to, so you don't need to check for it first.
