Checkbox

Checkboxes can be used to allow users to select single values for submission in a form (or not). Halfmoon comes with a custom checkbox design which works across browsers.

<!-- First checkbox -->
<div class="custom-checkbox">
  <input type="checkbox" id="checkbox-1" value="">
  <label for="checkbox-1">Checkbox 1</label>
</div>

<!-- Second checkbox (checked by default) -->
<div class="custom-checkbox">
  <input type="checkbox" id="checkbox-2" value="" checked="checked">
  <label for="checkbox-2">Checkbox 2</label>
</div>

The following things should be kept in mind when using checkboxes in Halfmoon:

  • The <label> element is a requirement, as without it, the custom checkbox will not be rendered.
  • The <input> element must have the type="checkbox" attribute.
  • The <label> element must come after the <input> element in the container with the .custom-checkbox class.
  • The id="..." attribute of the input and the for="..." attribute of the label should have the same value.
  • Containers with the class .custom-checkbox have no margins (margin: 0) by default. The vertically stacked ones on this page are styled to have a margin on the bottom using a utility class. This is not shown in the code for the sake of conciseness. We recommend using a wrapper with the .form-group class inside forms. This will add a margin between the elements. See the example here (opens in new tab).

Horizontal stacking #

By default, the containers with the class .custom-checkbox have the display: block property. However, they can be stacked horizontally by adding the .d-inline-block utility class to them.

<!-- Horizontally stacked checkboxes -->
<div class="custom-checkbox d-inline-block mr-10"> <!-- d-inline-block = display: inline-block, mr-10 = margin-right: 1rem (10px) -->
  <input type="checkbox" id="checkbox-3" value="">
  <label for="checkbox-3">Checkbox 3</label>
</div>
<div class="custom-checkbox d-inline-block">
  <input type="checkbox" id="checkbox-4" value="">
  <label for="checkbox-4">Checkbox 4</label>
</div>

Disabled checkboxes #

Checkboxes can be disabled by adding the disabled="..." attribute to them.

<!-- Disabled checkboxes -->
<div class="custom-checkbox">
  <input type="checkbox" id="checkbox-5" value="" disabled="disabled">
  <label for="checkbox-5">Checkbox 5 (disabled)</label>
</div>
<div class="custom-checkbox">
  <input type="checkbox" id="checkbox-6" value="" checked="checked" disabled="disabled">
  <label for="checkbox-6">Checkbox 6 (disabled)</label>
</div>

Empty label #

As mentioned above, the <label> element is a requirement. When creating checkboxes with empty labels, the contents of the label should be kept empty, but the element should still be there. Also, the class .blank should be added to the label. This will remove the extra margin. The next example shows a checkbox with an empty label inside an input group.

<!-- Input group with checkbox -->
<div class="input-group">
  <div class="input-group-prepend">
    <div class="input-group-text">
      <!-- Checkbox with empty label -->
      <div class="custom-checkbox">
        <input type="checkbox" id="checkbox-7" value="">
        <label for="checkbox-7" class="blank"></label>
      </div>
    </div>
  </div>
  <input type="text" class="form-control" placeholder="Input group with checkbox">
</div>

Up next: Radio

Coming soon

  • More components
  • More variables and customization
  • Form builder and validator JS
  • Themes and templates

Subscribe for updates


  • We will notify you when the framework gets a substantial update. No spam or marketing.
  • You can also follow us on Twitter and stay updated that way.