Search suggestions empty state in HTML, CSS and vanilla JS
A copy-paste Search suggestions empty state in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.
Live preview
Source (copy-ready)
<section class="dcl-empty-search-suggestions" data-dcl-scheme="light" aria-label="Search suggestions empty state example">
<div data-stack>
<h2>No results for “field guides”</h2>
<p>Try a narrower term from the handbook:</p>
<div data-row><button type="button" data-term="field">Search “field”</button><button type="button" data-term="guides">Search “guides”</button></div>
<p role="status"></p><ul data-well hidden></ul>
</div>
<script>
(() => {
const root = document.currentScript.closest(".dcl-empty-search-suggestions");
const preference = matchMedia("(prefers-color-scheme: dark)");
const setTheme = () => { root.dataset.dclScheme = preference.matches ? "dark" : "light"; };
preference.addEventListener("change", setTheme);
setTheme();
const find = (selector) => root.querySelector(selector);
const all = (selector) => Array.from(root.querySelectorAll(selector));
const samples = { field: ["Field visit checklist"], guides: ["Team guides", "Visitor guides"] };
all("[data-term]").forEach((button) => button.addEventListener("click", () => {
const items = samples[button.dataset.term];
const results = find("ul");
results.replaceChildren(...items.map((item) => {
const entry = document.createElement("li");
entry.textContent = item;
return entry;
}));
results.hidden = false;
find('[role="status"]').textContent = items.length + " demo result(s) for " + button.dataset.term + ".";
}));
})();
</script>
</section>
<style>
.dcl-empty-search-suggestions, .dcl-empty-search-suggestions * { box-sizing: border-box; }
.dcl-empty-search-suggestions { font: 1rem/1.5 system-ui, sans-serif; max-inline-size: 40rem; padding: clamp(0.75rem, 3vw, 1.25rem); border: 1px solid; border-radius: 0.75rem; overflow-wrap: anywhere; }
.dcl-empty-search-suggestions :where(h2, h3, p, ol, ul, dl, dd) { margin: 0; }
.dcl-empty-search-suggestions h2 { font-size: 1.25rem; line-height: 1.25; }
.dcl-empty-search-suggestions h3 { font-size: 1rem; }
.dcl-empty-search-suggestions p + p { margin-block-start: 0.5rem; }
.dcl-empty-search-suggestions [data-stack], .dcl-empty-search-suggestions form { display: grid; gap: 0.75rem; }
.dcl-empty-search-suggestions [data-row] { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; }
.dcl-empty-search-suggestions [data-split] { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 0.75rem 1.25rem; align-items: start; }
.dcl-empty-search-suggestions [data-spread] { justify-content: space-between; }
.dcl-empty-search-suggestions [hidden] { display: none !important; }
.dcl-empty-search-suggestions [data-well] { padding: 0.75rem; border-radius: 0.375rem; }
.dcl-empty-search-suggestions [data-chip] { display: inline-block; width: fit-content; padding: 0.125rem 0.55rem; border-radius: 99rem; font-size: 0.875rem; font-weight: 700; }
.dcl-empty-search-suggestions :where(button, summary, input, select) { font: inherit; }
.dcl-empty-search-suggestions :where(button, input, select) { min-block-size: 44px; min-inline-size: 0; max-inline-size: 100%; }
.dcl-empty-search-suggestions :where(button, input, select) { border: 1px solid; border-radius: 0.375rem; padding: 0.45rem 0.7rem; }
.dcl-empty-search-suggestions :where(button, summary) { cursor: pointer; font-weight: 650; }
.dcl-empty-search-suggestions :where(button, summary):active { box-shadow: inset 0 0 0 2px currentColor; }
.dcl-empty-search-suggestions summary:hover { text-decoration: underline; }
.dcl-empty-search-suggestions :where(button, input, select):disabled, .dcl-empty-search-suggestions [aria-disabled=true] { cursor: not-allowed; border-style: dashed; }
.dcl-empty-search-suggestions label { display: grid; gap: 0.25rem; }
.dcl-empty-search-suggestions :where(input, select) { inline-size: 100%; }
.dcl-empty-search-suggestions label[data-choice] { display: flex; gap: 0.5rem; align-items: center; min-block-size: 44px; }
.dcl-empty-search-suggestions label[data-choice] input { inline-size: 1.25rem; block-size: 1.25rem; min-block-size: 0; flex-shrink: 0; }
.dcl-empty-search-suggestions fieldset { min-inline-size: 0; margin: 0; border-radius: 0.375rem; padding: 0.5rem 0.75rem; }
.dcl-empty-search-suggestions :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.dcl-empty-search-suggestions[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.dcl-empty-search-suggestions ul[data-well] { padding-inline-start: 2rem; }
.dcl-empty-search-suggestions { color-scheme: light; border-color: #697f84; }
.dcl-empty-search-suggestions { color: #11292f; background-color: #ffffff; }
.dcl-empty-search-suggestions [data-well], .dcl-empty-search-suggestions [data-chip] { color: #11292f; background-color: #e4edef; }
.dcl-empty-search-suggestions button, .dcl-empty-search-suggestions input, .dcl-empty-search-suggestions select { color: #11292f; background-color: #e4edef; }
.dcl-empty-search-suggestions button[data-primary] { color: #ffffff; background-color: #00535a; }
.dcl-empty-search-suggestions button:hover { color: #ffffff; background-color: #003c42; }
.dcl-empty-search-suggestions button[disabled], .dcl-empty-search-suggestions button[aria-disabled=true] { color: #405a60; background-color: #e4edef; }
.dcl-empty-search-suggestions[data-dcl-scheme="dark"] { color-scheme: dark; border-color: #839fa5; }
.dcl-empty-search-suggestions[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; }
.dcl-empty-search-suggestions[data-dcl-scheme="dark"] [data-well], .dcl-empty-search-suggestions[data-dcl-scheme="dark"] [data-chip] { color: #eff8f9; background-color: #1c3c44; }
.dcl-empty-search-suggestions[data-dcl-scheme="dark"] button, .dcl-empty-search-suggestions[data-dcl-scheme="dark"] input, .dcl-empty-search-suggestions[data-dcl-scheme="dark"] select { color: #eff8f9; background-color: #1c3c44; }
.dcl-empty-search-suggestions[data-dcl-scheme="dark"] button[data-primary] { color: #11292f; background-color: #8fe1da; }
.dcl-empty-search-suggestions[data-dcl-scheme="dark"] button:hover { color: #11292f; background-color: #b2f2ec; }
.dcl-empty-search-suggestions[data-dcl-scheme="dark"] button[disabled], .dcl-empty-search-suggestions[data-dcl-scheme="dark"] button[aria-disabled=true] { color: #b0c9ce; background-color: #1c3c44; }
</style>
When to use
Offer concrete adjacent queries where the team understands likely search intent.
Avoid
Do not replace the original search term without an explicit choice.
Accessibility
Suggested searches are named buttons. The status announces which term was chosen and how many demo results appeared. Text contrast is at least 6.1:1 in light and 6.7:1 in dark.
Was this useful? Send feedback.