A preferences form often lets people choose several items from the same list. Checkboxes in an HTML form let people turn each choice on or off independently.
A label lets people click either the checkbox or its text. A fieldset groups related choices under a single prompt, called a legend.
An unchecked checkbox contributes no entry when the form is submitted. In a GET form, the selected values appear in the URL query string.
Steps to add checkboxes to an HTML form:
- Create
topics.htmlin your local test site's document root using your text editor, provided the filename is unused. - Write the workshop topic form in
topics.html.- topics.html
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Workshop topics</title> </head> <body> <h1>Workshop topics</h1> <form action="topics.html" method="get"> <button type="submit">Submit choices</button> </form> </body> </html>
The form sends a GET request back to
topics.html, so the local server can return the same page after submission. - Insert the checkbox group inside the form immediately before the Submit choices button.
<fieldset> <legend>Topics to explore</legend> <label> <input type="checkbox" name="topic" value="html"> HTML </label> <label> <input type="checkbox" name="topic" value="css"> CSS </label> <label> <input type="checkbox" name="topic" value="js"> JavaScript </label> </fieldset>
The boxes share the field name
topicand each has its own value. If two boxes are checked, the browser sends two entries under that name. - Save
topics.html. - Open
topics.htmlathttp://localhost:8000/in desktop Chrome.If your test server uses a different address or port, substitute it in the URL.
- Click the HTML label to check its box.

- Click the CSS label to check its box.

- Click Submit choices with only HTML and CSS checked.

- Verify that the returned Workshop topics page has
topic=html&topic=cssin its address.An error page, a missing value, or a
topic=jsentry means the check failed.