Sub topic 13
Search and filters on small screens
This chapter assumes you know the basics of search and filter design from earlier chapters: the search field, facets and counts, and URL-based filter state. It also assumes you can read HTML and TypeScript. Here you will adapt those pieces to phones, where space, input method, and attention are all limited.
What changes on a small screen
A phone changes four things that a desktop layout lets you ignore.
- Space. A 360 px wide viewport cannot hold a sidebar of filters next to a results list.
- Input. Users type on a software keyboard that covers roughly half the screen. Typing is slow and error-prone, so each keystroke costs more.
- Pointing. Fingers are imprecise. Controls need a target of at least 44×44 CSS pixels (Apple's guideline) or 48×48 dp (Material). Leave gaps between adjacent targets.
- Context. People often use one hand, with interruptions and a weak connection.
The design response is to show less at once, move secondary controls into a separate layer, and keep every layer easy to leave.
Search entry on mobile
You have two common entry points.
| Pattern | Use when | Trade-off |
|---|---|---|
| Persistent search field at the top | Search is the main way users find things (shops, marketplaces) | Uses about 56 px of vertical space on every screen |
| Search icon that opens a search mode | Search is secondary to browsing or navigation | One extra tap, and the feature is less discoverable |
Whichever you pick, tapping the field should open a dedicated search mode that fills the screen. In that mode, show recent searches and popular queries before the user types, then switch to suggestions as they type. A full-screen mode keeps the keyboard, the field, and the suggestions in one visible area. It also avoids a page that scrolls behind the keyboard.
Set input attributes so the keyboard helps instead of interfering.
<form role="search" action="/search" method="get">
<label for="q" class="visually-hidden">Search products</label>
<input
id="q"
name="q"
type="search"
enterkeyhint="search"
autocomplete="off"
autocapitalize="off"
autocorrect="off"
spellcheck="false"
placeholder="Search products"
>
</form>type="search"gives a clear button on many platforms and the right semantics.enterkeyhint="search"labels the keyboard's return key "Search" instead of "Return".autocapitalize="off"stops "Boots" from being capitalized on the first letter. Turn off autocorrect only where it hurts, such as product codes or names. For natural-language queries, leave it on, because it fixes typos for free.- Use a font size of at least 16 px in the field. Safari on iOS zooms the page when a focused input has a smaller font, and that zoom is disorienting.
Keep the field visible while results scroll if search is the primary task. If you hide it on scroll down, bring it back on any scroll up.
Suggestions under a keyboard
The keyboard leaves room for only four to six suggestion rows. Plan for that.
- Show at most five or six suggestions, and give each row a full-width tap target of 48 px or more.
- Put an "insert into field" arrow at the end of each row. Users can then refine a suggestion without retyping it.
- Order by likelihood, with the best match at the top. Rows at the bottom sit under the user's thumb, so don't hide important options there.
- Scroll the suggestion list, not the whole page. Dismiss the keyboard when the user starts to scroll the list.
- Keep the debounce delay from earlier chapters, but account for slower networks. Cancel or ignore a stale response so an old request cannot overwrite a newer one.
Filters: from sidebar to sheet
The desktop sidebar becomes a bottom sheet or a full-screen filter view, opened from a "Filters" button.
- A bottom sheet suits short lists of filters (up to about five groups). The results stay partly visible behind it, which keeps the user oriented.
- A full-screen view suits many filter groups, or groups with long option lists. Give it a header with a close button and the title, and a sticky footer for actions.
Put the "Filters" button and the "Sort" control in a sticky bar just under the search field. Show the number of active filters on the button, for example "Filters (3)". Users then know that filters are on even when the sheet is closed.
Draft state, Apply, and instant filtering
You can apply a filter change immediately or wait for a confirmation. On small screens, the better default is a draft state with an Apply button:
- The user opens the sheet and changes several options.
- The sheet keeps these changes as a draft. The results behind it do not reload.
- The footer button reports what Apply will do, such as "Show 128 results".
- Apply commits the draft. Closing the sheet discards it.
Instant filtering reloads results after each tap. That wastes data and makes the list jump while the user is still choosing. Use it only when a single control is involved, such as a sort order or a row of quick-filter chips, and the result list is fast.
The live count on the Apply button is the mobile version of facet counts. It answers "what will I get?" without leaving the sheet. When the count is zero, say "No results" and disable the button, so the user cannot reach an empty page by accident.
<button id="open-filters" type="button">Filters</button>
<dialog id="filter-sheet" aria-labelledby="filter-title">
<form method="dialog">
<h2 id="filter-title">Filters</h2>
<fieldset>
<legend>Category</legend>
<label><input type="checkbox" name="category" value="boots"> Boots</label>
<label><input type="checkbox" name="category" value="sandals"> Sandals</label>
<label><input type="checkbox" name="category" value="sneakers"> Sneakers</label>
</fieldset>
<footer>
<button id="reset" type="button">Reset</button>
<button id="apply" type="submit">Show results</button>
</footer>
</form>
</dialog>const sheet = document.querySelector<HTMLDialogElement>("#filter-sheet")!;
const form = sheet.querySelector<HTMLFormElement>("form")!;
const applyButton = form.querySelector<HTMLButtonElement>("#apply")!;
const resetButton = form.querySelector<HTMLButtonElement>("#reset")!;
const openButton = document.querySelector<HTMLButtonElement>("#open-filters")!;
function boxes(): HTMLInputElement[] {
return Array.from(form.querySelectorAll<HTMLInputElement>('input[name="category"]'));
}
function draftParams(): URLSearchParams {
const params = new URLSearchParams(location.search);
params.delete("category");
for (const value of new FormData(form).getAll("category")) {
params.append("category", String(value));
}
return params;
}
let latestRequest = 0;
async function refreshCount(): Promise<void> {
const ticket = ++latestRequest;
try {
const res = await fetch(`/api/search/count?${draftParams()}`);
if (!res.ok) throw new Error("count failed");
const body: { count: number } = await res.json();
if (ticket !== latestRequest) return; // a newer request replaced this one
applyButton.disabled = body.count === 0;
applyButton.textContent = body.count === 0 ? "No results" : `Show ${body.count} results`;
} catch {
if (ticket !== latestRequest) return;
applyButton.disabled = false; // fall back to a plain button
applyButton.textContent = "Show results";
}
}
openButton.addEventListener("click", () => {
const selected = new Set(new URLSearchParams(location.search).getAll("category"));
for (const box of boxes()) box.checked = selected.has(box.value);
sheet.showModal();
void refreshCount();
});
form.addEventListener("change", () => void refreshCount());
resetButton.addEventListener("click", () => {
for (const box of boxes()) box.checked = false;
void refreshCount();
});
form.addEventListener("submit", (event) => {
event.preventDefault();
location.search = draftParams().toString(); // commit the draft to the URL
});The sheet reads its starting state from the URL and writes back to the URL on Apply, so the shareable-URL behavior from the filter-state chapter still holds. Closing the dialog with Escape or the system back gesture discards the draft, because nothing was written. The ticket counter drops out-of-order responses, which are common on mobile networks.
Choosing controls for touch
Revisit the control choices from the earlier filter chapter with a finger in mind.
- Checkboxes and radio buttons. Make the whole row tappable, not just the small box. Wrap the input in its
labeland pad the label to 48 px high. - Range sliders. Two-thumb sliders are hard to use with a finger, and the thumbs can overlap. Offer preset ranges ("Under $50", "$50 to $100") or two numeric fields with
inputmode="numeric", and keep the slider as an optional extra. - Long option lists. Add a small search box inside the group, and show the top five options with a "Show more" row.
- Dates. Use the native date input, which opens the platform picker.
- Quick filters. A single horizontally scrollable row of chips beneath the search bar handles the two or three most common filters, such as "In stock" or "Free delivery". Let the next chip peek past the edge of the screen, so users can see that the row scrolls.
Applied filters and navigation
After the user applies filters, show them as chips above the results, with a clear "x" on each and a "Clear all" at the end. Place the row in a single line that scrolls sideways, not one that wraps into three lines and pushes the results off screen.
Treat the back gesture as part of the design. On a phone, back is the most frequent action. If your filter sheet opens as an overlay without a history entry, the back gesture leaves the whole results page. Native <dialog> handles Escape, but not every browser maps the back gesture to it, so test this on a real device. Tapping a result and then going back should return the user to the same results, filters, and scroll position. Keeping filters in the URL, and restoring scroll on return, gives you this.
Keyboard, viewport, and performance
- Use the
dvhunit or the Visual Viewport API for full-height sheets. Plain100vhon mobile browsers includes the area behind the address bar, so the footer button can end up hidden. - When the keyboard opens inside a filter group's search box, make sure the Apply footer stays reachable. Test with the keyboard open.
- Send smaller result pages and paginate or load more on demand. Lazy-load images below the first screen.
- Show a loading state in place, such as skeleton rows, and keep the previous results visible and dimmed while new ones load. A blank screen on a slow connection reads as a failure.
Accessibility on touch devices
The accessibility rules still apply, with a few additions. Move focus into the sheet when it opens and back to the "Filters" button when it closes. Native <dialog> with showModal() does both. Announce the result count after Apply with a role="status" region. Check that the layout survives the system's larger text setting, since a 48 px footer button with a long label like "Show 1,284 results" may wrap. Also, never rely on a swipe or a long-press as the only way to remove a filter, because screen-reader users and switch users cannot use them.
Exercise
A shopping app applies each filter change instantly inside its mobile filter sheet, and the results list behind the sheet reloads after every tap. Users complain that the screen flickers and that they often end up on an empty list. Name two changes that fix this and explain how each one helps.
Show answer
First, switch the sheet to a draft state with an Apply button. Changes stay local until the user commits them, so the list no longer reloads while they are still choosing, which removes the flicker and saves data. Second, show a live result count on the Apply button and disable it when the count is zero ("No results"). Users see what they will get before leaving the sheet, so they cannot reach an empty list by accident. Ignoring stale count responses (for example with a request ticket) keeps the displayed count correct on slow networks.
Exercise
Why is a two-thumb price slider a poor sole control on a phone, and what would you offer instead?
Show answer
Thumbs are small compared with a fingertip, they can overlap at close values, and the finger hides the value while dragging. Offer preset ranges such as "Under $50" and "$50 to $100", or two numeric fields with inputmode="numeric", and keep a slider only as an optional addition.