Skip to main content
The theme is a neutral and clean starter. You can use it as a base and customize it with CSS variables. If you want to build your own theme, you can start from the Classic theme and adjust it.

Installation

First, you need to install the theme.
npm install @algolia/autocomplete-theme-classic
Then import it in your project:
JavaScript
import "@algolia/autocomplete-theme-classic";
If you don’t use a package manager, you can link the style sheet in your HTML:
HTML
<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/@algolia/autocomplete-theme-classic@1.18.0/dist/theme.min.css"
  integrity="sha256-uoHLgXv1XCnxzCjK18RN9emuADqRdlAhgkBzwUS1VgM="
  crossorigin="anonymous"
/>

CSS variables

The theme uses CSS variables that you can customize in your own CSS.
All colors are defined with two variables: one for the RGB values and one for the alpha layer. This lets you adjust each value independently.

Size and spacing

NameTypeDescription
--aa-base-unitnumberBase value to calculate font sizes and spacing
--aa-spacing-factornumberBase value to calculate spacing increments
--aa-spacinglengthFixed spacing value derived from --aa-base-unit and --aa-spacing-factor
--aa-spacing-halflengthHalf of --aa-spacing
--aa-panel-max-heightlengthMaximum height for the panel before showing a vertical scrollbar

Z-index

NameTypeDescription
--aa-base-z-indexintegerBase value to calculate all z-index.

Font

NameTypeDescription
--aa-font-sizelengthFixed font size derived from --aa-base-unit
--aa-font-familystringBase font stack
--aa-font-weight-mediumnumberMedium font weight for --aa-font-family (usually 500)
--aa-font-weight-semiboldnumberSemibold font weight for --aa-font-family (usually 600)
--aa-font-weight-boldnumberBold font weight for --aa-font-family (usually 700)

Icons

NameTypeDescription
--aa-icon-sizelengthFixed icon size value
--aa-icon-stroke-widthnumberFixed icon stroke width
--aa-icon-color-rgbinteger,integer,integerRGB values for the icon color
--aa-icon-color-alphanumberAlpha value for the icon color
--aa-action-icon-sizelengthFixed action icon size value

Text colors

NameTypeDescription
--aa-text-color-rgbinteger,integer,integerRGB values for the global text color
--aa-text-color-alphanumberAlpha value for the global text color
--aa-primary-color-rgbinteger,integer,integerRGB values for the accent color
--aa-primary-color-alphanumberAlpha value for the accent color
--aa-muted-color-rgbinteger,integer,integerRGB values for the muted color
--aa-muted-color-alphanumberAlpha value for the muted color

Border colors

NameTypeDescription
--aa-panel-border-color-rgbinteger,integer,integerRGB values for the panel border
--aa-panel-border-color-alphanumberAlpha value for the panel border
--aa-input-border-color-rgbinteger,integer,integerRGB values for the input border
--aa-input-border-color-alphanumberAlpha value for the input border

Background colors

NameTypeDescription
--aa-background-color-rgbinteger,integer,integerRGB values for the background
--aa-background-color-alphanumberAlpha value for the background
--aa-input-background-color-rgbinteger,integer,integerRGB values for the input background
--aa-input-background-color-alphanumberAlpha value for the input background
--aa-selected-color-rgbinteger,integer,integerRGB values for selected, active, or focused elements
--aa-selected-color-alphanumberAlpha value for selected, active, or focused elements
--aa-description-highlight-background-color-rgbinteger,integer,integerRGB values for the description highlight background
--aa-description-highlight-background-color-alphanumberAlpha value for the description highlight background

Detached mode

NameTypeDescription
--aa-detached-media-querymedia queryMedia query to enable detached mode on smaller devices
--aa-detached-modal-media-querymedia queryMedia query to enable detached mode on bigger devices
--aa-detached-modal-max-widthlengthMaximum modal width in detached mode
--aa-detached-modal-max-heightlengthMaximum modal height in detached mode
--aa-overlay-color-rgbinteger,integer,integerRGB values for the overlay
--aa-overlay-color-alphanumberAlpha value for the overlay

Shadows

NameTypeDescription
--aa-panel-shadowbox-shadowShadow for the panel

Scrollbar

NameTypeDescription
--aa-scrollbar-widthlengthScrollbar width
--aa-scrollbar-track-background-color-rgbinteger,integer,integerRGB values for the scrollbar track
--aa-scrollbar-track-background-color-alphanumberAlpha value for the scrollbar track
--aa-scrollbar-thumb-background-color-rgbinteger,integer,integerRGB values for the scrollbar thumb
--aa-scrollbar-thumb-background-color-alphanumberAlpha value for the scrollbar thumb
To customize a value, you can create a custom style sheet and override the variable.
CSS
:root {
  --aa-icon-size: 24px;
}
Make sure to load these styles after the theme.

Templates

For the theme to work out of the box, you need to use a conventional CSS class set. All class names from the theme come with an aa- namespace to avoid interfering with your own styles.

Item

Here’s the markup for an item template.
autocomplete({
  // ...
  templates: {
    item({ item, components, html }) {
      return html`<div class="aa-ItemWrapper">
        <div class="aa-ItemContent">
          <div class="aa-ItemIcon">
            <img
              src="${item.image}"
              alt="${item.name}"
              width="40"
              height="40"
            />
          </div>
          <div class="aa-ItemContentBody">
            <div class="aa-ItemContentTitle">
              ${components.Highlight({ hit: item, attribute: "name" })}
            </div>
            <div class="aa-ItemContentDescription">
              ${components.Snippet({ hit: item, attribute: "description" })}
            </div>
          </div>
        </div>
        <div class="aa-ItemActions">
          <button
            class="aa-ItemActionButton aa-DesktopOnly aa-ActiveOnly"
            type="button"
            title="Select"
          >
            <svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor">
              <path
                d="M18.984 6.984h2.016v6h-15.188l3.609 3.609-1.406 1.406-6-6 6-6 1.406 1.406-3.609 3.609h13.172v-4.031z"
              />
            </svg>
          </button>
        </div>
      </div>`;
    },
  },
});
To wrap an item within a link, use the .aa-ItemLink class in place of the element with .aa-ItemWrapper. Make sure not to use both together.
autocomplete({
  // ...
  templates: {
    item({ item, html }) {
      return html`<a class="aa-ItemLink" href="${item.url}"> /* ... */ </a>`;
    },
  },
});
Here’s the markup for a header template.
autocomplete({
  // ...
  templates: {
    header({ html }) {
      return html`<span class="aa-SourceHeaderTitle">Products</span>
        <div class="aa-SourceHeaderLine" />`;
    },
    // ...
  },
});

No results

Here’s the markup for a noResults template.
JavaScript
autocomplete({
  // ...
  templates: {
    noResults() {
      return "No products for this query.";
    },
    // ...
  },
});

Additional CSS classes

The theme provides a set of optional classes for you to use in different contexts.

Modifiers

  • .aa-ItemIcon--noBorder removes the border of the icon
  • .aa-ItemIcon--alignTop aligns the icon to the top (recommended when the template is longer than three lines)
  • .aa-ItemIcon--picture makes the icon larger (recommended when using an image and the template is longer than three lines)
  • .aa-Panel--scrollable declares the scrollable containers of the panel

Utilities

  • .aa-ActiveOnly displays an element only when the item is active
  • .aa-DesktopOnly displays an element only on desktop devices
  • .aa-TouchOnly displays an element only on tap devices

Dark mode

The theme supports dark mode. You can enable it on the body tag in two different ways:
  • <body data-theme="dark" />
  • <body class="dark" />
I