🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
UI libraries / InstantSearch.js / Widgets
Signature
poweredBy({
  container: string|HTMLElement,
  // Optional parameters
  theme: string,
  cssClasses: object,
});
Import
1
import { poweredBy } from 'instantsearch.js/es/widgets';

About this widget

The poweredBy widget is used to display the Algolia logo to redirect to algolia.com.

Algolia requires that you use this widget if you’re on a community plan (open source, not-for-profit, or DocSearch).

Examples

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

Options

Parameter Description
container
type: string|HTMLElement
Required

The CSS Selector or HTMLElement to insert the widget into.

1
2
3
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
poweredBy({
  // ...
  theme: 'dark',
});
cssClasses
type: object
default: {}
Optional

The CSS classes you can 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
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 with connectPoweredBy

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

To use connectPoweredBy, you can import it with the declaration relevant to how you installed InstantSearch.js.

1
import { connectPoweredBy } from 'instantsearch.js/es/connectors';

Then it’s a 3-step process:

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

// 2. Create the custom widget
const customPoweredBy = 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

Parameter Description
url
type: string

The URL to redirect to.

Powered by Algolia</a> `; }; " class="snippet-body ">
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 = connectPoweredBy(
  renderPoweredBy
);

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

Instance options

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

The URL to redirect to.

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

Full example

Powered by Algolia</a> `; }; // Create the custom widget const customPoweredBy = connectPoweredBy( renderPoweredBy ); // Instantiate the custom widget search.addWidgets([ customPoweredBy({ container: document.querySelector('#powered-by'), }) ]);" class="snippet-body ">
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 = connectPoweredBy(
  renderPoweredBy
);

// Instantiate the custom widget
search.addWidgets([
  customPoweredBy({
    container: document.querySelector('#powered-by'),
  })
]);
Did you find this page helpful?