Format Code Now
/
Web & markupHTML Checkbox Generator Next: HTML Code Generator ›

HTML Checkbox Generator

WM-50

List your options one per line and get checkbox markup where every box has a linked label and the group has a legend.

Runs in your browser. Nothing is uploaded.

One option per line, plus optional name: and legend: lines

HTML

How to use it

  1. Add a legend: line to name the group, and an optional name: line for the field name.
  2. Write one option per line. Start a line with [x] to tick it, or write Label | value to set the value.
  3. Choose whether labels wrap the input or sit beside it, and whether each option gets a div.
  4. Copy the HTML into your form.

What a checkbox sends to the server

A ticked box sends its name and value; an unticked box sends nothing at all, so the server cannot tell an unticked box from one that was never on the form. If you give a box no value, browsers send the value on. When several boxes share a name, the server receives that name once per ticked box, so your form handler must read a list. This generator gives all boxes in a group the same name and a value built from the label, unless you write one after a vertical bar.

Labels and the fieldset legend

Every box needs a label, because a label gives a larger click target and is read out by screen readers. The default output uses a label with a for attribute that matches the input id; the other style puts the input inside the label, which needs no id. A group of boxes also needs a name, which the fieldset and legend pair provides. The tool asks for a legend line when you have two or more options so the group is never anonymous.

The required option

Required on a checkbox means that box must be ticked before the form can be submitted. That suits a single box such as accepting terms. On a group of topic choices it would force the user to tick every box, so leave it off. If you need at least one box ticked from a group, the browser cannot check that for you and you need a script or a server-side check.

Questions people ask

How do I make a checkbox checked by default?

Add the checked attribute. In this generator, start the option line with [x], for example [x] HTML. Users can still untick it. Only the initial state changes, not what the form sends.

Why does my unchecked checkbox not show up in the form data?

Browsers leave unticked boxes out of the submission, by design. Only ticked ones are sent. Treat a missing name on the server as unticked. If you need an explicit value, add a hidden input with the same name before the checkbox.

What is the default value of a checkbox?

If there is no value attribute, a ticked checkbox sends the text on. That is rarely useful, so give each box a value. This tool sets one from the label or from the text after a vertical bar.

Should I use for and id or wrap the input in the label?

Both are valid and both make the label clickable. The for and id form works when the input and label are separate in your layout; wrapping needs no id. This tool supports both through the Label option.

Can I make a group where at least one box must be ticked?

HTML cannot check that on its own. The required attribute applies to each box separately. Use a short script that checks the group on submit, and always repeat the check on the server.

About this tool

Every line becomes one checkbox with a label. Start a line with [x] to tick it by default. Write Label | value to set the submitted value; otherwise the value is the label in lowercase letters, digits and hyphens. All boxes share one name, so a server receives the name once for each ticked box. A group of two or more boxes needs a legend line, because a fieldset without one gives screen reader users no group name. The Required option adds required to every box, which means every box must be ticked; for a normal group, leave it off. Unticked boxes are not submitted. Text and attribute values are escaped.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.