Typeahead Autocomplete
A search input with a live autocomplete dropdown of matches.
Requires Bootstrap 5. Add the CDN tags below to your page (styles in
<head>, scripts before </body>). The downloaded file already includes them.<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script><div class="card border-0 shadow-sm" style="max-width:340px"><div class="card-body position-relative">
<input class="form-control" id="taInput" placeholder="Type a country…" autocomplete="off">
<div class="list-group position-absolute w-100 shadow" id="taList" style="z-index:5;display:none;left:0;right:0;margin:0 16px"></div>
</div></div>var data=['Latvia','Lithuania','Estonia','Germany','France','Finland','Sweden','Norway'];
var inp=document.getElementById('taInput'),list=document.getElementById('taList');
inp.addEventListener('input',function(){var q=inp.value.toLowerCase();if(!q){list.style.display='none';return}var m=data.filter(function(d){return d.toLowerCase().indexOf(q)===0});list.innerHTML=m.map(function(d){return '<button class="list-group-item list-group-item-action py-2 small">'+d+'</button>'}).join('');list.style.display=m.length?'block':'none';list.querySelectorAll('button').forEach(function(b){b.onclick=function(){inp.value=b.textContent;list.style.display='none'}})});Free to use.This component uses Bootstrap 5 (linked above). Copy any file, or download a ready-to-open .html page with the CDN links already included.