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

Import

About this widget

Use the frequentlyBoughtTogether widget to display a list of frequently bought together items. See also: Set up Algolia Recommend

Examples

JavaScript
Display the frequentlyBoughtTogether widget as a scrollable carousel.
JavaScript

Options

container
string | HTMLElement
required
The CSS Selector or HTMLElement to insert the widget into.
objectIDs
string[]
required
The list of objectIDs to get recommendations for. If you specify multiple objectIDs, you’ll get a single set of aggregated results from the requests, ordered by their score.
Each objectID you pass in the array counts towards the number of requests in your pricing plan. For example, if you want recommendations for the array ["A", "B", "C"], you’ll consume three requests from your quota, not one.
JavaScript
limit
number
The number of recommendations 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
threshold
number
The threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned.
JavaScript
queryParameters
Omit<SearchParameters, 'page' | 'hitsPerPage' | 'offset' | 'length'>
List of search parameters to send.
JavaScript
escapeHTML
boolean
default:true
Escapes HTML entities from recommendations string values.
JavaScript
templates
object
The templates to use for the widget.
JavaScript
cssClasses
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 recommendations.
  • item. The list item.
JavaScript
transformItems
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.
empty
string | function
The template to use when there are no recommendations.
header
string | function
The template to use for the recommendations header. This template receives the recommendations as well as the cssClasses object.
item
string | function
The template to use for each recommendation. This template receives an object containing a single record.
layout
function
since: v4.74.0
The template to use to wrap all items.InstantSearch.js provides an out-of-the-box carousel layout template with the following options:cssClasses:
  • root. The carousel’s root element.
  • list. The list of recommendations.
  • item. The list item.
  • navigation. The navigation controls.
  • navigationPrevious. The “Previous” navigation control.
  • navigationNext. The “Next” navigation control.
templates:
  • previous. The content of the “Previous” navigation control.
  • next. The content of the “Next” navigation control.

HTML output

HTML

Customize the UI with connectFrequentlyBoughtTogether

If you want to create your own UI of the frequentlyBoughtTogether widget, you can use connectors. To use connectFrequentlyBoughtTogether, 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

items
object[]
The matched recommendations from the Algolia API.
JavaScript
widgetParams
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

objectIDs
string[]
required
The list of object IDs for which to get recommendations. If you specify multiple object IDs, you’ll get a single set of aggregated results from the requests, ordered by their score.
Each objectID you pass in the array counts towards the number of requests in your pricing plan. For example, if you want recommendations for the array ["A", "B", "C"], you’ll consume three requests from your quota, not one.
JavaScript
limit
number
The number of recommendations 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
threshold
number
The threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned.
JavaScript
queryParameters
Omit<SearchParameters, 'page' | 'hitsPerPage' | 'offset' | 'length'>
List of search parameters to send.
JavaScript
escapeHTML
boolean
default:true
Escapes HTML entities from recommendations string values.
JavaScript
transformItems
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 10, 2026