Skip to main content

About this widget

Displays the highlighted attributes of your search results.

Explore example code

Browse the Highlighting example code on GitHub.

Examples

Consider a movies . Each movie record consists of two fields: title and year. Algolia’s response to the query “red” could look like:
JSON
Consider the _highlightResult’s value: "The Shawshank <em>Red</em>emption". The part of the string to highlight is marked with <em> tags or your custom tags. HighlightedString is constructed with a raw tagged string, detects the tags and creates a TaggedString. This tagged string provides following properties:
  • input. The input string.
  • output. The input string without its tags.
  • taggedRanges. A list of ranges defining highlighted ranges in output.
You can build a highlighted string in iOS is with an NSAttributedString. InstantSearch provides HighlightedString and NSAttributedString extensions to simplify this.
Swift
The produced NSAttributedString can be assigned to a UIKit component that supports it.
Swift
The Hit wrapper structure uses the HighlightedString structure. You can extract a highlighted string for an attribute using its hightlightedString(forKey key: String) function. Example:
Swift
You can read more about usage of the Hit wrapper structure in the Hits reference.
Last modified on July 10, 2026