Sub topic 6
Presenting search results
This chapter covers how to lay out and communicate search results once a query has run. It assumes you know how to build basic HTML forms and lists and can read TypeScript. It also assumes you have read the earlier chapters on the search field and on forgiving queries. Ranking and sorting, filter controls, and empty states each get their own chapters, so this one only touches them where results presentation depends on them.
What the results page has to do
A results page answers three questions in order:
- Did the system understand what I asked?
- How many things did it find, and are they the right kind?
- Which one should I open?
Most presentation mistakes come from answering the third question while ignoring the first two. A beautiful card grid does not help if the user cannot tell whether the query was reinterpreted, truncated, or partially matched.
Confirm the query and the result count
Show the query the user ran, near the results, in the same words they typed. If your system changed the query, say so. This happens when it corrects a typo, expands a synonym, or drops a stop word.
- Corrected: "Showing results for boots. Search instead for bots."
- Expanded: "Showing results for sneakers and similar terms."
- Unchanged: "24 results for "boots"."
Always offer a way back to the literal query when you auto-correct. Users searching for a product code, a name, or a rare term are often right and the corrector is wrong.
A result count gives the user a sense of scale. Treat it carefully:
- Show an exact count when the count is cheap and stable, such as "24 results".
- Show an approximate count when the backend estimates it, such as "About 1,200 results". An exact number that changes on the next page load erodes trust.
- Omit the count when it adds nothing, such as in an infinite feed where no one will reach the end.
The count should live in a status region so screen readers announce it after each update. The example below shows a search landmark with a visible label and a status message.
<form role="search" action="/search" method="get">
<label for="q">Search products</label>
<input id="q" name="q" type="search" autocomplete="off">
<button type="submit">Search</button>
</form>
<p role="status">24 results for "boots"</p>The role="status" paragraph is a polite live region. Update its text when results change and a screen reader announces the new count without moving focus.
Choose a result layout
The layout should match what users compare when they decide.
| Layout | Best when | Watch out for |
|---|---|---|
| List (one item per row) | Users scan text: documents, emails, help articles, people | Rows with little visual difference are hard to tell apart |
| Grid of cards | Users judge by image: products, photos, listings | Titles get truncated, and the reading order is unclear |
| Table | Users compare attributes: files, orders, records | Wide tables break on small screens |
| Map or split view | Location matters: stores, rentals, venues | Results off screen are invisible, so sync list and map |
Pick by the comparison task, not by habit. If users decide on price and size, put price and size in every result. If they decide on a photo, make the photo large.
What goes inside a result
Each result needs enough information to decide whether to open it, and no more. A reliable structure is:
- A title that is a real link, so the whole item has a clear target.
- One or two attributes that distinguish this item from its neighbors.
- A snippet or image that shows why it matched.
- A status or action only when the user can use it immediately, such as "In stock" or "Add to cart".
Keep the order of these parts the same on every result. Users learn to scan one column and skip the rest.
Show why a result matched
For text search, highlight the matched terms in the snippet. Highlighting tells the user why a result appears and lets them reject it quickly. Use bold or a background tint, and never color alone. Keep the highlight in the markup semantic. The <mark> element is the standard choice.
function escapeHtml(text: string): string {
return text
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """);
}
function escapeRegExp(text: string): string {
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function highlight(snippet: string, terms: string[]): string {
const safe = escapeHtml(snippet);
const cleaned = terms.map((t) => t.trim()).filter((t) => t.length > 0);
if (cleaned.length === 0) return safe;
const pattern = new RegExp(`(${cleaned.map((t) => escapeRegExp(escapeHtml(t))).join("|")})`, "gi");
return safe.replace(pattern, "<mark>$1</mark>");
}
console.log(highlight("Waterproof leather boots, size 42", ["boots", "leather"]));
// Waterproof <mark>leather</mark> <mark>boots</mark>, size 42Two details in this code matter. First, the snippet is escaped before any markup is added, because result text often comes from users and would otherwise be an injection path. Second, the search terms are escaped for use in a regular expression, because a query such as c++ would otherwise throw an error.
Handle long and missing content
Real data is messy. Plan for these cases before you design the "happy path" card.
- Long titles. Truncate with an ellipsis after two lines at most, and keep the full title available through the link text or a tooltip. Do not truncate the part that distinguishes items, such as the model number at the end.
- Missing images. Use a neutral placeholder with a fixed aspect ratio so the layout does not jump.
- Missing attributes. Leave the field out instead of printing "N/A" in every row. If a missing value matters, such as price, show a clear alternative like "Price on request".
- Duplicates. Near-identical results waste attention. Group variants, such as sizes and colors, under one result and show the variation in the detail view.
Load more results: pagination, infinite scroll, or a button
Result sets are usually too large to load at once. The three standard patterns have different trade-offs.
| Pattern | Strength | Weakness |
|---|---|---|
| Numbered pagination | Users know where they are and can return to page 3 | Each page change interrupts scanning |
| "Load more" button | Keeps position, gives the user control, and the footer stays reachable | Long lists become heavy in memory |
| Infinite scroll | Smooth for browsing feeds | Loses position on back navigation, hides the footer, and is hard for keyboard users |
For goal-driven search, where people compare and return to earlier results, prefer numbered pagination or a "Load more" button. Reserve infinite scroll for exploratory feeds. Whichever you choose, restore the scroll position and loaded results when the user presses the back button. This ties into the URL-state chapter: the page number or cursor belongs in the URL.
When new results are appended, announce them. After "Load more", move focus to the first new result or update the status region ("Showing 41 to 60 of 120"). Without this, keyboard and screen reader users get no signal that anything changed.
Keep results stable while the query changes
Results often update as the user types or changes a filter. Two failure modes appear here:
- Layout jumps. The list collapses to a spinner and then expands, and the page jumps under the user's cursor. Keep the old results visible, dimmed, until the new ones arrive, and reserve space for the list.
- Stale results. A slow response to an old query arrives after a response to a newer one and overwrites it. Tag each request and ignore responses that are not for the latest query.
let latestRequest = 0;
async function runSearch(query: string, render: (items: string[]) => void): Promise<void> {
const requestId = ++latestRequest;
const response = await fetch(`/api/search?q=${encodeURIComponent(query)}`);
const items: string[] = await response.json();
if (requestId !== latestRequest) return; // a newer search has started
render(items);
}The counter is a simple guard. In production, AbortController can also cancel the older request so the network is not wasted.
Presentation decisions at a glance
The diagram shows the order of decisions when a results page renders.
Common errors
- Showing results without echoing the query, so users cannot tell if their input was understood.
- Auto-correcting silently, with no route back to the literal query.
- Highlighting by color only, or inserting unescaped text into HTML.
- Choosing infinite scroll for tasks where users return to earlier results.
- Replacing the list with a spinner on every keystroke, which causes flicker and layout shift.
- Letting out-of-order responses overwrite newer ones.
Exercise
A user searches for "bots" and your system automatically shows results for "boots". Name two things the page should show, and explain why the second one matters.
Show answer
The page should show a message such as "Showing results for boots" and a link such as "Search instead for bots". The link matters because auto-correction can be wrong, for example for product codes, names, or rare terms. Without a route back, the user cannot get the results for what they actually typed.
Exercise
A user types quickly, and a slow response for "boo" arrives after the response for "boots". What happens without a guard, and how does the latestRequest counter prevent it?
Show answer
Without a guard, the late "boo" response calls render last and overwrites the "boots" results, so the list no longer matches the query. The counter gives each request an id. After the response arrives, the code compares its id with the latest id and returns without rendering if they differ, so only the newest search updates the page.
Exercise
You are building a results page for a document search where users often return to earlier results to compare them. Which loading pattern do you choose, and what must you do about the back button?
Show answer
Choose numbered pagination or a "Load more" button, not infinite scroll. Store the page number or cursor in the URL and restore the loaded results and scroll position when the user navigates back.