Expanding Search
A compact search button opens into a field with popular searches below it. Escape or a click outside closes it again. Handy in a crowded header.
How to use it
- Paste the HTML where the forms & inputs should appear.
- Add the CSS to your stylesheet. All classes are prefixed, so nothing clashes with your own styles.
- Add the JavaScript and call init() with the element that contains the HTML.
<!-- Expanding Search · © 2026 NedDev BV · NedDev Lab-licentie (gratis gebruik, niet doorverkopen) · neddev.com/nl/lab/gebruik/#licentie -->
<div class="jouw-container">
<form class="nzs" role="search" action="#" novalidate>
<div class="nzs__vak">
<label class="nzs__verborgen" for="nzs-veld">Zoeken in de tuinwinkel</label>
<input id="nzs-veld" class="nzs__veld" type="search" placeholder="Zoek een product" autocomplete="off" tabindex="-1">
<button class="nzs__knop" type="button" aria-expanded="false" aria-controls="nzs-tips" aria-label="Zoekveld openen"><svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="10.5" cy="10.5" r="6"/><path d="M15 15l5 5"/></svg></button>
</div>
<ul class="nzs__tips" id="nzs-tips" hidden>
<li><button type="button" class="nzs__tip">Tuinset teak</button></li>
<li><button type="button" class="nzs__tip">Parasol 3 meter</button></li>
<li><button type="button" class="nzs__tip">Loungekussens</button></li>
<li><button type="button" class="nzs__tip">Plantenbak cortenstaal</button></li>
</ul>
<p class="nzs__melding" aria-live="polite"></p>
</form>
</div>/* Expanding Search · © 2026 NedDev BV · NedDev Lab-licentie (gratis gebruik, niet doorverkopen) · neddev.com/nl/lab/gebruik/#licentie */
.nzs{width:100%;container-type:inline-size;display:flex;flex-direction:column;align-items:center;font-family:'Switzer',sans-serif;color:#0a0a0a;margin:0}
.nzs__vak{position:relative;display:flex;align-items:center;width:50px;height:50px;background:#fff;border:1px solid #d8d4cd;border-radius:4px;box-sizing:border-box;overflow:hidden;transition:width .38s cubic-bezier(.2,.8,.2,1),border-color .2s}
.nzs.is-open .nzs__vak{width:min(380px,86cqw);border-color:#0a0a0a}
.nzs__verborgen{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.nzs__veld{flex:1 1 0;width:0;min-width:0;height:100%;border:0;background:transparent;padding:0;font:inherit;font-size:16px;color:#0a0a0a;opacity:0;transition:opacity .2s;outline:none}
.nzs__veld::-webkit-search-cancel-button{display:none}
.nzs.is-open .nzs__veld{opacity:1;padding-left:14px;transition-delay:.12s}
.nzs__knop{flex:0 0 40px;width:40px;height:40px;margin:4px;display:grid;place-items:center;background:#F5480F;border:0;border-radius:4px;cursor:pointer;transition:background .18s}
.nzs__knop:hover{background:#d93c08}
.nzs__knop:focus-visible{outline:2px solid #0a0a0a;outline-offset:2px}
.nzs__knop svg{width:20px;height:20px;fill:none;stroke:#fff;stroke-width:2;stroke-linecap:round}
.nzs__tips{list-style:none;margin:8px 0 0;padding:6px;width:min(380px,86cqw);box-sizing:border-box;background:#fff;border:1px solid #e3dfd8;border-radius:4px}
.nzs__tips[hidden]{display:none}
.nzs__tip{display:block;width:100%;text-align:left;padding:8px 10px;background:none;border:0;border-radius:4px;font:inherit;font-size:14px;color:#0a0a0a;cursor:pointer}
.nzs__tip:hover,.nzs__tip:focus-visible{background:#f4f3f1;outline:none}
.nzs__melding{margin:10px 0 0;font-size:14px;color:#5b5750;min-height:1.4em}
@media (prefers-reduced-motion:reduce){.nzs__vak,.nzs__veld{transition:none}}// Expanding Search · © 2026 NedDev BV · NedDev Lab-licentie (gratis gebruik, niet doorverkopen) · neddev.com/nl/lab/gebruik/#licentie
// root = het element waarin de HTML staat
function init(root){
var f = root.querySelector('.nzs'); if (!f) return;
var veld = f.querySelector('.nzs__veld'), knop = f.querySelector('.nzs__knop'), tips = f.querySelector('.nzs__tips'), melding = f.querySelector('.nzs__melding');
var alle = Array.prototype.slice.call(f.querySelectorAll('.nzs__tip'));
function open() {
f.classList.add('is-open'); knop.setAttribute('aria-expanded', 'true'); knop.setAttribute('aria-label', 'Zoeken');
veld.tabIndex = 0; tips.hidden = false; filter();
setTimeout(function () { veld.focus({ preventScroll: true }); }, 60);
}
function dicht() {
f.classList.remove('is-open'); knop.setAttribute('aria-expanded', 'false'); knop.setAttribute('aria-label', 'Zoekveld openen');
veld.tabIndex = -1; tips.hidden = true;
}
function zoek() {
var q = veld.value.trim(); if (!q) return;
melding.textContent = 'U zoekt op \u201c' + q + '\u201d.'; tips.hidden = true;
}
function filter() {
var q = veld.value.trim().toLowerCase(), zichtbaar = 0;
alle.forEach(function (b) { var ok = !q || b.textContent.toLowerCase().indexOf(q) > -1; b.parentNode.hidden = !ok; if (ok) zichtbaar++; });
tips.hidden = !f.classList.contains('is-open') || zichtbaar === 0;
}
knop.addEventListener('click', function () {
if (!f.classList.contains('is-open')) open();
else if (veld.value.trim()) zoek();
else dicht();
});
veld.addEventListener('input', function () { melding.textContent = ''; filter(); });
alle.forEach(function (b) { b.addEventListener('click', function () { veld.value = b.textContent; zoek(); veld.focus({ preventScroll: true }); }); });
f.addEventListener('submit', function (e) { e.preventDefault(); zoek(); });
f.addEventListener('keydown', function (e) { if (e.key === 'Escape') { veld.value = ''; melding.textContent = ''; dicht(); knop.focus(); } });
document.addEventListener('pointerdown', function (e) { if (f.classList.contains('is-open') && !f.contains(e.target) && !veld.value.trim()) dicht(); });
}
init(document.querySelector('.jouw-container'));
More forms & inputs
Seen something you like?
Add it to your selection and send it over. We build your site around it, in your brand.
Get in touch →