splitforms.com

HTML · FORM CONTROL

HTML checkbox: checked, value, events and what gets sent

Last reviewed

An HTML checkbox is an <input type="checkbox"> form control that lets a user select zero, one or more independent options. A checked box submits its name=value pair, while an unchecked box submits nothing; without a value attribute, a checked box submits name=on. To make a checkbox in HTML, add <input type="checkbox"> inside a form and wrap it in a <label> so the text toggles the box: <label><input type="checkbox" name="subscribe" value="yes"> Subscribe</label>. The checked attribute marks it on by default, and name/value control what gets submitted. Give several boxes the same name to collect multiple answers. To see how the same name attribute works on other fields, read the HTML input reference, and for uploads see the HTML file input.

  • Live, editable example
  • Copy-paste snippet
  • Attributes & common mistakes
Live demo · nothing is sent

What gets submitted

Fill in the form above and press its button. The demo stops the request and lists every name=value pair the browser would send, plus the controls it leaves out.

With a free access key in the form, these fields land in your splitforms dashboard; access_key and botcheck are read by splitforms, not stored as lead data.

Edit the HTML and re-run it
Runs in a sandbox. Nothing is sent.

Minimal snippet

checkbox-example.html
<label>
  <input type="checkbox" name="subscribe" value="yes" checked>
  Subscribe to the newsletter
</label>

<!-- Checked:   subscribe=yes
     Unchecked: nothing is sent -->

Want this form to email you its submissions? Point it at a free splitforms endpoint, with no server to build. Get a free access key →

Copy-paste code

HTML Checkbox code you can paste today.

Replace YOUR_ACCESS_KEY with a key from your free splitforms dashboard. The form posts to one endpoint — submissions land in your inbox and dashboard with spam filtering built in.

Get free access key
checkbox.html
<form action="https://splitforms.com/api/submit" method="POST">
  <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY">

  <label for="name">Name</label>
  <input type="text" id="name" name="name" required>

  <fieldset>
    <legend>I'm interested in (tick all that apply)</legend>
    <label><input type="checkbox" name="interest" value="newsletter"> Newsletter</label>
    <label><input type="checkbox" name="interest" value="beta"> Beta access</label>
    <label><input type="checkbox" name="interest" value="demo"> Product demo</label>
  </fieldset>

  <label><input type="checkbox" name="agree_terms" value="yes" required> I agree to the terms</label>

  <button type="submit">Send</button>
</form>

Attributes and accessibility

What attributes and labels does an HTML checkbox need?

Set name and value so a checked box sends a clear name=value pair, and use checked, disabled and required to control its starting state, whether it can be used and whether it must be ticked. The indeterminate state is set only in JavaScript (box.indeterminate = true): it draws a mixed dash for select-all controls but is not an HTML attribute and changes only the look, so the box still submits by its checked state. For accessibility, give every box a label with for/id or by wrapping it, and group related boxes in a fieldset with a legend so screen readers announce what the group is for.

What attributes and labels does an HTML checkbox need?
Attribute or patternWhat it doesSubmission and accessibility effect
nameThe key the box is submitted under.A named, checked and enabled box sends name=value; a box without a name is never submitted.
valueThe value sent when the box is checked.Defaults to on when omitted, so set a meaningful value to tell answers apart.
checkedMarks the box ticked in the HTML.Sets the starting state and what form.reset() restores; it does not track later user toggles.
disabledGreys out the box and blocks interaction.A disabled box is skipped on submit even when it is checked.
requiredRequires this box to be ticked before submit.Blocks submission until ticked; it requires that one box, not one of a group.
<label for="id"> or a wrapping <label>Gives the box its accessible name and makes the text toggle it.Clicking the label toggles the box; without a label a screen reader announces an unnamed checkbox.

A fieldset + legend around a group of related boxes is the accessible way to caption the group — better than a plain heading.

Sources: WHATWG HTML Standard: checkbox state · WHATWG HTML Standard: indeterminate · MDN: input type=checkbox · MDN: label element

What gets submitted

What does a checkbox send when the form is submitted?

A checked checkbox sends its name and value; an unchecked one sends nothing, so the key is missing rather than false. Boxes that share a name each add their own pair, and a disabled box is skipped even when it is checked.

What does a checkbox send when the form is submitted?
Checkbox stateWhat the browser sendsNotes
Checked, with value="yes"agree=yesThe value is sent exactly as written.
Checked, no value attributeagree=onon is the default value, so always set a meaningful one.
UncheckedNothing: the agree key is absentNo agree= and no false. Treat a missing key as unchecked.
Several checked boxes with the same nameinterest=beta&interest=demoOne pair per checked box, in page order. Object.fromEntries(new FormData(form)) keeps only the last; read them all with formData.getAll("interest").
disabled (checked or not)NothingDisabled controls are skipped. To send a fixed value, use a hidden input instead.
indeterminate set in JavaScriptWhatever its checked state saysIndeterminate only changes how the box looks. It is not an HTML attribute and is never submitted.
No name attributeNothingOnly named controls are submitted; id does not count.

These are the checkbox rows only. The other input types are listed with their submitted values in the input types table.

Sources: WHATWG HTML Standard: constructing the entry list · WHATWG HTML Standard: checkbox state · WHATWG HTML Standard: indeterminate · MDN: checkbox value · MDN: FormData.getAll()

Checked state

How do you check if a checkbox is checked?

Read the checked property in JavaScript: box.checked is true when the box is ticked and false when it is not. In CSS, the :checked selector matches a ticked box. The checked attribute in the HTML only sets the starting state, so do not read it to learn what the person chose.

How do you check if a checkbox is checked?
Way to checkExampleWhat to know
checked propertybox.checkedThe live state, true or false. Read this one; it changes as the person clicks.
:checked in CSSinput:checked + spanStyles ticked boxes with no script. :indeterminate matches a box whose indeterminate property is true.
Every ticked box in a groupdocument.querySelectorAll("input[name=interest]:checked")Returns only the ticked boxes. Map them to box.value to get the answers.
FormDatanew FormData(form).has("agree")true only for a ticked, enabled, named box. That is exactly what the server receives.
defaultChecked propertybox.defaultCheckedMirrors the checked attribute, the state form.reset() goes back to. After a click or box.checked = true, changing the attribute no longer changes what the box shows.
value propertybox.valueThe value attribute, or on when there is none, whether or not the box is ticked. It is not the checked state.
indeterminate propertybox.indeterminateSeparate from checked: a box can be indeterminate and checked at once, so read both when you use it.

Submitted to a form backend like splitforms, a ticked box arrives as name=value; an unticked one is simply missing from the submission.

Sources: MDN: HTMLInputElement checked · MDN: HTMLInputElement indeterminate · WHATWG HTML Standard: checkbox state · MDN: checkbox checked

Events

Which events does an HTML checkbox fire?

A checkbox fires input and then change when the person toggles it, plus a click event first. Use change to react to a new state: event.target.checked already holds it. Setting box.checked from a script fires none of them.

Which events does an HTML checkbox fire?
EventWhen it firesWhat to know
changeAfter a user toggle: a click, a tap, the Space key, or a click on its label.The usual choice. It bubbles, so one listener on the <form> covers every box.
inputRight before change, on the same toggle.Checkboxes fire it too, but it adds nothing over change, so pick one.
clickOn a mouse click, a tap, the Space key, a click on the label or a call to box.click().Fires before change. checked already shows the new state inside the handler, and preventDefault() puts it back. A label click fires click on the label and again on the box.
invalidWhen a submit or reportValidity() finds a required box unchecked.It does not bubble, so listen on the box itself. Use it to set a custom message.
No eventA script sets box.checked or box.indeterminate, or form.reset() runs.Neither change nor input fires. Dispatch one yourself with box.dispatchEvent(new Event("change", { bubbles: true })) if other code listens.

Sources: MDN: change event · MDN: input event · WHATWG HTML Standard: checkbox state

Checkbox vs radio

What is the difference between a checkbox and a radio button?

A checkbox is independent: a visitor can tick any number of boxes in a group. A radio button is exclusive: a group of radios with the same name allows exactly one choice. Use checkboxes for multiple answers and radios for one answer.

What is the difference between a checkbox and a radio button?
ControlHow many can be pickedSame name meansUse it for
CheckboxAny number, including noneIndependent answers: each ticked box sends its own name=valueInterests, toppings, opt-in
Radio buttonExactly oneOne exclusive group: picking another clears the firstSize, plan, delivery
Checkbox with requiredAt least oneThe group must have a tickTerms, topics
Radio with requiredOneThe group must have a choiceRequired size or plan

Sources: WHATWG HTML Standard: checkbox state · MDN: input type=radio

Attributes · <input type="checkbox">

Which HTML Checkbox attributes matter?

These attributes decide how the <input type="checkbox"> behaves and what actually gets emailed to your inbox when someone submits.

HTML Checkbox attributes and what each one does
AttributeWhat it doesDocs
nameThe key the value is submitted under. Boxes in a group can share a name; each checked one adds its own name=value pair.MDN
valueWhat's sent when the box is checked. Without it, the browser submits the literal "on".MDN
checkedBoolean. Pre-checks the box when the page loads.MDN
requiredBoolean. Forces this box to be checked before the form can submit (useful for "I agree" consent). It can't express "at least one of a group".MDN
disabledGreys out the box and excludes it from submission, even when it is checked.MDN
indeterminateNot an HTML attribute: a JavaScript property (box.indeterminate = true) that draws a mixed state. It changes the look only; the box still submits by its checked state.MDN

Common mistakes

HTML Checkbox not working? Here's why.

Most broken forms come down to a few small mistakes with the <input type="checkbox">. Check these before you ship, then forward every submission to Slack or a webhook.

  1. Unchecked = not submitted

    If a checkbox is unchecked, its name is absent from the submission entirely — not sent as false. Detect this server-side as "key missing".

  2. Without value, you get "on"

    A checked checkbox with no value= submits the string "on". Always set a meaningful value so you can tell states apart.

  3. Checkbox vs radio

    Checkboxes are independent (tick any number); radios in a group are mutually exclusive (pick one). Use radios when exactly one choice is allowed.

  4. Wrap it in a label

    A bare box is a tiny click target with no accessible name. Put the <input> inside a <label>, or link them with for and id, so clicking the text toggles the box and screen readers announce it.

Sources: WHATWG HTML Standard: <input type="checkbox"> · MDN: <input type="checkbox">

fieldset + legend

How do I make a checkbox list (checklist) in HTML?

Put the boxes in a <fieldset>, caption the group with a <legend>, give every box the same name and its own value, and wrap each one in a <label> so its text toggles it. Each ticked box sends its own name=value pair, so a three-item checklist with two ticks sends two pairs.

Stack the labels with display: block for a vertical list. required on one box only requires that box; to require any one of them, see at least one checkbox.

checklist.html
<form action="https://splitforms.com/api/submit" method="POST">
  <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY">

  <fieldset class="checklist">
    <legend>Before launch</legend>
    <label><input type="checkbox" name="done" value="dns"> DNS records set</label>
    <label><input type="checkbox" name="done" value="ssl"> SSL certificate live</label>
    <label><input type="checkbox" name="done" value="backup"> Backup tested</label>
  </fieldset>

  <button type="submit">Save checklist</button>
</form>

<style>
  .checklist label { display: block; margin: 6px 0; }
</style>

<!-- Ticking DNS and Backup sends: done=dns&done=backup -->

.checked

How do I get the checked values in JavaScript?

Read box.checked for one box. For a group, select the ticked boxes with :checked and map them to their value. One change listener on the form covers every box and runs after each toggle.

read-checked.html
<form id="prefs">
  <label><input type="checkbox" name="interest" value="newsletter"> Newsletter</label>
  <label><input type="checkbox" name="interest" value="beta"> Beta access</label>
  <label><input type="checkbox" name="terms" value="yes"> I agree</label>
</form>

<script>
  const form = document.getElementById("prefs");

  form.addEventListener("change", () => {
    // One box: true or false
    const agreed = form.elements.terms.checked;

    // A group: the value of every ticked box
    const interests = [...form.querySelectorAll("input[name=interest]:checked")]
      .map((box) => box.value); // ["newsletter", "beta"]

    console.log({ agreed, interests });
  });
</script>

type="hidden"

How do I send a value when the checkbox is unchecked?

Put a hidden input with the same name before the checkbox. Unchecked, only the hidden value is sent (newsletter=no). Checked, both are sent in page order (newsletter=no&newsletter=yes), so a server that keeps the last value for a repeated name reads yes. PHP's $_POST, Rails, Django's request.POST[key] and Object.fromEntries() all keep the last value.

The hidden input must come first. Servers that keep every value (Express body parsers, splitforms) receive both no and yes when the box is ticked, so read the last one. Flask's request.form.get() returns the first value; use getlist() there.

unchecked-value.html
<form action="https://splitforms.com/api/submit" method="POST">
  <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY">

  <!-- Always sent. Must come BEFORE the checkbox. -->
  <input type="hidden" name="newsletter" value="no">
  <label>
    <input type="checkbox" name="newsletter" value="yes">
    Send me the newsletter
  </label>

  <button type="submit">Send</button>
</form>

<!-- Unchecked: newsletter=no
     Checked:   newsletter=no&newsletter=yes -->

indeterminate

How do I make a select-all checkbox with an indeterminate state?

Give the select-all box no name, so it is never submitted. When it changes, copy its checked state to every box in the group. When one of those changes, count the ticked ones: all ticked checks the select-all box, none unchecks it, and anything in between sets indeterminate = true, the mixed state.

indeterminate exists only in JavaScript and only changes the look. Clicking a box clears it, and the box still submits by its checked state.

select-all.html
<label><input type="checkbox" id="all"> Select all topics</label>

<fieldset id="topics">
  <legend>Topics</legend>
  <label><input type="checkbox" name="topic" value="pricing"> Pricing</label>
  <label><input type="checkbox" name="topic" value="api"> API</label>
  <label><input type="checkbox" name="topic" value="security"> Security</label>
</fieldset>

<script>
  const all = document.getElementById("all");
  const boxes = [...document.querySelectorAll('#topics input[type="checkbox"]')];

  all.addEventListener("change", () => {
    boxes.forEach((box) => (box.checked = all.checked));
  });

  boxes.forEach((box) =>
    box.addEventListener("change", () => {
      const ticked = boxes.filter((b) => b.checked).length;
      all.checked = ticked === boxes.length;
      all.indeterminate = ticked > 0 && ticked < boxes.length;
    }),
  );
</script>

setCustomValidity

How do I require at least one checkbox in a group?

required on a checkbox means that particular box must be ticked, so it can't say "any one of these". Instead, set a custom validity message on the first box while none is checked. The browser then blocks the submit and shows your message, exactly like a required field, and clears it as soon as one box is ticked. How plain required behaves on every control is covered in the HTML required attribute reference.

This is a browser-side check. Anyone can post to your endpoint without it, so check the group on the server too. For a 1-to-3 limit, :has() styling and React, see require at least one checkbox.

require-one.html
<fieldset id="topics">
  <legend>Which topics? (pick at least one)</legend>
  <label><input type="checkbox" name="topic" value="pricing"> Pricing</label>
  <label><input type="checkbox" name="topic" value="api"> API</label>
  <label><input type="checkbox" name="topic" value="security"> Security</label>
</fieldset>

<script>
  const boxes = [...document.querySelectorAll('#topics input[type="checkbox"]')];

  function checkGroup() {
    const ok = boxes.some((b) => b.checked);
    boxes[0].setCustomValidity(ok ? "" : "Pick at least one topic.");
  }

  boxes.forEach((b) => b.addEventListener("change", checkGroup));
  checkGroup(); // invalid until a box is ticked
</script>

Copy-paste ready

The HTML Checkbox example below is a complete, working form — paste it into any HTML page and it submits, no edits to the markup required.

No backend to build

Your html checkbox form posts to one endpoint. No server, PHP, or API route — accepted submissions are saved to your dashboard before owner notification email is attempted; delivery time and inbox placement depend on provider and recipient settings.

A form that really submits

Unlike a static reference snippet, this <input type="checkbox"> form actually sends data to a free splitforms backend, with spam filtering built in.

How it works

How to add HTML Checkbox to any page.

Copy the html checkbox example, drop in your free access key, and paste it into any page — submissions start landing in your dashboard.

Copy the code

Copy the HTML Checkbox example below.

Add your access key

Replace YOUR_ACCESS_KEY with a free splitforms key from the dashboard.

Paste into your site

Drop the form into any HTML page. Submissions arrive in your dashboard.

Questions

HTML Checkbox questions, answered.

View all FAQs
How do I check if a checkbox is checked?

Read its checked property: document.getElementById("agree").checked is true or false. For a group, document.querySelectorAll("input[name=interest]:checked") returns only the ticked boxes. In CSS, the :checked selector matches a ticked box. The checked attribute in the HTML only sets the starting state.

Which events does an HTML checkbox fire?

When the person toggles it, a checkbox fires click, then input, then change. Use change and read event.target.checked for the new state. Setting box.checked from JavaScript fires none of them, so dispatch a change event yourself if other code listens.

How do I add a checkbox in HTML?

Use <input type="checkbox" name="agree" value="yes">, wrapped in a <label> so the text is clickable. Add checked to pre-tick it, and required to force it on (common for consent).

What is input type checkbox in HTML?

input type="checkbox" creates a box the user can tick or untick. It sends its name=value only when checked, and nothing when unchecked. Wrap it in a <label> so the text is clickable, and add checked to pre-tick it.

How do I add a label to a checkbox?

Wrap the box in the label: <label><input type="checkbox" name="news" value="yes"> Email me news</label>, or give the box an id and point <label for="..."> at it. Either way, clicking the text toggles the box and screen readers read the text as its name.

How do I make a checklist in HTML?

Use a <fieldset> with a <legend>, then one <label><input type="checkbox" name="done" value="..."> item</label> per line, all with the same name. Each ticked item is submitted as its own name=value pair; style the labels with display: block for a vertical list.

What value does a checkbox submit?

When checked, it submits its value= attribute. If value= is missing it submits "on". When unchecked, nothing is submitted for that name at all.

How do I let users select multiple options?

Give each checkbox the same name (e.g. name="interest") and a different value. Each checked box sends its own pair (interest=beta&interest=demo). Read all of them with formData.getAll("interest"). Object.fromEntries() keeps only the last one, and so does PHP's $_POST unless the name ends in [].

How do I make an HTML checkbox checked?

Add the checked attribute: <input type="checkbox" name="news" value="yes" checked>. The box is ticked when the page loads, and form.reset() returns it to that state. In JavaScript, set box.defaultChecked = true or box.checked = true; the attribute only sets the starting state.

How do I get a checkbox value in a form?

Read it from the submitted data: a checked box arrives as name=value, and an unchecked one is missing. In JavaScript, new FormData(form).get("news") returns the value when checked and null when not, while formData.getAll("interest") returns every ticked value in a group. On the server, read the same name from the POST body.

How do I send an unchecked checkbox value?

Put a hidden input with the same name and the "off" value before the checkbox: <input type="hidden" name="newsletter" value="no">. Unchecked, only no is sent; checked, no and then yes are sent, so a server that keeps the last value reads yes. The full walkthrough is in [send a value when a checkbox is unchecked](/blog/send-unchecked-checkbox-value).

How do I pre-check a checkbox?

Add the checked attribute: <input type="checkbox" name="news" value="yes" checked>. It will be ticked when the page loads.

Why doesn't my unchecked checkbox submit anything?

By design — an unchecked checkbox is not included in the form data. Treat the absence of the key as the unchecked state in your backend, rather than expecting a false value.

How do I send a value when a checkbox is unchecked?

Add <input type="hidden" name="newsletter" value="no"> before the checkbox with the same name. Unchecked, only "no" is sent; checked, "no" and then "yes" are sent, and servers that keep the last value (PHP, Rails, Django) read "yes".

Is an indeterminate checkbox submitted?

Only if it is checked. indeterminate is a JavaScript property that only changes how the box looks, so the box submits by its checked state like any other checkbox: name=value when checked, nothing when unchecked. Clicking it clears the indeterminate state.

How do I require at least one checkbox in a group?

required can't do it, because it applies to a single box. Use JavaScript: while no box is checked, call setCustomValidity("Pick at least one") on the first box, and clear it with setCustomValidity("") once one is ticked.

Simple pricing

How much does splitforms cost?

Free gives you 500 submissions for $0 — no card, no time limit. Pro is $5/month for 5,000 submissions a month, and Annual is $49/year for 15,000 a month with every Pro feature.

Free

$0— 500 submissions
 

No card, no time limit

Best for testing

For side projects and indie devs.

  • 500 free submissions
  • Unlimited forms
  • Email notifications included
  • Smart spam filtering
  • Submissions dashboard
  • Redirect after submit
  • MCP server included

Annual

$49/ year
About $4.08 per month, billed yearly
Best value

Every Pro feature with triple the volume — $0.27 per 1,000 at full use.

  • 15,000 submissions per month
  • Unlimited forms
  • Everything in Pro
  • File uploads with 5 GB storage
  • 3 team seats
  • Priority email support

No credit card required on Free • Cancel anytime • Full pricing and FAQ