About this snippet

Offer a distraction-free search experience with this fullscreen overlay. When triggered, it covers the entire page with a clean search input and a close button, ensuring the user focuses solely on finding content.

Size
1.7 KB
Uses
HTML, CSS, JavaScript
Loads
Nothing external
Views
560
<button onclick="openSearch()" class="search-trigger">Search Website</button>

<div id="searchOverlay" class="search-overlay">
  <button class="close-btn" onclick="closeSearch()">&times;</button>
  <div class="overlay-content">
    <input type="text" placeholder="Type to search..." autofocus>
    <p>Press Enter to see results</p>
  </div>
</div>
.search-trigger {
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  padding: 10px 20px;
  background: #1f2937;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.search-overlay {
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  height: 100%;
  width: 100%;
  position: fixed;
  z-index: 1000;
  top: 0;
  left: 0;
  background-color: rgba(0,0,0, 0.95);
  display: none;
  animation: fadeIn 0.3s;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.overlay-content {
  position: relative;
  top: 25%;
  width: 80%;
  text-align: center;
  margin: auto;
}
.overlay-content input {
  padding: 15px;
  font-size: 3rem;
  border: none;
  border-bottom: 2px solid #4b5563;
  background: transparent;
  color: white;
  width: 100%;
  outline: none;
}
.overlay-content input:focus {
  border-color: #3b82f6;
}
.overlay-content p {
  color: #9ca3af;
  margin-top: 20px;
  font-size: 1.2rem;
}
.close-btn {
  position: absolute;
  top: 20px;
  right: 45px;
  font-size: 4rem;
  color: white;
  background: none;
  border: none;
  cursor: pointer;
  line-height: 1;
}
function openSearch() {
  document.getElementById("searchOverlay").style.display = "block";
}
function closeSearch() {
  document.getElementById("searchOverlay").style.display = "none";
}
Esc
↑↓ moveEnter select

Start from a template

Open an .html file, or HTML, CSS, JS, Markdown, Less or TypeScript files. You can also drop them here. Styles and scripts go into their panes.

Share

Source

Keyboard shortcuts

Save