6

How can I hide a checkbox using HTML / CSS?

Let's say I have

<table>
  <thead>
    <th>
      Col A
    </th>
    <th>
      Col B
    </th>
  </thead>
  <tbody>
    <tr>
      <td> <input type="checkbox" class="hidden"> Some stuff </td>
    </tr>
    <tr>
      <td> Some Other stuff </td>
    </tr>
  </tbody>
</table>

The name and the values of the checkbox are not constant. I know there's some way with jquery but is there a way to hide it with pure CSS or HTML?

1
  • The answers below all work, the real question is why would you want to? If you're trying to pass data to a form, just use <input type="hidden" name="V" value="B" /> Commented May 15, 2014 at 15:54

5 Answers 5

24

Please keep in mind that setting the display property to none, makes the element inaccessible using tabs (see: Checkbox tab index not working when set to hidden with custom design). If you case about accessibility, you can use:

input[type=checkbox].hidden{
  opacity: 0;
}
Sign up to request clarification or add additional context in comments.

Comments

6
.hidden {
    display: none;
}

This will hide the checkbox (or any HTML item with the class of "hidden") from display. The checkbox still exists in HTML and can be enabled/disabled with Javascript or by visitors with developer tools.

2 Comments

The checkbox might also not be submitted correctly.
Keep in mind that setting display: none also hides the checkbox in screen readers and disables the default tab focus.
3

Simple enough!

input[type=checkbox].hidden{
   display:none;
}

Or if you want to be crazy and use inline styles (best to avoid):

<input type="checkbox" class="hidden" name="V" value="B" style="display:none;">

4 Comments

Thanks for that quick answer. However, I have multiple checkboxes inside my table with different names and values so I can't therefore rely on this.
@Wistar - I've amended, not you can use CSS to target an element on id class decendancy or any attribute
Thats odd, it is effectively the same as the OPs accepted answer above :S its likely you may have a different issue?
Crazy and use inline styles LOL? If I know hiding the box is forever I only use inline styling.
-1

you have class hidden added to that checkbox.

input[type=checkbox].hidden {
   display:none;
}

or just

.hidden {
   display:none;
}

Comments

-1
.hidden{
display:none;
}

this will work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.