1802

This is one of the minor CSS problems that plague me constantly.

How do folks around Stack Overflow vertically align checkboxes and their labels consistently cross-browser?

Whenever I align them correctly in Safari (usually using vertical-align: baseline on the input), they're completely off in Firefox and IE.

Fix it in Firefox, and Safari and IE are inevitably messed up. I waste time on this every time I code a form.

Here's the standard code that I work with:

<form>
    <div>
        <label><input type="checkbox" /> Label text</label>
    </div>
</form>

I usually use Eric Meyer's reset, so form elements are relatively clean of overrides. Looking forward to any tips or tricks that you have to offer!

Not A Bot
  • 2,220
  • 2
  • 10
  • 24
One Crayon
  • 18,759
  • 9
  • 30
  • 38
  • 7
    Put each checkbox and label within an
  • element. Add overflow:hidden to the
  • and float the label and checkbox left. Then they all align perfectly fine. Don't put the checkbox within the label element obviously.
  • – volume one Jan 18 '14 at 18:37
  • 5
    I have acieved it by using `height` and `line-height` attributes, give a look to http://jsfiddle.net/wepw5o57/3/ – TheGr8_Nik Dec 09 '14 at 13:41
  • Manipulation with `position` and `top` will solve this problem Example: https://jsfiddle.net/ynkjc22s/ – Profesor08 Apr 09 '16 at 12:59
  • 2019. still the same issue. still need some hacks to get it work :( – dieter Apr 06 '19 at 08:40
  • @dieter see my answer, I've explained why hacks are needed and what approach is not hacky: https://stackoverflow.com/a/56558431/3995261 – YakovL Jun 12 '19 at 10:31