Build a Searchable Project Directory with HTML, CSS, and JavaScript

By CampCodes Administrator

Updated on:

A project list becomes more useful when readers can narrow it down. In this lesson, you will build a small directory with a search box, a language filter, a result count, and a clear message when nothing matches.

The links are ordinary HTML. JavaScript only filters the list already on the page, so the projects remain available if the script fails or is disabled. There is no database or search service behind this example.

Start with three files

Create a folder named project-directory and save index.html, style.css, and app.js inside it. Use a current browser and a text editor. Basic HTML and JavaScript knowledge is enough; there is no build step.

A title search and language choice narrow three project rows to one matching result.
Both filters apply to the same list. Clearing them restores every project.

Save this as index.html. Each project has a language value in a data attribute. Its title and description are the searchable text. The form has visible labels, and the count is a status message rather than a popup.

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Find a small project</title>
<link rel="stylesheet" href="style.css">
<script type="module" src="app.js"></script>
<main>
  <header><p class="eyebrow">A weekend of practice</p>
    <h1>Find a small project.</h1>
    <p>Pick one idea, run the example, then change something.</p>
  </header>
  <form id="filters" role="search" aria-label="Filter projects">
    <div><label for="query">Search titles and descriptions</label>
      <input id="query" type="search" placeholder="Try files or tasks"></div>
    <div><label for="language">Language</label>
      <select id="language"><option value="all">All languages</option>
        <option value="javascript">JavaScript</option><option value="python">Python</option>
        <option value="php">PHP</option></select></div>
    <button type="reset">Clear filters</button>
  </form>
  <p id="count" role="status" aria-live="polite">3 projects</p>
  <ul id="projects">
    <li data-language="javascript"><span>JavaScript</span>
      <h2><a href="https://www.campcodes.com/tutorials/javascript-how-to-use-fetch-api-in-a-real-project/">Fetch task list</a></h2>
      <p>Read a JSON file and show tasks, loading feedback, and useful errors.</p></li>
    <li data-language="python"><span>Python</span>
      <h2><a href="https://www.campcodes.com/mini-projects/python-mini-projects/python-build-a-python-csv-cleaner-for-beginners/">CSV contact cleaner</a></h2>
      <p>Clean local contact files and remove duplicate rows.</p></li>
    <li data-language="php"><span>PHP</span>
      <h2><a href="https://www.campcodes.com/tutorials/php-how-to-use-pdo-in-a-real-project/">SQLite task list</a></h2>
      <p>Store and search tasks with prepared database statements.</p></li>
  </ul>
  <p id="empty" hidden>No matching projects. Try a shorter search or another language.</p>
  <noscript><p>Filtering needs JavaScript. All three project links are available above.</p></noscript>
</main>
</html>

Give the controls room to work

Save the stylesheet as style.css. The form wraps when the screen gets narrow, and each control has a minimum height of 44 pixels. The links keep their underlines. Keyboard focus has a visible outline, including on the reset button.

* { box-sizing: border-box; }
body { margin: 0; background: #f5f3eb; color: #183c31;
  font: 1rem/1.6 system-ui, sans-serif; }
main { max-width: 900px; margin: auto; padding: 48px 24px; }
h1 { font-size: clamp(2.2rem, 6vw, 4rem); line-height: 1.1; margin: 12px 0; }
h2 { font-size: 1.3rem; margin: 4px 0; }
.eyebrow { font-weight: 700; }
form { display: flex; flex-wrap: wrap; gap: 16px; align-items: end;
  margin-top: 32px; padding: 20px; background: #fff; border: 1px solid #bac9bf; }
form div:first-child { flex: 1 1 280px; }
label { display: block; font-weight: 650; margin-bottom: 6px; }
input, select, button { font: inherit; min-height: 44px; padding: 8px 12px;
  max-width: 100%; border: 1px solid #688174; border-radius: 4px; }
input { width: 100%; }
button { background: #1d5944; color: #fff; cursor: pointer; }
ul { list-style: none; padding: 0; }
li { padding: 22px 0; border-bottom: 1px solid #bac9bf; }
li span { font-size: .85rem; font-weight: 700; }
li p { margin: 6px 0; }
a { color: #14533c; text-underline-offset: 3px; }
:focus-visible { outline: 3px solid #af4b17; outline-offset: 4px; }
[hidden] { display: none !important; }

The final hidden rule is intentional. When a result does not match, JavaScript sets its hidden property. A future stylesheet should not accidentally override that state and display the row anyway.

Apply both filters in one place

Save this module as app.js. The matching function receives data and returns a boolean. The update function then hides or shows each row, counts the visible results, and changes the empty message. It does not rebuild the list or insert HTML from the search field.

export function matchesProject(project, query, language) {
  const term = query.trim().toLocaleLowerCase('en');
  return (language === 'all' || project.language === language)
    && project.text.toLocaleLowerCase('en').includes(term);
}

if (typeof document !== 'undefined') {
  const form = document.querySelector('#filters');
  const query = document.querySelector('#query');
  const language = document.querySelector('#language');
  const rows = [...document.querySelectorAll('#projects > li')];
  const count = document.querySelector('#count');
  const empty = document.querySelector('#empty');

  function update() {
    let visible = 0;
    for (const row of rows) {
      const match = matchesProject({
        language: row.dataset.language, text: row.textContent
      }, query.value, language.value);
      row.hidden = !match;
      if (match) visible += 1;
    }
    count.textContent = `${visible} ${visible === 1 ? 'project' : 'projects'}`;
    empty.hidden = visible !== 0;
  }

  form.addEventListener('submit', event => event.preventDefault());
  form.addEventListener('input', update);
  form.addEventListener('change', update);
  form.addEventListener('reset', () => {
    // The reset event fires before the browser restores the input values.
    setTimeout(update, 0);
  });
  update();
}

Run it and try a few searches

Open a terminal in the folder and run python3 -m http.server 8000 --bind 127.0.0.1. On Windows your Python command may be py. Visit http://127.0.0.1:8000 in Firefox or another current browser. Stop the local server with Ctrl+C when finished. JavaScript modules should be served over HTTP rather than opened as local file URLs.

  • With no filters, the count is 3 projects.
  • Search for FILES, with or without surrounding spaces. Only the Python cleaner matches.
  • Choose JavaScript while that search remains. The count becomes 0 projects and the empty message appears.
  • Press Clear filters. All three rows return and the search field is empty.

Searching is case-insensitive substring matching. A short query can match anywhere in the title, language label, or description. It does not rank results, correct spelling, or search linked articles. Those choices are useful to state before a directory grows.

Why reset needs a small delay

The browser dispatches the reset event before it restores the form’s original values. Updating immediately inside that event would read the old search. Scheduling the update for the next task lets the native reset finish first. The submit handler also prevents Enter in the search box from navigating away from this local filter.

The status paragraph announces the new count without moving focus. A reader can continue typing or tab to the next control. The empty message explains how to recover instead of leaving an unexplained blank space.

Add a fourth project

Duplicate a list item in the HTML, set its data-language to an existing option, and replace the link, title, and description. The script reads the rows on startup, so a page reload includes it automatically. To introduce another language, add a matching select option too. Keep the option value and data attribute identical.

For a large catalog, send filters to the server and paginate results there. This version intentionally searches only the few rows loaded in the browser. Do not promise readers that it searches an entire website.

Download all the example files

The ZIP contains this original CampCodes example, a README, and an MIT license. No account, package installation, or paid service is needed.

References and verification

The HTML standard describes form reset timing. This guide was rewritten with AI assistance on October 22, 2026. Automated checks covered matching, whitespace, letter case, language combinations, and no matches. The page was also checked in Firefox for filtering, the empty result, and reset. The example uses only local filtering; linked lessons are separate pages.

Leave a Comment