API Reference / InstantSearch.js Widgets / poweredBy
Widget signature
instantsearch.widgets.poweredBy({
  container: string|HTMLElement,
  // Optional parameters
  theme: string,
  cssClasses: object,
});

About this widget

The poweredBy widget is used to display the Algolia logo to redirect to our website.

Algolia requires that you use this widget if you only use your free usage credits, or are on a Community or Free legacy plan.

Examples

1
2
3
instantsearch.widgets.poweredBy({
  container: '#powered-by',
});

Options

container
type: string|HTMLElement
Required

The CSS Selector or HTMLElement to insert the widget into.

1
2
3
instantsearch.widgets.poweredBy({
  container: '#powered-by',
});
theme
type: string ("light"|"dark")
default: light
Optional

The version of the logo to use, legible on light or dark backgrounds.

1
2
3
4
instantsearch.widgets.poweredBy({
  // ...
  theme: 'dark',
});
cssClasses
type: object
default: {}
Optional

The CSS classes to override.

  • root: the root element of the widget.
  • link: the link element.
  • logo: the SVG element.
1
2
3
4
5
6
7
8
9
10
instantsearch.widgets.poweredBy({
  // ...
  cssClasses: {
    root: 'MyCustomPoweredBy',
    link: [
      'MyCustomPoweredByLink',
      'MyCustomPoweredByLink--subclass',
    ],
  },
});

HTML output

1
2
3
4
5
<div class="ais-PoweredBy ais-PoweredBy--light">
  <a href="..." target="_blank" class="ais-PoweredBy-link" aria-label="Search by Algolia" rel="noopener noreferrer">
    <!-- <svg> ... </svg> -->
  </a>
</div>

Customize the UI - connectPoweredBy

If you want to create your own UI of the poweredBy widget, you can use connectors.

It’s a 3-step process:

// 1. Create a render function
const renderPoweredBy = (renderOptions, isFirstRender) => {
  // Rendering logic
};

// 2. Create the custom widget
const customPoweredBy = instantsearch.connectors.connectPoweredBy(
  renderPoweredBy
);

// 3. Instantiate
search.addWidgets([
  customPoweredBy({
    // instance params
  })
]);

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).

const renderPoweredBy = (renderOptions, isFirstRender) => {
  const { string url, object widgetParams } = renderOptions;

  if (isFirstRender) {
    // Do some initial rendering and bind events
  }

  // Render the widget
}

Rendering options

url
type: string

The URL to redirect to.

1
2
3
4
5
6
7
const renderPoweredBy = (renderOptions, isFirstRender) => {
  const { url } = renderOptions;

  document.querySelector('#powered-by').innerHTML = `
    <a href="${url}">Powered by Algolia</a>
  `;
};
widgetParams
type: object

All original widget options forwarded to the render function.

1
2
3
4
5
6
7
8
9
10
11
12
13
const renderPoweredBy = (renderOptions, isFirstRender) => {
  const { widgetParams } = renderOptions;

  widgetParams.container.innerHTML = '...';
};

// ...

search.addWidgets([
  customPoweredBy({
    container: document.querySelector('#powered-by'),
  })
]);

Create and instantiate the custom widget

We first create custom widgets from our rendering function, then we instantiate them. When doing that, there are two types of parameters you can give:

  • Instance parameters: they are predefined parameters that you can use to configure the behavior of Algolia.
  • Your own parameters: to make the custom widget generic.

Both instance and custom parameters are available in connector.widgetParams, inside the renderFunction.

const customPoweredBy = instantsearch.connectors.connectPoweredBy(
  renderPoweredBy
);

search.addWidgets([
  customPoweredBy({
    // Optional parameters
    url: string,
  })
]);

Instance options

url
type: string
default: https://algolia.com
Optional

The URL to redirect to.

1
2
3
customPoweredBy({
  url: 'https://algolia.com/about',
});

Full example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Create the render function
const renderPoweredBy = (renderOptions, isFirstRender) => {
  const { url, widgetParams } = renderOptions;

  widgetParams.container.innerHTML = `
    <a href="${url}">Powered by Algolia</a>
  `;
};

// Create the custom widget
const customPoweredBy = instantsearch.connectors.connectPoweredBy(
  renderPoweredBy
);

// Instantiate the custom widget
search.addWidgets([
  customPoweredBy({
    container: document.querySelector('#powered-by'),
  })
]);

Did you find this page helpful?