Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS

W3.CSS Filters

Share

Filter HTML Elements

With a little JavaScript, you can filter W3.CSS tables, lists, dropdowns, and other content.

The examples below filter elements as the user types in an input field.

Filter Tables

Use JavaScript to hide table rows that do not match the text entered in an input field:

Example

Name Country
Alfreds FutterkisteGermany
Berglunds snabbkopSweden
Island TradingUK
Koniglich EssenGermany
Laughing Bacchus WinecellarsCanada
Magazzini Alimentari RiunitiItaly
North/SouthUK
Paris specialitesFrance
Try It Yourself »


Filter Lists

The same technique can be used to filter list items:

Example

  • Adele
  • Agnes
  • Billy
  • Bob
  • Calvin
  • Christina
  • Cindy
Try It Yourself »

Filter Dropdowns

You can also filter links inside a dropdown.

The JavaScript reads the text in the input field and hides links that do not match.


Modern Filter Pattern

The basic pattern is:

Example

const filter = input.value.toLowerCase();

items.forEach(item => {
  item.style.display =
    item.textContent.toLowerCase().includes(filter)
    ? "" : "none";
});

The includes() method checks whether the text contains the search value.

The textContent property reads the visible text without treating it as HTML.


Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@Learn Html

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@Learn Html

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.