Search boxes and filters give visitors a way to narrow what a site shows them. An HTML form collects their choices and sends them to a URL when they submit it.
A label gives visitors a visible prompt and helps assistive technology identify its input. The input's name is the key the browser sends with the value.
GET suits read-only requests such as searches because the resulting URL carries the inputs and can be shared. Those values may appear in browser history and server logs, so keep passwords and other private information out of a GET form.
Steps to create an HTML form:
- Create a file named search.html in your local site's document root using your text editor only if that file does not already exist.
A running local web server can serve this page as a static file. The local site in the example is http://localhost:8000.
- Insert the GET form immediately after the <h1> heading.
<form action="search.html" method="get"> </form>
The action is the destination URL. The static test sends the request back to search.html so you can see the submitted values in the address bar. For a working search, the action would point to your site's GET search endpoint.
- Add the Keyword and Category fields between the opening and closing form tags.
<p> <label for="keyword">Keyword</label> <input type="text" id="keyword" name="q"> </p> <p> <label for="category">Category</label> <input type="text" id="category" name="category"> </p>
Each label's for matches the corresponding input's id. Clicking that label focuses its field. The browser sends the name values q and category as query keys. For your own endpoint, the names must match the parameters it expects.
- Save search.html.
- search.html
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Search the catalog</title> </head> <body> <h1>Search the catalog</h1> <form action="search.html" method="get"> <p> <label for="keyword">Keyword</label> <input type="text" id="keyword" name="q"> </p> <p> <label for="category">Category</label> <input type="text" id="category" name="category"> </p> <button type="submit">Search</button> </form> </body> </html>
- Open search.html from your local site's URL in the browser.
The example address is http://localhost:8000/search.html.
- Enter a sample keyword such as lamp in Keyword.

- Enter a sample category such as lighting in Category.

- Submit the form with Search.

- Verify that the Search the catalog page loads with /search.html and both submitted values under q and category in the address bar.
With lamp and lighting, the address ends in /search.html?q=lamp&category=lighting. A browser or server error page means the check failed. If a field is missing from the URL, its name may be missing or misspelled.