Skip to main content
If you’re using the deprecated recommend-js UI library, see trendingFacets.
Signature

Import

About this widget

Use the trendingFacets widget to display a list of trending facet values. See also: Set up Algolia Recommend

Examples

JavaScript

Options

string | HTMLElement
required
The CSS Selector or HTMLElement to insert the widget into.
string
required
The facet attribute to get trending values for.
JavaScript
number
The number of trending facet values to retrieve. Depending on the available recommendations and the other request parameters, the actual number of items may be lower than that. If limit isn’t provided or set to 0, all matching recommendations are returned.
JavaScript
number
The threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned.
JavaScript
Omit<SearchParameters, 'page' | 'hitsPerPage' | 'offset' | 'length'>
List of search parameters to send when there aren’t enough recommendations.
JavaScript
boolean
default:true
Escapes HTML entities from recommendations string values.
JavaScript
object
The templates to use for the widget.
JavaScript
object
default:"{}"
The CSS classes you can override:
  • root. The widget’s root element.
  • emptyRoot. The container element without results.
  • title. The widget’s title element.
  • container. The container of the list element.
  • list. The list of trending facet values.
  • item. The list item.
JavaScript
function
default:"items => items"
A function that receives the list of items before they are displayed. It should return a new array with the same structure. Use this to transform, filter, or reorder the items.The function also has access to the full results data, including all standard response parameters and parameters from the helper, such as disjunctiveFacetsRefinements.
JavaScript

Templates

You can customize parts of a widget’s UI using the Templates API. Each template includes an html function, which you can use as a tagged template. This function safely renders templates as HTML strings and works directly in the browser—no build step required. For details, see Templating your UI.
The html function is available in InstantSearch.js version 4.46.0 or later.
string | function
The template to use when there are no trending facet values.
string | function
The template to use for the widget header. This template receives the items as well as the cssClasses object.
string | function
The template to use for each trending facet value. This template receives an object with facetName, facetValue, and _score.

HTML output

HTML

Customize the UI with connectTrendingFacets

If you want to create your own UI of the trendingFacets widget, you can use connectors. To use connectTrendingFacets, you can import it with the declaration relevant to how you installed InstantSearch.js.
Then it’s a 3-step process:
JavaScript

Create a render function

This rendering function is called before the first search (init lifecycle step) and each time results come back from Algolia (render lifecycle step).
JavaScript

Rendering options

object[]
The trending facet values from the Algolia Recommend API. Each item has facetName, facetValue, and _score properties.
JavaScript
object
All original widget options forwarded to the render function.
JavaScript

Create and instantiate the custom widget

First, create your custom widgets using a rendering function. Then, instantiate them with parameters. There are two kinds of parameters you can pass:
  • Instance parameters. Predefined options that configure Algolia’s behavior.
  • Custom parameters. Parameters you define to make the widget reusable and adaptable.
Inside the renderFunction, both instance and custom parameters are accessible through connector.widgetParams.
JavaScript

Instance options

string
required
The facet attribute to get trending values for.
JavaScript
number
The number of trending facet values to retrieve. Depending on the available recommendations and the other request parameters, the actual number of items may be lower than that. If limit isn’t provided or set to 0, all matching recommendations are returned.
JavaScript
number
The threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned.
JavaScript
Omit<SearchParameters, 'page' | 'hitsPerPage' | 'offset' | 'length'>
List of search parameters to send when there aren’t enough recommendations.
JavaScript
boolean
default:true
Escapes HTML entities from recommendations string values.
JavaScript
function
default:"items => items"
A function that receives the list of items before they are displayed. It should return a new array with the same structure. Use this to transform, filter, or reorder the items.The function also has access to the full results data, including all standard response parameters and parameters from the helper, such as disjunctiveFacetsRefinements.
JavaScript

Full example

Last modified on July 22, 2026