A site search's results page, with a live count, snippets, facets, sorting and a no-match help.
<div class="cap-search" data-facets id="results">
<div class="cap-search-main">
<p class="cap-search-count" aria-live="polite">3 results</p>
<div class="cap-search-sort">
<nav aria-label="Sort results" class="cap-chips"><a class="cap-chip" href="#" aria-current="true">Relevance</a><a class="cap-chip" href="#newest">Newest</a></nav>
</div>
<ol class="cap-search-list" aria-label="Search results">
<li class="cap-search-result">
<div class="cap-search-head"><span class="cap-pill" data-variant="outline">Guide</span><h3 class="cap-search-title"><a href="#getting-started"><mark>Getting</mark> started</a></h3></div>
<p class="cap-search-snippet">Before you publish, <mark>getting</mark> the checks green is the first step <draft> mode allows.</p>
<p class="cap-search-why">Matched on the title and the text · 2025</p>
</li>
<li class="cap-search-result">
<div class="cap-search-head"><span class="cap-pill" data-variant="outline">Section</span><h3 class="cap-search-title"><a href="#release-notes">Upgrading</a></h3></div>
<p class="cap-search-context">in <a href="#notes">Release notes</a></p>
<p class="cap-search-snippet">…when <mark>getting</mark> a new release, read the notes first…</p>
<p class="cap-search-why">Matched on the text · 2024</p>
</li>
<li class="cap-search-result">
<div class="cap-search-head"><span class="cap-pill" data-variant="outline">Post</span><h3 class="cap-search-title"><a href="#spring">Spring update</a></h3></div>
<p class="cap-search-snippet">A season of <mark>getting</mark> things shipped.</p>
</li>
</ol>
</div>
<aside class="cap-search-facets" aria-label="Filter results">
<section>
<h3>Type</h3>
<nav class="cap-chips" aria-label="Type"><a class="cap-chip" href="#guide">Guide <span class="cap-chip-count">1</span></a><a class="cap-chip" href="#post">Post <span class="cap-chip-count">2</span></a></nav>
</section>
</aside>
</div>
Copy
View code
Installation
HTML and CSS React
// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/search-results.css";
import { snippetParts, snippetHtml, markQuery } from "capsomer/behavior/search-results";Copy
import "capsomer/tokens.css";
import "capsomer/search-results.css";
import { Snippet, SearchResult, SearchResults } from "capsomer/react/search-results";Copy
Usage
<div class="cap-search" data-facets>
<div class="cap-search-main">
<p class="cap-search-count" aria-live="polite">3 results</p>
<ol class="cap-search-list" aria-label="Search results">
<li class="cap-search-result">
<div class="cap-search-head"><span class="cap-pill" data-variant="outline">Guide</span><h2 class="cap-search-title"><a href="/guides/getting-started">Getting started</a></h2></div>
<p class="cap-search-context">in <a href="/guides">Guides</a></p>
<p class="cap-search-snippet">Before you publish, <mark>getting</mark> the checks green…</p>
<p class="cap-search-why">Matched on the title</p>
</li>
</ol>
</div>
<aside class="cap-search-facets" aria-label="Filter results">…link chips…</aside>
</div>Copy
Examples
Nothing matched, with something to try
<div class="cap-search" id="empty">
<div class="cap-search-main">
<p class="cap-search-count" aria-live="polite">No results</p>
<div class="cap-search-empty">
<p>Nothing matched <strong>field nots</strong>.</p>
<section aria-labelledby="try-recent">
<h3 id="try-recent">Recent</h3>
<ul><li><a href="#notes">Field notes</a></li><li><a href="#report">Annual report</a></li></ul>
</section>
</div>
</div>
</div>
Copy
View code
API reference
Snippet Prop Type Required Does textstringYes Text with each match between the markers (MARK_OPEN, MARK_CLOSE), as FTS5's snippet() writes it. openstringclosestring
SearchResult Prop Type Required Does hrefstringYes titleReactNodeYes kindReactNodeWhat kind of thing it is ("Post", "Guide"), a badge before the title. contextReactNodeWhere it sits ("in Getting started", a path), under the title. snippetstringThe snippet, with its matches between the markers. whyReactNodeWhy it matched and anything else worth a word ("Matched on the title", a year). level2 | 3The title's heading level in the page's outline.
SearchResults Prop Type Required Does countstringYes The count line ("24 results"): resultsText writes it. Always rendered, empty before a search, so the live region exists before it first speaks. childrenReactNodeResults, a SearchResult each. facetsReactNodeFilters, beside the results on a wide screen and above them on a narrow one. sortReactNodeThe sort links, above the results. emptyReactNodeWhat shows when nothing matched: a sentence and something to try (related tags, recent items). pagerReactNodeThe pages, under the results. labelstring
Functions Function Signature Does snippetParts(snippet: string, open?: string, close?: string): SnippetPart[]The snippet as runs of plain and matched text. A marker left open runs to the end as a match; a stray close is dropped. Empty runs are left out. snippetHtml(snippet: string, open?: string | undefined, close?: string | undefined): stringThe snippet as HTML: every run escaped, each match in a <mark>. For a page built without React. markQuery(text: string, query: string): stringMarks every word of a query in a plain text, for an index searched in the page (no server snippet). Words match case- and accent-blind at the start of a word, as the catalog's search does. resultsText(count: number, options?: { more?: boolean | undefined; noun?: readonly [string, string] | undefined; }): stringThe count line: "No results", "1 result", "24 results", "100+ results" when the search stopped counting. Said in a live region that exists before the first search, so it is heard.
Parts and data attributes Class Is .cap-searchthe root .cap-search-contexta part .cap-search-counta part .cap-search-emptya part .cap-search-facetsa part .cap-search-heada part .cap-search-lista part .cap-search-maina part .cap-search-resulta part .cap-search-snippeta part .cap-search-sorta part .cap-search-titlea part .cap-search-whya part
Attribute Values data-facetspresent or absent
State Read from :emptythe platform
Accessibility
Links and chips only: Tab moves through the sort, the results, the pages and the facets.
Each title is a heading at the level the page needs (level), so a screen reader lists the results by heading. No manual NVDA or VoiceOver run is planned (decision of 2026-11-07); the automated browser checks and a front-end review stand in.