Filterable List Template
An interactive list that users can instantly filter by typing into a search field.
This component is perfect for directories, product lists, or any long list that benefits from a simple, real-time search function to help users find what they need quickly.

About this Template
This component uses vanilla JavaScript to add a useful live search feature to a standard list. It listens for the input
event on the search field and, on every keystroke, loops through the list items to show or hide them based on the user's query. The search is case-insensitive for a better user experience and includes a "no results" message for when a search returns empty.
Features
- Real-time Filtering: Updates the list instantly as the user types, with no need to press enter.
- Pure JavaScript: The functionality is lightweight and uses no external libraries like jQuery.
- Case-Insensitive Search: The search logic converts both the query and the list text to lowercase for a forgiving search experience.
- "No Results" Feedback: A message appears to inform the user when their search doesn't match any items.
- Accessible: Uses a proper
label
for the search input and ARIA attributes to connect the input to the list it controls. - Self-Contained Code: All functionality and styles are scoped to a single parent class.
Code Breakdown
The HTML consists of a search input
and an unordered list (ul
) that has an id
. The search input has an aria-controls
attribute that points to the list's id
, programmatically linking them.
The JavaScript first selects the necessary elements: the input field, all list items, and the "no results" message element. An event listener is attached to the input to fire on the input
event.
Inside the event handler, the script gets the search term and converts it to lowercase. It then iterates through each list item. For each item, it gets the item's text, converts it to lowercase, and checks if it includes the search term. Based on the result, it toggles the item's hidden
attribute. After checking all items, it updates the visibility of the "no results" message based on whether any items are currently visible.
Code
Here's the full code for the template: