Skip to main content
Signature

About this widget

The snippet function returns attributes in your search results in a shorter form (a snippet). Snippeted attributes are also highlighted. This function uses Algolia’s snippeting feature in combination with the hits or infiniteHits widgets. To determine which attributes should be snippeted, set them from the Algolia dashboard, the CLI, or with the API (using the attributesToSnippet parameter):
JavaScript
With attributesToSnippet, you can also set the snippet’s size to a specific number of words (it defaults to 10). For example, attributesToSnippet: ['description:5'].

Examples

JavaScript

Options

string
required
The attribute of the record to snippet. For deeply nested objects, specify a dot-separated value like actor.bio.
JavaScript
object
required
Original hit object provided to the function. The value is already bound to the function inside a string template, so you don’t have to provide it. For this to work, the provided object must have a _snippetResult[attribute].value property.
JavaScript
string
default:"mark"
The name of the HTML element to wrap the snippeted parts of the string.
JavaScript
string
default:"span"
The HTML element that wraps the non-highlighted parts of the string.
JavaScript
string
default:", "
The character between each item when the attribute to highlight is an array.
JavaScript
object
default:"{}"
The CSS classes you can override:
  • root. The component’s root element.
  • highlighted. The highlighted parts.
  • nonHighlighted. The non-highlighted parts.
  • separator. The separator elements between highlighted parts.
JavaScript

HTML output

HTML
Last modified on July 22, 2026