Skip to content

Full-screen search in HTML and CSS

A search covering the page, with popular suggestions, opened from the navigation bar.

Here is an excerpt of this component's code in HTML and CSS. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in HTML and CSS

dialog.js
document.querySelectorAll("[data-dialog-open]").forEach((button) => {
  const dialog = document.getElementById(button.dataset.dialogOpen);
  button.addEventListener("click", () => dialog.showModal());
});

document.querySelectorAll("dialog").forEach((dialog) => {
  dialog.addEventListener("click", (event) => {
    if (event.target === dialog) dialog.close();
  });
  dialog.querySelectorAll("[data-dialog-close]").forEach((button) => {
    button.addEventListener("click", () => dialog.close(button.value));
  });
index.html
<!doctype html>
<html lang="fr">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Recherche plein écran</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <main class="demo">
      <button type="button" class="search-trigger" data-dialog-open="search-overlay">
        <svg viewBox="0 0 24 24" aria-hidden="true"><path d="m20 20-4.5-4.5M17 10.5a6.5 6.5 0 1 1-13 0 6.5 6.5 0 0 1 13 0Z" /></svg>
style.css
:root {
  --search-bg: #f7f3ec;
  --search-text: #2b241b;
  --search-muted: #6b5d4a;
  --search-line: #2b241b;
  --search-chip: #ebe3d6;
  --search-ring: #2b241b;
  --demo-bg: #f7f3ec;
  --demo-text: #2b241b;
}

@media (prefers-color-scheme: dark) {

Free component: copy it freely, including for commercial projects.

Modals components in HTML and CSS
  • A legal-age check window for a wine shop or brewery, accessible, remembered for the session and with the French Evin law notices.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A short form in a window to request a call from an advisor.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A small window asking to confirm an action before running it.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component