Coding Hubs School of AI – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 8448811540
Back to HTML Notes
Topic #712

Checkbox

<input type="checkbox"> represents an independent on/off choice — each checkbox is its own separate toggle, unrelated to any others on the page unless you deliberately group them.

Syntax

<input type="checkbox" name="subscribe" id="subscribe" checked>
<label for="subscribe">Subscribe to newsletter</label>

Basic Example

<input type="checkbox" id="terms" name="terms" required>
<label for="terms">I agree to the Terms and Conditions</label>

Browser output: a small square box the user can click to toggle checked/unchecked; the label text is also clickable, toggling the checkbox too, since they're properly associated.

How It Works

A checked checkbox submits its value (defaulting to "on" if unspecified) under its name. An unchecked checkbox sends nothing at all — its name doesn't appear in the submitted data whatsoever, which trips up a lot of beginners expecting a "false" value.

Important Attributes

AttributePurpose
checkedPre-checks the box by default
valueWhat gets submitted when checked (defaults to "on")
nameUse the same name with [] across several checkboxes to collect them as one array of selected values

Real-World Example

<fieldset>
    <legend>Which topics interest you?</legend>
    <input type="checkbox" id="topic-ai" name="topics[]" value="ai">
    <label for="topic-ai">AI & Machine Learning</label>

    <input type="checkbox" id="topic-web" name="topics[]" value="web">
    <label for="topic-web">Web Development</label>
</fieldset>

Multiple independent checkboxes sharing a name with [] — any number of them can be checked, and the server receives an array of every selected value.

Common Mistakes

  • Expecting an unchecked checkbox to submit as false or empty — it submits nothing at all, which server-side code must account for
  • Skipping a real <label> and relying on nearby text alone — this loses the larger, more forgiving click target a proper label provides

Best Practices

  • Always pair each checkbox with a real, associated <label>
  • Group related checkboxes in a <fieldset> with a <legend>

Accessibility Considerations

A properly labeled checkbox lets users click either the box or its text to toggle it — a meaningfully larger, more forgiving target than the tiny checkbox square alone, which matters a great deal for users with motor impairments.

SEO Considerations

No direct ranking effect.

Browser & Modern HTML Notes

Checkbox appearance can be styled with modern CSS (including the accent-color property for a quick native-looking color change) without needing to fully rebuild the control from scratch.

Mini Practice

  1. Build 3 independent, properly labeled checkboxes for a "select your interests" section.
  2. Explain what value is submitted for an unchecked checkbox with no explicit value attribute.

Related HTML Notes

Want to go beyond the notes?

Join Coding Hubs School of AI's HTML course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →