# Tailwind Plus Elements Documentation
Tailwind Plus Elements is a JavaScript UI component library that powers all the interactive behavior in our HTML snippets. It has no dependencies on JavaScript frameworks like React, and works with any modern stack—Next.js, Rails, Laravel, Svelte, Astro, or even plain HTML.
## Available components
Tailwind Plus Elements includes the following UI components:
- [Autocomplete](#autocomplete)
- [Command palette](#command-palette)
- [Dialog](#dialog)
- [Disclosure](#disclosure)
- [Dropdown menu](#dropdown-menu)
- [Popover](#popover)
- [Select](#select)
- [Tabs](#tabs)
## Browser support
Elements targets the same modern browsers supported by Tailwind CSS v4.0, and relies on the following minimum versions:
- **Chrome 111** _(released March 2023)_
- **Safari 16.4** _(released March 2023)_
- **Firefox 128** _(released July 2024)_
## Installing in your project
The easiest way to install Elements is via the CDN. To do this, add the following script to your project's `
` tag:
```html
```
Alternatively, if you have a build pipeline you can also install it via npm:
```bash
npm install @tailwindplus/elements
```
Next, import Elements into your root layout:
```js
import '@tailwindplus/elements'
```
## Detecting when ready
Sometimes you may want to add additional functionality to the Elements' components using JavaScript. To do this you must ensure that Elements has been loaded and is ready before interacting with it. You can do this by listening to the `elements:ready` event on the `window` object:
```js
function myFunction() {
let autocomplete = document.getElementById('autocomplete')
// Do something with the autocomplete element
}
if (customElements.get('el-autocomplete')) {
myFunction()
} else {
window.addEventListener('elements:ready', myFunction)
}
```
## Autocomplete
The `` component is a text input that allows users to enter arbitrary values or select from a list of filtered suggestions. It behaves like a native``, but offers greater control over styling.
### Component API
#### ``
The main autocomplete component that manages form integration, filtering, and coordinates with its child components
| Type | Name | Description |
| ------------------------- | -------------- | ----------------------------------------- |
| CSS variables (Read-only) | --input-width | Provides the width of the input element. |
| CSS variables (Read-only) | --button-width | Provides the width of the button element. |
#### ``
The options container that handles the popover behavior.
| Type | Name | Description |
| --------------------------- | --------------- | ------------------------------------------------------------------------------------------ |
| Attributes | popover | Required to enable the popover behavior. |
| Attributes | anchor | Configures the way the options are anchored to the button. |
| Attributes | anchor-strategy | Sets the `position` CSS property of the popover to either `absolute` (default) or `fixed`. |
| CSS variables | --anchor-gap | Sets the gap between the anchor and the popover. |
| CSS variables | --anchor-offset | Sets the distance that the popover should be nudged from its original position. |
| Data attributes (Read-only) | data-closed | Present before transitioning in, and when transitioning out. |
| Data attributes (Read-only) | data-enter | Present when transitioning in. |
| Data attributes (Read-only) | data-leave | Present when transitioning out. |
| Data attributes (Read-only) | data-transition | Present when transitioning in or out. |
| Methods | togglePopover() | Toggles the options visibility. |
| Methods | showPopover() | Shows the options. |
| Methods | hidePopover() | Hides the options. |
#### ``
Individual selectable option within the autocomplete.
| Type | Name | Description |
| --------------------------- | ------------- | ------------------------------------------------- |
| Attributes | value | The value of the option (required for selection). |
| Attributes | disabled | Whether the option is disabled. |
| ARIA attributes (Read-only) | aria-selected | Present when the option is selected. |
#### ``
Automatically displays the content of the currently selected option.
### Examples
#### Basic example
Use the `` and `` components, along with a native ` ` and ``, to build an autocomplete input:
```html
Wade Cooper
Tom Cooper
Jane Doe
```
#### Positioning the dropdown
Add the `anchor` prop to the `` to automatically position the dropdown relative to the ` `:
```html
```
Use the values `top`, `right`, `bottom`, or `left` to center the dropdown along the appropriate edge, or combine it with `start` or `end` to align the dropdown to a specific corner, such as `top start` or `bottom end`.
To control the gap between the input and the dropdown, use the `--anchor-gap` CSS variable:
```html
```
Additionally, you can use `--anchor-offset` to control the distance that the dropdown should be nudged from its original position.
#### Setting the dropdown width
The `` has no width set by default, but you can add one using CSS:
```html
```
If you'd like the dropdown width to match the ` ` width, use the `--input-width` CSS variable that's exposed on the `` element:
```html
```
#### Adding transitions
To animate the opening and closing of the dropdown, target the `data-closed`, `data-enter`, `data-leave`, and `data-transition` attributes with CSS to style the different stages of the transition:
```html
```
#### Disabling the input
To disable the input, add the `disabled` attribute to the ` `:
```html
```
## Command palette
The `` component provides a fast, keyboard-friendly way for users to search and select from a predefined list of options. It's typically displayed inside a dialog — often triggered with a `Cmd+K` shortcut — making it ideal for building power-user features like global searches.
### Component API
#### ``
The main command component that manages filtering and coordinates with its child components
| Type | Name | Description |
| ---------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Attributes | name | The form field name for the command when used in forms. |
| Attributes | value | The selected value of the command. Can be read and set programmatically. |
| Events | change | Dispatched when the active item changes. Detail contains `relatedTarget` property with the active item or `null`. |
| Methods | setFilterCallback(cb) | Allows you to customize the filtering behavior of the command. The callback receives an object with `query`, `node` and `content` properties, and should return a `boolean`. |
| Methods | reset() | Resets the command to its initial state. |
#### ``
Contains all the command items and groups. All focusable children will be considered options.
#### ``
Optional container for suggestion items that are shown when the input is empty.
#### ``
Groups related command items together.
#### ``
Optional element shown when no items match the current query.
#### ``
Optional preview content shown when a specific item is active.
| Type | Name | Description |
| ---------- | ---- | ------------------------------------------------------------- |
| Attributes | for | The `id` of the item this preview content is associated with. |
### Examples
#### Basic example
Use the ``, ``, `` components, along with a native ` `, to build a command palette:
```html
Option #1
Option #2
Option #3
No results found.
```
## Dialog
The `` component is a lightweight wrapper around the native `` element that adds scroll locking, click-outside-to-close support, and smooth exit transitions that work consistently across all browsers. It builds on standard HTML APIs while making dialogs easier to use and style.
### Component API
#### ``
Wrapper around the native `` element used to manage the open state and transitions.
| Type | Name | Description |
| --------------------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| Attributes | open | A boolean attribute that indicates whether the dialog is open or closed. You can change the attribute to dynamically open or close the dialog. |
| Data attributes (Read-only) | data-closed | Present before transitioning in, and when transitioning out. |
| Data attributes (Read-only) | data-enter | Present when transitioning in. |
| Data attributes (Read-only) | data-leave | Present when transitioning out. |
| Data attributes (Read-only) | data-transition | Present when transitioning in or out. |
| Events | open | Dispatched when the dialog is opened in any way other than by updating the `open` attribute. |
| Events | close | Dispatched when the dialog is closed in any way other than by updating the `open` attribute. |
| Events | cancel | Dispatched when the user attempts to dismiss the dialog via Escape key or clicking outside. Calling `preventDefault()` prevents the dialog from closing. |
| Methods | show() | Shows the dialog in modal mode. |
| Methods | hide() | Hides the dialog. Takes an optional object with a `restoreFocus` property to disable the default focus restoration. |
#### ``
The native dialog element.
| Type | Name | Description |
| -------- | ---------- | ------------------ |
| Commands | show-modal | Opens the dialog. |
| Commands | close | Closes the dialog. |
#### ``
The visual backdrop behind your dialog panel.
| Type | Name | Description |
| --------------------------- | --------------- | ------------------------------------------------------------ |
| Data attributes (Read-only) | data-closed | Present before transitioning in, and when transitioning out. |
| Data attributes (Read-only) | data-enter | Present when transitioning in. |
| Data attributes (Read-only) | data-leave | Present when transitioning out. |
| Data attributes (Read-only) | data-transition | Present when transitioning in or out. |
#### ``
The main content area of your dialog. Clicking outside of this will trigger the dialog to close.
| Type | Name | Description |
| --------------------------- | --------------- | ------------------------------------------------------------ |
| Data attributes (Read-only) | data-closed | Present before transitioning in, and when transitioning out. |
| Data attributes (Read-only) | data-enter | Present when transitioning in. |
| Data attributes (Read-only) | data-leave | Present when transitioning out. |
| Data attributes (Read-only) | data-transition | Present when transitioning in or out. |
### Examples
#### Basic example
Use the `` and `` components, along with a native ``, to build a dialog:
```html
Delete profile
```
#### Opening the dialog
You can open dialogs using the `show-modal` [invoker command](https://developer.mozilla.org/en-US/docs/Web/API/Invoker_Commands_API):
```html
Open dialog
```
Alternatively you can add the `open` attribute to the `` to open it:
```diff
-
+
```
You can also programmatically open the dialog using the `show()` method on ``:
```html
```
#### Closing the dialog
You can close dialogs using the `close` [invoker command](https://developer.mozilla.org/en-US/docs/Web/API/Invoker_Commands_API):
```html
Close dialog
```
Alternatively you can remove the `open` attribute from the `` to close it:
```diff
-
+
```
You can also programmatically close the dialog using the `hide()` method on ``:
```html
```
#### Adding a backdrop
Use the `` component to add a backdrop behind your dialog panel:
```html
```
The primary benefit of using the `` component over the native `::backdrop` pseudo-element is that it can be transitioned reliably using CSS.
#### Adding transitions
To animate the opening and closing of the dialog, target the `data-closed`, `data-enter`, `data-leave`, and `data-transition` attributes with CSS to style the different stages of the transition:
```html
```
## Disclosure
The `` component provides a simple, accessible way to show and hide content — ideal for building things like toggleable accordion panels or expandable sections.
### Component API
#### ``
Contains the content of the disclosure.
| Type | Name | Description |
| --------------------------- | --------------- | ------------------------------------------------------------ |
| Attributes | hidden | Whether the disclosure is initially hidden (closed). |
| Attributes | open | Automatically synced with the `hidden` attribute. |
| Data attributes (Read-only) | data-closed | Present before transitioning in, and when transitioning out. |
| Data attributes (Read-only) | data-enter | Present when transitioning in. |
| Data attributes (Read-only) | data-leave | Present when transitioning out. |
| Data attributes (Read-only) | data-transition | Present when transitioning in or out. |
| Methods | show() | Shows the disclosure. |
| Methods | hide() | Hides the disclosure. |
| Methods | toggle() | Toggles the disclosure. |
| Commands | --show | Shows the disclosure. |
| Commands | --hide | Hides the disclosure. |
| Commands | --toggle | Toggles the disclosure. |
### Examples
#### Basic example
Use the `` component, along with a native ``, to build a disclosure:
```html
What's the best thing about Switzerland?
I don't know, but the flag is a big plus.
```
#### Opening a disclosure
You can open disclosures using the `--show` [invoker command](https://developer.mozilla.org/en-US/docs/Web/API/Invoker_Commands_API):
```html
Show disclosure
```
Alternatively you can remove the `hidden` attribute to open it:
```diff
-
+
```
You can also programmatically open disclosures using the `show()` method:
```html
```
#### Closing a disclosure
You can close disclosures using the `--hide` [invoker command](https://developer.mozilla.org/en-US/docs/Web/API/Invoker_Commands_API):
```html
Hide disclosure
```
Alternatively you can add the `hidden` attribute to close it:
```diff
-
+
```
You can also programmatically close disclosures using the `hide()` method:
```html
```
#### Toggling a disclosure
You can toggle disclosures using the `--toggle` [invoker command](https://developer.mozilla.org/en-US/docs/Web/API/Invoker_Commands_API):
```html
Toggle disclosure
```
You can also programmatically toggle disclosures using the `toggle()` method:
```html
```
#### Adding transitions
To animate the opening and closing of the disclosure, target the `data-closed`, `data-enter`, `data-leave`, and `data-transition` attributes with CSS to style the different stages of the transition:
```html
```
## Dropdown menu
The `` component makes it easy to build dropdown menus with full keyboard support and built-in anchoring to control where the dropdown appears relative to its trigger.
### Component API
#### ``
Connects the button with the menu.
| Type | Name | Description |
| ------------- | ------------- | ---------------------------------------------------- |
| CSS variables | --input-width | Provides the width of the input element (read-only). |
#### ``
Contains all the menu items. All focusable children will be considered options.
| Type | Name | Description |
| --------------------------- | --------------- | ------------------------------------------------------------------------------------------------------ |
| Attributes | popover | Required to enable the popover behavior. |
| Attributes | open | Controls the open/closed state of the menu. |
| Attributes | anchor | Where to position the dropdown menu. Supports values like "bottom", "bottom-start", "bottom-end", etc. |
| Attributes | anchor-strategy | Sets the `position` CSS property of the popover to either `absolute` (default) or `fixed`. |
| CSS variables | --anchor-gap | Sets the gap between the anchor and the popover. |
| CSS variables | --anchor-offset | Sets the distance that the popover should be nudged from its original position. |
| Data attributes (Read-only) | data-closed | Present before transitioning in, and when transitioning out. |
| Data attributes (Read-only) | data-enter | Present when transitioning in. |
| Data attributes (Read-only) | data-leave | Present when transitioning out. |
| Data attributes (Read-only) | data-transition | Present when transitioning in or out. |
| Methods | togglePopover() | Toggles the menu visibility. |
| Methods | showPopover() | Shows the menu. |
| Methods | hidePopover() | Hides the menu. |
### Examples
#### Basic example
Use the `` and `` components, along with a native ``, to build a dropdown menu:
```html
Options
Edit
Duplicate
Archive
Delete
```
All focusable children within the `` component will be considered options.
## Popover
The `` component is used to display floating panels with arbitrary content — perfect for things like navigation menus and flyouts.
### Component API
#### ``
Contains the content of the popover.
| Type | Name | Description |
| --------------------------- | --------------- | ------------------------------------------------------------------------------------------------ |
| Attributes | anchor | Where to position the popover. Supports values like "bottom", "bottom-start", "bottom-end", etc. |
| Attributes | anchor-strategy | Sets the `position` CSS property of the popover to either `absolute` (default) or `fixed`. |
| Data attributes (Read-only) | data-closed | Present before transitioning in, and when transitioning out. |
| Data attributes (Read-only) | data-enter | Present when transitioning in. |
| Data attributes (Read-only) | data-leave | Present when transitioning out. |
| Data attributes (Read-only) | data-transition | Present when transitioning in or out. |
| Events | toggle | Dispatched when the popover opens or closes. |
| Methods | togglePopover() | Toggles the popover visibility. |
| Methods | showPopover() | Shows the popover. |
| Methods | hidePopover() | Hides the popover. |
#### ``
Links related popovers to prevent them from closing when focus is moved between them.
### Examples
#### Basic example
Use the `` component, along with a native ``, to build a popover:
```html
Menu A
Content A
```
#### Grouping popovers
Use the `` component to group popovers together. This prevents them from closing when focus is moved between them:
```html
Menu A
Content A
Menu B
Content B
```
## Select
The `` component is a fully accessible replacement for a native `` element, designed to give you complete control over styling.
### Component API
#### ``
Manages form integration and coordinates with its child components.
| Type | Name | Description |
| ------------------------- | ------------- | ----------------------------------------------------------------------- |
| Attributes | name | The form field name for the select when used in forms. |
| Attributes | value | The selected value of the select. Can be read and set programmatically. |
| Events | input | Dispatched when the selected option changes. |
| Events | change | Dispatched when the selected option changes. |
| CSS variables (Read-only) | --input-width | Provides the width of the input element (read-only). |
#### ``
The options container that handles the popover behavior.
| Type | Name | Description |
| --------------------------- | --------------- | ------------------------------------------------------------------------------------------ |
| Attributes | popover | Required to enable the popover behavior. |
| Attributes | anchor | Configures the way the options are anchored to the button. |
| Attributes | anchor-strategy | Sets the `position` CSS property of the popover to either `absolute` (default) or `fixed`. |
| CSS variables | --anchor-gap | Sets the gap between the anchor and the popover. |
| CSS variables | --anchor-offset | Sets the distance that the popover should be nudged from its original position. |
| Data attributes (Read-only) | data-closed | Present before transitioning in, and when transitioning out. |
| Data attributes (Read-only) | data-enter | Present when transitioning in. |
| Data attributes (Read-only) | data-leave | Present when transitioning out. |
| Data attributes (Read-only) | data-transition | Present when transitioning in or out. |
| Methods | togglePopover() | Toggles the options visibility. |
| Methods | showPopover() | Shows the options. |
| Methods | hidePopover() | Hides the options. |
#### ``
Individual selectable option within the select.
| Type | Name | Description |
| --------------------------- | ------------- | ------------------------------------------------- |
| Attributes | value | The value of the option (required for selection). |
| Attributes | disabled | Whether the option is disabled. |
| ARIA attributes (Read-only) | aria-selected | Present when the option is selected. |
#### ``
Automatically displays the content of the currently selected option.
### Examples
#### Basic example
Use the ``, `` and `` components, along with a native ``, to build a select input:
```html
Active
Active
Inactive
Archived
```
#### Positioning the dropdown
Add the `anchor` prop to the `` to automatically position the dropdown relative to the ` `:
```html
```
Use the values `top`, `right`, `bottom`, or `left` to center the dropdown along the appropriate edge, or combine it with `start` or `end` to align the dropdown to a specific corner, such as `top start` or `bottom end`.
To control the gap between the input and the dropdown, use the `--anchor-gap` CSS variable:
```html
```
Additionally, you can use `--anchor-offset` to control the distance that the dropdown should be nudged from its original position.
#### Setting the dropdown width
The `` has no width set by default, but you can add one using CSS:
```html
```
If you'd like the dropdown width to match the `` width, use the `--button-width` CSS variable that's exposed on the `` element:
```html
```
#### Adding transitions
To animate the opening and closing of the dropdown, target the `data-closed`, `data-enter`, `data-leave`, and `data-transition` attributes with CSS to style the different stages of the transition:
```html
```
#### Disabling the input
To disable the input, add the `disabled` attribute to the ``:
```html
Active
```
## Tabs
The `` component makes it easy to build accessible, keyboard-navigable tab interfaces with full control over styling and layout.
### Component API
#### ``
The main container that coordinates the tabs and panels.
| Type | Name | Description |
| ------- | ------------------- | ----------------------------- |
| Methods | setActiveTab(index) | Sets the active tab by index. |
#### ``
The container for tab buttons.
#### ``
The container for tab panels. All direct children are considered panels.
### Examples
#### Basic example
Use the ``, ``, and `` components, along with native `` elements, to build a tab group:
```html
Tab 1
Tab 2
Tab 3
Content 1
Content 2
Content 3
```
#### Setting the active tab
The initially active tab is determined by the absence of the `hidden` attribute on panels. This allows the component to work correctly with server-side rendering.
```html
Active panel
Inactive panel
Inactive panel
```