[html] How to align checkboxes and their labels consistently cross-browsers

This is one of the minor CSS problems that plagues 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:

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

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!

This question is related to html css cross-browser alignment forms

The answer is


try vertical-align: middle

also your code seems like it should be:

_x000D_
_x000D_
<form>_x000D_
    <div>_x000D_
        <input id="blah" type="checkbox"><label for="blah">Label text</label>_x000D_
    </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_


I've never had a problem with doing it like this:

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

Try my solution, I tried it in IE 6, FF2 and Chrome and it renders pixel by pixel in all the three browsers.

_x000D_
_x000D_
* {_x000D_
  padding: 0px;_x000D_
  margin: 0px;_x000D_
}_x000D_
#wb {_x000D_
  width: 15px;_x000D_
  height: 15px;_x000D_
  float: left;_x000D_
}_x000D_
#somelabel {_x000D_
  float: left;_x000D_
  padding-left: 3px;_x000D_
}
_x000D_
<div>_x000D_
  <input id="wb" type="checkbox" />_x000D_
  <label for="wb" id="somelabel">Web Browser</label>_x000D_
</div>
_x000D_
_x000D_
_x000D_


position: relative; has some issues in IE with z-index and animations like jQuery's slideUp/slideDown.

CSS:

input[type=checkbox], input[type=radio] {
    vertical-align: baseline;
    position: relative;
    top: 3px;
    margin: 0 3px 0 0;
    padding: 0px;
}
input.ie7[type=checkbox], input.ie7[type=radio] {
    vertical-align: middle;
    position: static;
    margin-bottom: -2px;
    height: 13px;
    width: 13px;
}

jQuery:

$(document).ready(function () {
    if ($.browser.msie && $.browser.version <= 7) {
        $('input[type=checkbox]').addClass('ie7');
        $('input[type=radio]').addClass('ie7');
    }
});

The styling probably needs tweaks depending on the font-size used in <label>

PS:
I use ie7js to make the css work in IE6.


The following gives pixel-perfect consistency across browsers, even IE9:

The approach is quite sensible, to the point of being obvious:

  1. Create an input and a label.
  2. Display them as block, so you can float them as you like.
  3. Set the height and the line-height to the same value to ensure they center and align vertically.
  4. For em measurements, to calculate the height of the elements, the browser must know the height of the font for those elements, and it must not itself be set in em measurements.

This results in a globally applicable general rule:

input, label {display:block;float:left;height:1em;line-height:1em;}

With font size adaptable per form, fieldset or element.

#myform input, #myform label {font-size:20px;}

Tested in latest Chrome, Safari, and Firefox on Mac, Windows, Iphone, and Android. And IE9.

This method is likely applicable to all input types that are not higher than one line of text. Apply a type rule to suit.


I usually leave a checkbox unlabeled and then make its "label" a separate element. It's a pain, but there's so much cross-browser difference between how checkboxes and their labels are displayed (as you've noticed) that this is the only way I can come close to controlling how everything looks.

I also end up doing this in winforms development, for the same reason. I think the fundamental problem with the checkbox control is that it is really two different controls: the box and the label. By using a checkbox, you're leaving it up to the implementers of the control to decide how those two elements are displayed next to each other (and they always get it wrong, where wrong = not what you want).

I really hope someone has a better answer to your question.


Sometimes vertical-align needs two inline (span, label, input, etc...) elements next to each other to work properly. The following checkboxes are properly vertically centered in IE, Safari, FF, and Chrome, even if the text size is very small or large.

They all float next to each other on the same line, but the nowrap means that the whole label text always stays next to the checkbox.

The downside is the extra meaningless SPAN tags.

_x000D_
_x000D_
.checkboxes label {_x000D_
  display: inline-block;_x000D_
  padding-right: 10px;_x000D_
  white-space: nowrap;_x000D_
}_x000D_
.checkboxes input {_x000D_
  vertical-align: middle;_x000D_
}_x000D_
.checkboxes label span {_x000D_
  vertical-align: middle;_x000D_
}
_x000D_
<form>_x000D_
  <div class="checkboxes">_x000D_
    <label for="x"><input type="checkbox" id="x" /> <span>Label text x</span></label>_x000D_
    <label for="y"><input type="checkbox" id="y" /> <span>Label text y</span></label>_x000D_
    <label for="z"><input type="checkbox" id="z" /> <span>Label text z</span></label>_x000D_
  </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_

Now, if you had a very long label text that needed to wrap without wrapping under the checkbox, you'd use padding and negative text indent on the label elements:

_x000D_
_x000D_
.checkboxes label {_x000D_
  display: block;_x000D_
  padding-right: 10px;_x000D_
  padding-left: 22px;_x000D_
  text-indent: -22px;_x000D_
}_x000D_
.checkboxes input {_x000D_
  vertical-align: middle;_x000D_
}_x000D_
.checkboxes label span {_x000D_
  vertical-align: middle;_x000D_
}
_x000D_
<form>_x000D_
  <div class="checkboxes">_x000D_
    <label for="x"><input type="checkbox" id="x" /> <span>Label text x so long that it will probably wrap so let's see how it goes with the proposed CSS (expected: two lines are aligned nicely)</span></label>_x000D_
    <label for="y"><input type="checkbox" id="y" /> <span>Label text y</span></label>_x000D_
    <label for="z"><input type="checkbox" id="z" /> <span>Label text z</span></label>_x000D_
  </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_


Try my solution, I tried it in IE 6, FF2 and Chrome and it renders pixel by pixel in all the three browsers.

_x000D_
_x000D_
* {_x000D_
  padding: 0px;_x000D_
  margin: 0px;_x000D_
}_x000D_
#wb {_x000D_
  width: 15px;_x000D_
  height: 15px;_x000D_
  float: left;_x000D_
}_x000D_
#somelabel {_x000D_
  float: left;_x000D_
  padding-left: 3px;_x000D_
}
_x000D_
<div>_x000D_
  <input id="wb" type="checkbox" />_x000D_
  <label for="wb" id="somelabel">Web Browser</label>_x000D_
</div>
_x000D_
_x000D_
_x000D_


Maybe some folk are making the same mistake I did? Which was... I had set a width for the input boxes, because they were mostly of type 'text' , but then forgotten to over-ride that width for checkboxes - so my checkbox was trying to occupy a lot of excess width and so it was tough to align a label beside it.

.checkboxlabel {
    width: 100%;
    vertical-align: middle;
}
.checkbox {
    width: 20px !important;
}
<label for='acheckbox' class='checkboxlabel'>
    <input name="acheckbox" id='acheckbox' type="checkbox" class='checkbox'>Contact me</label>

Gives clickable labels and and proper alignment as far back as IE6 (using a class selector) and in late versions of Firefox, Safari and Chrome


I've never had a problem with doing it like this:

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

try vertical-align: middle

also your code seems like it should be:

_x000D_
_x000D_
<form>_x000D_
    <div>_x000D_
        <input id="blah" type="checkbox"><label for="blah">Label text</label>_x000D_
    </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_


try this code

input[type="checkbox"] {
    -moz-appearance: checkbox;
    -webkit-appearance: checkbox;
    margin-left:3px;
    border:0;
    vertical-align: middle;
    top: -1px;
    bottom: 1px;
    *overflow: hidden;
    box-sizing: border-box; /* 1 */
    *height: 13px; /* Removes excess padding in IE 7 */
    *width: 13px;
    background: #fff;
}

This works well for me:

_x000D_
_x000D_
fieldset {_x000D_
  text-align:left;_x000D_
  border:none_x000D_
}_x000D_
fieldset ol, fieldset ul {_x000D_
  padding:0;_x000D_
  list-style:none_x000D_
}_x000D_
fieldset li {_x000D_
  padding-bottom:1.5em;_x000D_
  float:none;_x000D_
  clear:left_x000D_
}_x000D_
label {_x000D_
  float:left;_x000D_
  width:7em;_x000D_
  margin-right:1em_x000D_
}_x000D_
fieldset.checkboxes li {_x000D_
  clear:both;_x000D_
  padding:.75em_x000D_
}_x000D_
fieldset.checkboxes label {_x000D_
  margin:0 0 0 1em;_x000D_
  width:20em_x000D_
}_x000D_
fieldset.checkboxes input {_x000D_
  float:left_x000D_
}
_x000D_
<form>_x000D_
  <fieldset class="checkboxes">_x000D_
    <ul>_x000D_
      <li>_x000D_
        <input type="checkbox" name="happy" value="yep" id="happy" />_x000D_
        <label for="happy">Happy?</label>_x000D_
      </li>_x000D_
      <li>_x000D_
        <input type="checkbox" name="hungry" value="yep" id="hungry" />_x000D_
        <label for="hungry">Hungry?</label>_x000D_
      </li>_x000D_
    </ul>_x000D_
  </fieldset>_x000D_
</form>
_x000D_
_x000D_
_x000D_


Try my solution, I tried it in IE 6, FF2 and Chrome and it renders pixel by pixel in all the three browsers.

_x000D_
_x000D_
* {_x000D_
  padding: 0px;_x000D_
  margin: 0px;_x000D_
}_x000D_
#wb {_x000D_
  width: 15px;_x000D_
  height: 15px;_x000D_
  float: left;_x000D_
}_x000D_
#somelabel {_x000D_
  float: left;_x000D_
  padding-left: 3px;_x000D_
}
_x000D_
<div>_x000D_
  <input id="wb" type="checkbox" />_x000D_
  <label for="wb" id="somelabel">Web Browser</label>_x000D_
</div>
_x000D_
_x000D_
_x000D_


One easy thing that seems to work well is to apply a adjust the vertical position of the checkbox with vertical-align. It will still be vary across browsers, but the solution is uncomplicated.

input {
    vertical-align: -2px;
}

Reference


This is not the best way of going about solving the issue

vertical-align: middle

Adding style="position:relative;top:2px;" to the input box would move it down 2px. So depending on your font size, you can move it along.


_x000D_
_x000D_
input[type=checkbox]_x000D_
{_x000D_
    vertical-align: middle;_x000D_
} 
_x000D_
<input id="testCheckbox" name="testCheckbox" type="checkbox">_x000D_
<label for="testCheckbox">I should align</label>
_x000D_
_x000D_
_x000D_


If you're using Twitter Bootstrap, you can just use the checkbox class on the <label>:

<label class="checkbox">
    <input type="checkbox"> Remember me
</label>

So I know this has been answered many times, but I feel I have a way more elegant solution than those that have been provided already. And not only 1 elegant solution, but 2 separate solutions to tickle your fancy. With that said, everything you need to know and see are contained in 2 JS Fiddle's, with comments.


Solution #1 relies on the native "Checkbox" of the given browser, though with a twist... Its contained in a div which is easier to position cross-browser, with an overflow: hidden to chop the excess of a 1px stretched checkbox (this is so you cant see the ugly borders of FF)

Simple HTML: (follow the link to review the css with comments, code block is to satisfy stackoverflow) http://jsfiddle.net/KQghJ/

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

Solution #2 uses the "Checkbox Toggle Hack" to toggle the CSS state of a DIV, which has been properly positioned across browser, and setup with a simple sprite for the checkbox unchecked and checked states. All that is needed is to adjust the background-position with said Checkbox Toggle Hack. This, in my opinion, is the more elegant solution as you have more control over your checkboxes & radios, and can guarantee they look the same across browser.

Simple HTML: (follow the link to review the CSS with comments, code block is to satisfy StackOverflow) http://jsfiddle.net/Sx5M2/

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

If anyone disagree's with these methods, please leave me a comment, I would love to hear some feedback on why others have not come across these solutions, or if they have, why I see no answers here regarding them? If anyone sees one of these methods fail, it would be nice to see that too, but these have been tested in the latest browsers and rely on HTML / CSS methods that are quite old, and universal as far as I have seen.


Use simply vertical-align: sub, as pokrishka already suggested.

Fiddle

HTML Code:

<div class="checkboxes">
    <label for="check1">Test</label>
    <input id="check1" type="checkbox"></input>
</div>

CSS Code:

.checkboxes input {
    vertical-align: sub;
}

For consistency with form fields across browsers we use : box-sizing: border-box

button, checkbox, input, radio, textarea, submit, reset, search, any-form-field {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

<fieldset class="checks">
    <legend>checks for whatevers</legend>
    <input type="" id="x" />
    <label for="x">Label</label>
    <input type="" id="y" />
    <label for="y">Label</label>
    <input type="" id="z" />
    <label for="z">Label</label>
</fieldset>

You should wrap form controls grouped together in their own fieldsets anyways, here, it plays the wrappa. set input/label do display:block, input float left, label float right, set your widths, control spacing with left/right margins, align label text accordingly.

so

fieldset.checks {
    width:200px
}
.checks input, .checks label {
    display:block;
}
.checks input {
    float:right;
    width:10px;
    margin-right:5px
}
.checks label {
    float:left;
    width:180px;
    margin-left:5px;
    text-align:left;
    text-indent:5px
}

you probably need to set border, outline and line-height on both as well for cross-browser/media solutions.


Hardcode the checkbox's height and width, remove its padding, and make its height plus vertical margins equal to the label's line-height. If the label text is inline, float the checkbox. Firefox, Chrome, and IE7+ all render the following example identically: http://www.kornea.com/css-checkbox-align


With an input type checkbox wrapped inside the label and floated to the left like so:

<label for="id" class="checkbox">
    <input type="checkbox" id="id">
    <span>The Label</span>
</label>

this worked for me:

label.checkbox {
    display: block;
}
.checkbox input {
    float: left;
    height: 18px;
    vertical-align: middle;
}
.checkbox span {
    float: left;
    line-height: 18px;
    margin: 0 0 0 20px;
}

Make sure the height of the is identical to the line-height of the (blocklevel) .


I usually use line height in order to adjust the vertical position of my static text:

_x000D_
_x000D_
label {_x000D_
  line-height: 18px;_x000D_
}_x000D_
input {_x000D_
  width: 13px;_x000D_
  height: 18px;_x000D_
  font-size: 12px;_x000D_
  line-height: 12px;_x000D_
}
_x000D_
<form>_x000D_
  <div>_x000D_
    <label><input type="checkbox" /> Label text</label>_x000D_
  </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_

Hope that helps.


The chosen answer with 400+ upvotes did not work for me in Chrome 28 OSX, probably because it wasn't tested in OSX or that it did work in whatever was around in 2008 when this question was answered.

The times have changed, and new CSS3 solutions are now feasible. My solution uses pseudoelements to create a custom checkbox. So the stipulations (pros or cons, however you look at it) are as follows:

  • Only works in modern browsers (FF3.6+, IE9+, Chrome, Safari)
  • Relies on a custom designed checkbox, that will be rendered exactly the same in every browser/OS. Here I've just chosen some simple colors, but you could always add linear gradients and such to give it more of a bang.
  • Is geared to a certain font/font size, which if changed, you'd simply change the positioning and size of the checkbox to make it appear vertically aligned. If tweaked correctly, the end result should still be near to exactly the same in all browser / operating systems.
  • No vertical-alignment properties, no floats
  • Must use the provided markup in my example, it will not work if structured like the question, however, the layout will essentially look the same. If you want to move things around, you'll have to also move the associated CSS

_x000D_
_x000D_
div.checkbox {_x000D_
    position: relative;_x000D_
    font-family: Arial;_x000D_
    font-size: 13px;_x000D_
}_x000D_
label {_x000D_
    position: relative;_x000D_
    padding-left: 16px;_x000D_
}_x000D_
label::before {_x000D_
    content :"";_x000D_
    display: inline-block;_x000D_
    width: 10px;_x000D_
    height: 10px;_x000D_
    background-color: white;_x000D_
    border: solid 1px #9C9C9C;_x000D_
    position: absolute;_x000D_
    top: 1px;_x000D_
    left: 0px;_x000D_
}_x000D_
label::after {_x000D_
    content:"";_x000D_
    width: 8px;_x000D_
    height: 8px;_x000D_
    background-color: #666666;_x000D_
    position: absolute;_x000D_
    left: 2px;_x000D_
    top: 3px;_x000D_
    display: none;_x000D_
}_x000D_
input[type=checkbox] {_x000D_
    visibility: hidden;_x000D_
    position: absolute;_x000D_
}_x000D_
input[type=checkbox]:checked + label::after {_x000D_
    display: block;_x000D_
}_x000D_
input[type=checkbox]:active + label::before {_x000D_
    background-color: #DDDDDD;_x000D_
}
_x000D_
<form>_x000D_
    <div class="checkbox">_x000D_
        <input id="check_me" type=checkbox />_x000D_
        <label for="check_me">Label for checkbox</label>_x000D_
    </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_

This solution hides the checkbox, and adds and styles pseudoelements to the label to create the visible checkbox. Because the label is tied to the hidden checkbox, the input field will still get updated and the value will be submitted with the form.

And if you're interested, here's my take on radio buttons: http://jsfiddle.net/DtKrV/2/

Hope someone finds this useful!


try vertical-align: middle

also your code seems like it should be:

_x000D_
_x000D_
<form>_x000D_
    <div>_x000D_
        <input id="blah" type="checkbox"><label for="blah">Label text</label>_x000D_
    </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_


If you use ASP.NET Web Forms you don't need to worry about DIVs and other elements or fixed sizes. We can align the <asp:CheckBoxList> text by setting float:left to the CheckboxList input type in CSS.

Please check the following example code:

.CheckboxList
{
    font-size: 14px;
    color: #333333;
}
.CheckboxList input
{
    float: left;
    clear: both;
}

.ASPX code:

<asp:CheckBoxList runat="server" ID="c1" RepeatColumns="2" CssClass="CheckboxList">
</asp:CheckBoxList>

I have not completely tested my solution, but it seems to work great.

My HTML is simply:

<label class="checkbox"><input type="checkbox" value="0000">0000 - 0100</label>

I then set all checkboxes to 24px for both height and width. To make the text aligned I make the label's line-height also 24px and assign vertical-align: top; like so:

EDIT: After IE testing I added vertical-align: bottom; to the input and changed the label's CSS. You may find you need a conditional IE css case to sort out padding - but the text and box are inline.

_x000D_
_x000D_
input[type="checkbox"] {_x000D_
    width: 24px;_x000D_
    height: 24px;_x000D_
    vertical-align: bottom;_x000D_
}_x000D_
label.checkbox {_x000D_
    vertical-align: top;_x000D_
    line-height: 24px;_x000D_
    margin: 2px 0;_x000D_
    display: block;_x000D_
    height: 24px;_x000D_
}
_x000D_
<label class="checkbox"><input type="checkbox" value="0000">0000 - 0100</label>_x000D_
<label class="checkbox"><input type="checkbox" value="0100">0100 - 0200</label>_x000D_
<label class="checkbox"><input type="checkbox" value="0200">0200 - 0300</label>_x000D_
<label class="checkbox"><input type="checkbox" value="0300">0300 - 0400</label>
_x000D_
_x000D_
_x000D_

If anyone finds that this doesn't work, please kindly let me know. Here is it in action (in Chrome and IE - apologies as screenshots were taken on retina and using parallels for IE):

screenshot of checkboxes: Chrome screenshot of checkboxes: IE


Working off of One Crayon's solution, I have something that works for me and is simpler:

_x000D_
_x000D_
.font2 {font-family:Arial; font-size:32px} /* Sample font */_x000D_
_x000D_
input[type=checkbox], input[type=radio] {_x000D_
  vertical-align: middle;_x000D_
  position: relative;_x000D_
  bottom: 1px;_x000D_
}_x000D_
_x000D_
input[type=radio] { _x000D_
  bottom: 2px; _x000D_
} 
_x000D_
<label><input type="checkbox" /> Label text</label>_x000D_
<p class="font2">_x000D_
  <label><input type="checkbox"/> Label text</label>_x000D_
</p>
_x000D_
_x000D_
_x000D_

Renders pixel-for-pixel the same in Safari (whose baseline I trust) and both Firefox and IE7 check out as good. It also works for various label font sizes, big and small. Now, for fixing IE's baseline on selects and inputs...


Update: (Third-Party Edit)

The proper bottom position depends on font-family and font-size! I found using bottom: .08em; for checkbox & radio elements is a good general value. I tested it in Chrome/Firefox/IE11 in windows with Arial & Calibri fonts using several small/mid/large font-sizes.

_x000D_
_x000D_
.font2, .font2 input {font-family:Arial; font-size:32px} /* Sample font */_x000D_
_x000D_
input[type=checkbox], input[type=radio] {_x000D_
  vertical-align: middle; _x000D_
  position: relative;_x000D_
  bottom: .08em; /* this is a better value for different fonts! */_x000D_
}
_x000D_
<label><input type="checkbox" /> Label text</label> _x000D_
_x000D_
<p class="font2">_x000D_
  <label><input type="checkbox"/> Label text</label>_x000D_
</p>
_x000D_
_x000D_
_x000D_


I usually leave a checkbox unlabeled and then make its "label" a separate element. It's a pain, but there's so much cross-browser difference between how checkboxes and their labels are displayed (as you've noticed) that this is the only way I can come close to controlling how everything looks.

I also end up doing this in winforms development, for the same reason. I think the fundamental problem with the checkbox control is that it is really two different controls: the box and the label. By using a checkbox, you're leaving it up to the implementers of the control to decide how those two elements are displayed next to each other (and they always get it wrong, where wrong = not what you want).

I really hope someone has a better answer to your question.


Let's finally take a look at the source of the problem

The checkboxes are rendered using images (one may set custom ones via CSS). Here is an (unchecked) checkbox in FireFox, highlighted with DOM inspector:

it's just a square

And here's the same unstyled checkbox in Chrome:

it's an uncentered square with "margins" on the right and on the bottom

You can see the margin (orange); padding is not present (would be shown green). So what's this pseudo-margin on the right and on the bottom of the checkbox? These are parts of the image used for the checkbox. That's why using just vertical-align: middle doesn't really suffice and that's the source of the cross-browser problems.

So what can we do about this?

One obvious option is – replace the images! Fortunately, one can do this via CSS and replace those with external images, base64 (in-CSS) images, in-CSS svg or just pseudo-elements. It's a robust (cross-browser!) approach, and here's an example of such adjustment stolen from this question:

_x000D_
_x000D_
.checkbox-custom {_x000D_
  opacity: 0;_x000D_
  position: absolute;_x000D_
}_x000D_
.checkbox-custom,_x000D_
.checkbox-custom-label {_x000D_
  display: inline-block;_x000D_
  vertical-align: middle;_x000D_
  margin: 5px;_x000D_
  cursor: pointer;_x000D_
}_x000D_
.checkbox-custom + .checkbox-custom-label:before {_x000D_
  content: '';_x000D_
  display: inline-block;_x000D_
  background: #fff;_x000D_
  border-radius: 5px;_x000D_
  border: 2px solid #ddd;_x000D_
  vertical-align: middle;_x000D_
  width: 10px;_x000D_
  height: 10px;_x000D_
  padding: 2px;_x000D_
  margin-right: 10px;_x000D_
  text-align: center;_x000D_
}_x000D_
.checkbox-custom:checked + .checkbox-custom-label:before {_x000D_
  width: 1px;_x000D_
  height: 5px;_x000D_
  border: solid blue;_x000D_
  border-width: 0 3px 3px 0;_x000D_
  transform: rotate(45deg);_x000D_
  -webkit-transform: rotate(45deg);_x000D_
  -ms-transform: rotate(45deg);_x000D_
  border-radius: 0px;_x000D_
  margin: 0px 15px 5px 5px;_x000D_
}
_x000D_
<div>_x000D_
  <input id="checkbox-1" class="checkbox-custom" name="checkbox-1" type="checkbox">_x000D_
  <label for="checkbox-1" class="checkbox-custom-label">First Choice</label>_x000D_
</div>_x000D_
<div>_x000D_
  <input id="checkbox-2" class="checkbox-custom" name="checkbox-2" type="checkbox">_x000D_
  <label for="checkbox-2" class="checkbox-custom-label">Second Choice</label>_x000D_
</div>
_x000D_
_x000D_
_x000D_

You may want to read some more in-depth articles about such styling like some listed here; it's out of scope of this answer.

Ok, still what about no-custom-images-or-pseudo-elements solution?

TL;DR: looks like this won't work, use custom checkbox instead

First, let's notice that if in other browsers those pseudo-margins inside checkbox icon were arbitrary, there were no consistent solution. To build one, we have to explore the anatomy of such images in existing browsers.

So what browsers do have the pseudo-margins in checkboxes? I've checked out Chrome 75, Vivaldi 2.5 (Chromium-based), FireFox 54 (don't ask why such outdated), IE 11, Edge 42, Safari ?? (borrowed one for a minute, forgot to check out the version). Only Chrome and Vivaldi has such pseudo-margins (I suspect all Chromium-based browsers as well, like Opera).

What's the size of those pseudo-margins? To figure this out one can use a zoomed checkbox:

_x000D_
_x000D_
input {_x000D_
  zoom: 10;_x000D_
  box-shadow: 0 0 1px inset #999;_x000D_
}
_x000D_
<input type=checkbox>
_x000D_
_x000D_
_x000D_

my result is ~7% of width/height and hence 0.9-1.0px in absolute units. The accuracy may be questioned, though: try different values of zoom for the checkbox. In my tests in both Chrome and Vivaldi the relative size of the pseudo-margin is very different at zoom values 10, 20 and at values 11-19 (??):

for zoom = 10 it's 7% while for zoom = 11 it's almost twice that value

scale seems to be more consistent:

_x000D_
_x000D_
input {_x000D_
  transform: scale(10) translate(50%, 50%);_x000D_
  box-shadow: 0 0 1px inset #999;_x000D_
}
_x000D_
<input type=checkbox>
_x000D_
_x000D_
_x000D_

so probably ~14% and 2px are the correct values.

Now that we know (?) the size of the pseudo-margin, let's note this is not enough. Are the sizes of the checkbox icons the same for all browsers? Alas! Here's what DOM inspector shows for unstyled checkboxes:

  • FireFox: 13.3px
  • Chromium-based: 12.8px for the whole thing, hence 12.8 (100% - 14%) = 11px for what is visually perceived as checkbox
  • IE 11, Edge: 13px
  • Safari: n/a (these should be compared on the same screen, I believe)

Now before we discuss any solutions or tricks, let's ask: what is a correct alignment? What are we trying to achieve? To certain point it's a matter of taste, but basically I can think of the following "nice" alignments' aspects:

text and checkbox on the same baseline (I deliberately don't adjust checkbox size here):

enter image description here

or have same middle line in terms of lowercase letters:

enter image description here

or same middle line in terms of capital letters (it's easier to see the difference for different font size):

enter image description here

and also we have to decide whether the size of the checkbox should be equal to the height of a lowercase letter, a capital letter or something else (bigger, smaller or between lowercase and capital).

For this discussion let's call an alignment nice if the checkbox is on the same baseline as the text and has the size of a capital letter (a highly arguable choice):

enter image description here

Now what tools do we have to:

  1. adjust checkbox size
  2. recognize Chromium with its pseudo-margined checkbox and set specific styles
  3. adjust checkbox/label vertical alignment

?

  1. Regarding the checkbox size adjustment: there are width, height, size, zoom, scale (have I missed something?). zoom and scale don't allow to set absolute size, so they may help only with adjusting to text size, not set cross-browser size (unless we can write browser-specific rules). size doesn't work with Chrome (did it work with old IE? anyway, it's not that interesting). width and height work in Chrome and other browsers, so we can set a common size, but again, in Chrome it sets the size of the whole image, not the checkbox itself. Note: it is minimum(width, height) which defines a checkbox's size (if width ? height, the area outside checkbox square is added to "pseudo-margin").

    An unfortunate thing is, the pseudo-margins in Chrome checkbox are not set to zero for any width and heights, as far as I can see.

  2. I'm afraid there's no reliable CSS-only method these days.

  3. Let's consider vertical alignment. vertical-align can't give consistent results when set to middle or baseline because of the Chrome's pseudo-margin, the only real option to get the same "coordinate system" for all the browsers is to align label and input to the top:

    comparing vertical-align: top and bottom

    (on the picture: vertical-align: top, bottom and bottom without box-shadow)

So what result do we get from this?

_x000D_
_x000D_
input[type="checkbox"] {_x000D_
    height: 0.95em;_x000D_
    width: 0.95em;_x000D_
}_x000D_
label, input {_x000D_
    vertical-align: top;_x000D_
}
_x000D_
<label><input type="checkbox">label</label>
_x000D_
_x000D_
_x000D_

The snippet above works with Chrome (Chromium-based browsers), but other browsers require a smaller size of the checkbox. It seems to be impossible to adjust both the size and vertical alignment in a way that works around Chromium's checkbox image quirk. My final suggestion is: use custom checkboxes instead – and you'll avoid frustration :)


I found out one way to do it that gives the same result in almost all browsers. At the very least up-to-date browsers. It works in Firefox, Chrome, Safari, Opera. In IE it will just look almost as if there were no rules applied for inputs or labels (i.e., it'll still have the label a few pixels below the input), so I think it's excusable.

HTML

<label class="boxfix"><input type="radio">Label</label>

CSS

.boxfix {
    vertical-align: bottom;
}
.boxfix input {
    margin: 0;
    vertical-align: bottom;
    position: relative;
    top: 1.999px; /* the inputs are slightly more centered in IE at 1px (they don't interpret the .999 here), and Opera will round it to 2px with three decimals */
}

I have not completely tested my solution, but it seems to work great.

My HTML is simply:

<label class="checkbox"><input type="checkbox" value="0000">0000 - 0100</label>

I then set all checkboxes to 24px for both height and width. To make the text aligned I make the label's line-height also 24px and assign vertical-align: top; like so:

EDIT: After IE testing I added vertical-align: bottom; to the input and changed the label's CSS. You may find you need a conditional IE css case to sort out padding - but the text and box are inline.

_x000D_
_x000D_
input[type="checkbox"] {_x000D_
    width: 24px;_x000D_
    height: 24px;_x000D_
    vertical-align: bottom;_x000D_
}_x000D_
label.checkbox {_x000D_
    vertical-align: top;_x000D_
    line-height: 24px;_x000D_
    margin: 2px 0;_x000D_
    display: block;_x000D_
    height: 24px;_x000D_
}
_x000D_
<label class="checkbox"><input type="checkbox" value="0000">0000 - 0100</label>_x000D_
<label class="checkbox"><input type="checkbox" value="0100">0100 - 0200</label>_x000D_
<label class="checkbox"><input type="checkbox" value="0200">0200 - 0300</label>_x000D_
<label class="checkbox"><input type="checkbox" value="0300">0300 - 0400</label>
_x000D_
_x000D_
_x000D_

If anyone finds that this doesn't work, please kindly let me know. Here is it in action (in Chrome and IE - apologies as screenshots were taken on retina and using parallels for IE):

screenshot of checkboxes: Chrome screenshot of checkboxes: IE


The chosen answer with 400+ upvotes did not work for me in Chrome 28 OSX, probably because it wasn't tested in OSX or that it did work in whatever was around in 2008 when this question was answered.

The times have changed, and new CSS3 solutions are now feasible. My solution uses pseudoelements to create a custom checkbox. So the stipulations (pros or cons, however you look at it) are as follows:

  • Only works in modern browsers (FF3.6+, IE9+, Chrome, Safari)
  • Relies on a custom designed checkbox, that will be rendered exactly the same in every browser/OS. Here I've just chosen some simple colors, but you could always add linear gradients and such to give it more of a bang.
  • Is geared to a certain font/font size, which if changed, you'd simply change the positioning and size of the checkbox to make it appear vertically aligned. If tweaked correctly, the end result should still be near to exactly the same in all browser / operating systems.
  • No vertical-alignment properties, no floats
  • Must use the provided markup in my example, it will not work if structured like the question, however, the layout will essentially look the same. If you want to move things around, you'll have to also move the associated CSS

_x000D_
_x000D_
div.checkbox {_x000D_
    position: relative;_x000D_
    font-family: Arial;_x000D_
    font-size: 13px;_x000D_
}_x000D_
label {_x000D_
    position: relative;_x000D_
    padding-left: 16px;_x000D_
}_x000D_
label::before {_x000D_
    content :"";_x000D_
    display: inline-block;_x000D_
    width: 10px;_x000D_
    height: 10px;_x000D_
    background-color: white;_x000D_
    border: solid 1px #9C9C9C;_x000D_
    position: absolute;_x000D_
    top: 1px;_x000D_
    left: 0px;_x000D_
}_x000D_
label::after {_x000D_
    content:"";_x000D_
    width: 8px;_x000D_
    height: 8px;_x000D_
    background-color: #666666;_x000D_
    position: absolute;_x000D_
    left: 2px;_x000D_
    top: 3px;_x000D_
    display: none;_x000D_
}_x000D_
input[type=checkbox] {_x000D_
    visibility: hidden;_x000D_
    position: absolute;_x000D_
}_x000D_
input[type=checkbox]:checked + label::after {_x000D_
    display: block;_x000D_
}_x000D_
input[type=checkbox]:active + label::before {_x000D_
    background-color: #DDDDDD;_x000D_
}
_x000D_
<form>_x000D_
    <div class="checkbox">_x000D_
        <input id="check_me" type=checkbox />_x000D_
        <label for="check_me">Label for checkbox</label>_x000D_
    </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_

This solution hides the checkbox, and adds and styles pseudoelements to the label to create the visible checkbox. Because the label is tied to the hidden checkbox, the input field will still get updated and the value will be submitted with the form.

And if you're interested, here's my take on radio buttons: http://jsfiddle.net/DtKrV/2/

Hope someone finds this useful!


position: relative; has some issues in IE with z-index and animations like jQuery's slideUp/slideDown.

CSS:

input[type=checkbox], input[type=radio] {
    vertical-align: baseline;
    position: relative;
    top: 3px;
    margin: 0 3px 0 0;
    padding: 0px;
}
input.ie7[type=checkbox], input.ie7[type=radio] {
    vertical-align: middle;
    position: static;
    margin-bottom: -2px;
    height: 13px;
    width: 13px;
}

jQuery:

$(document).ready(function () {
    if ($.browser.msie && $.browser.version <= 7) {
        $('input[type=checkbox]').addClass('ie7');
        $('input[type=radio]').addClass('ie7');
    }
});

The styling probably needs tweaks depending on the font-size used in <label>

PS:
I use ie7js to make the css work in IE6.


Working off of One Crayon's solution, I have something that works for me and is simpler:

_x000D_
_x000D_
.font2 {font-family:Arial; font-size:32px} /* Sample font */_x000D_
_x000D_
input[type=checkbox], input[type=radio] {_x000D_
  vertical-align: middle;_x000D_
  position: relative;_x000D_
  bottom: 1px;_x000D_
}_x000D_
_x000D_
input[type=radio] { _x000D_
  bottom: 2px; _x000D_
} 
_x000D_
<label><input type="checkbox" /> Label text</label>_x000D_
<p class="font2">_x000D_
  <label><input type="checkbox"/> Label text</label>_x000D_
</p>
_x000D_
_x000D_
_x000D_

Renders pixel-for-pixel the same in Safari (whose baseline I trust) and both Firefox and IE7 check out as good. It also works for various label font sizes, big and small. Now, for fixing IE's baseline on selects and inputs...


Update: (Third-Party Edit)

The proper bottom position depends on font-family and font-size! I found using bottom: .08em; for checkbox & radio elements is a good general value. I tested it in Chrome/Firefox/IE11 in windows with Arial & Calibri fonts using several small/mid/large font-sizes.

_x000D_
_x000D_
.font2, .font2 input {font-family:Arial; font-size:32px} /* Sample font */_x000D_
_x000D_
input[type=checkbox], input[type=radio] {_x000D_
  vertical-align: middle; _x000D_
  position: relative;_x000D_
  bottom: .08em; /* this is a better value for different fonts! */_x000D_
}
_x000D_
<label><input type="checkbox" /> Label text</label> _x000D_
_x000D_
<p class="font2">_x000D_
  <label><input type="checkbox"/> Label text</label>_x000D_
</p>
_x000D_
_x000D_
_x000D_


Use simply vertical-align: sub, as pokrishka already suggested.

Fiddle

HTML Code:

<div class="checkboxes">
    <label for="check1">Test</label>
    <input id="check1" type="checkbox"></input>
</div>

CSS Code:

.checkboxes input {
    vertical-align: sub;
}

input {
    margin: 0;
}

actually does the trick


Sometimes vertical-align needs two inline (span, label, input, etc...) elements next to each other to work properly. The following checkboxes are properly vertically centered in IE, Safari, FF, and Chrome, even if the text size is very small or large.

They all float next to each other on the same line, but the nowrap means that the whole label text always stays next to the checkbox.

The downside is the extra meaningless SPAN tags.

_x000D_
_x000D_
.checkboxes label {_x000D_
  display: inline-block;_x000D_
  padding-right: 10px;_x000D_
  white-space: nowrap;_x000D_
}_x000D_
.checkboxes input {_x000D_
  vertical-align: middle;_x000D_
}_x000D_
.checkboxes label span {_x000D_
  vertical-align: middle;_x000D_
}
_x000D_
<form>_x000D_
  <div class="checkboxes">_x000D_
    <label for="x"><input type="checkbox" id="x" /> <span>Label text x</span></label>_x000D_
    <label for="y"><input type="checkbox" id="y" /> <span>Label text y</span></label>_x000D_
    <label for="z"><input type="checkbox" id="z" /> <span>Label text z</span></label>_x000D_
  </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_

Now, if you had a very long label text that needed to wrap without wrapping under the checkbox, you'd use padding and negative text indent on the label elements:

_x000D_
_x000D_
.checkboxes label {_x000D_
  display: block;_x000D_
  padding-right: 10px;_x000D_
  padding-left: 22px;_x000D_
  text-indent: -22px;_x000D_
}_x000D_
.checkboxes input {_x000D_
  vertical-align: middle;_x000D_
}_x000D_
.checkboxes label span {_x000D_
  vertical-align: middle;_x000D_
}
_x000D_
<form>_x000D_
  <div class="checkboxes">_x000D_
    <label for="x"><input type="checkbox" id="x" /> <span>Label text x so long that it will probably wrap so let's see how it goes with the proposed CSS (expected: two lines are aligned nicely)</span></label>_x000D_
    <label for="y"><input type="checkbox" id="y" /> <span>Label text y</span></label>_x000D_
    <label for="z"><input type="checkbox" id="z" /> <span>Label text z</span></label>_x000D_
  </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_


One easy thing that seems to work well is to apply a adjust the vertical position of the checkbox with vertical-align. It will still be vary across browsers, but the solution is uncomplicated.

input {
    vertical-align: -2px;
}

Reference


Try my solution, I tried it in IE 6, FF2 and Chrome and it renders pixel by pixel in all the three browsers.

_x000D_
_x000D_
* {_x000D_
  padding: 0px;_x000D_
  margin: 0px;_x000D_
}_x000D_
#wb {_x000D_
  width: 15px;_x000D_
  height: 15px;_x000D_
  float: left;_x000D_
}_x000D_
#somelabel {_x000D_
  float: left;_x000D_
  padding-left: 3px;_x000D_
}
_x000D_
<div>_x000D_
  <input id="wb" type="checkbox" />_x000D_
  <label for="wb" id="somelabel">Web Browser</label>_x000D_
</div>
_x000D_
_x000D_
_x000D_


_x000D_
_x000D_
input[type=checkbox]_x000D_
{_x000D_
    vertical-align: middle;_x000D_
} 
_x000D_
<input id="testCheckbox" name="testCheckbox" type="checkbox">_x000D_
<label for="testCheckbox">I should align</label>
_x000D_
_x000D_
_x000D_


This works well for me:

_x000D_
_x000D_
fieldset {_x000D_
  text-align:left;_x000D_
  border:none_x000D_
}_x000D_
fieldset ol, fieldset ul {_x000D_
  padding:0;_x000D_
  list-style:none_x000D_
}_x000D_
fieldset li {_x000D_
  padding-bottom:1.5em;_x000D_
  float:none;_x000D_
  clear:left_x000D_
}_x000D_
label {_x000D_
  float:left;_x000D_
  width:7em;_x000D_
  margin-right:1em_x000D_
}_x000D_
fieldset.checkboxes li {_x000D_
  clear:both;_x000D_
  padding:.75em_x000D_
}_x000D_
fieldset.checkboxes label {_x000D_
  margin:0 0 0 1em;_x000D_
  width:20em_x000D_
}_x000D_
fieldset.checkboxes input {_x000D_
  float:left_x000D_
}
_x000D_
<form>_x000D_
  <fieldset class="checkboxes">_x000D_
    <ul>_x000D_
      <li>_x000D_
        <input type="checkbox" name="happy" value="yep" id="happy" />_x000D_
        <label for="happy">Happy?</label>_x000D_
      </li>_x000D_
      <li>_x000D_
        <input type="checkbox" name="hungry" value="yep" id="hungry" />_x000D_
        <label for="hungry">Hungry?</label>_x000D_
      </li>_x000D_
    </ul>_x000D_
  </fieldset>_x000D_
</form>
_x000D_
_x000D_
_x000D_


Hardcode the checkbox's height and width, remove its padding, and make its height plus vertical margins equal to the label's line-height. If the label text is inline, float the checkbox. Firefox, Chrome, and IE7+ all render the following example identically: http://www.kornea.com/css-checkbox-align


I usually use line height in order to adjust the vertical position of my static text:

_x000D_
_x000D_
label {_x000D_
  line-height: 18px;_x000D_
}_x000D_
input {_x000D_
  width: 13px;_x000D_
  height: 18px;_x000D_
  font-size: 12px;_x000D_
  line-height: 12px;_x000D_
}
_x000D_
<form>_x000D_
  <div>_x000D_
    <label><input type="checkbox" /> Label text</label>_x000D_
  </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_

Hope that helps.


I don't like relative positioning because it makes element rendered above everything else on its level (it can get on top of something if you have complex layout).

I've discovered that vertical-align: sub makes checkboxes look good enough aligned in Chrome, Firefox and Opera. Can't check Safari since I don't have MacOS and IE10 is slightly off, but I've found it to be good enough solution for me.

Another solution might be to try and make specific CSS for every browser and fine-tune it with some vertical-align in %/pixels/EMs: http://css-tricks.com/snippets/css/browser-specific-hacks/


CSS:

.threeCol .listItem {
    width:13.9em;
    padding:.2em;
    margin:.2em;
    float:left;
    border-bottom:solid #f3f3f3 1px;
}
.threeCol input {
    float:left;
    width:auto;
    margin:.2em .2em .2em 0;
    border:none;
    background:none;
}
.threeCol label {
    float:left;
    margin:.1em 0 .1em 0;
}

HTML:

<div class="threeCol">
    <div class="listItem">
        <input type="checkbox" name="name" id="id" value="checkbox1" />
        <label for="name">This is your checkBox</label>
    </div>
</div>

The above code will place your list items in threecols and just change widths to suit.


_x000D_
_x000D_
<form>_x000D_
    <div>_x000D_
        <label style="display: inline-block">_x000D_
            <input style="vertical-align: middle" type="checkbox" />_x000D_
            <span style="vertical-align: middle">Label text</span>_x000D_
         </label>_x000D_
    </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_

The trick is to use vertical-align only in table cells or inline-block if using label tag.


I usually use line height in order to adjust the vertical position of my static text:

_x000D_
_x000D_
label {_x000D_
  line-height: 18px;_x000D_
}_x000D_
input {_x000D_
  width: 13px;_x000D_
  height: 18px;_x000D_
  font-size: 12px;_x000D_
  line-height: 12px;_x000D_
}
_x000D_
<form>_x000D_
  <div>_x000D_
    <label><input type="checkbox" /> Label text</label>_x000D_
  </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_

Hope that helps.


With an input type checkbox wrapped inside the label and floated to the left like so:

<label for="id" class="checkbox">
    <input type="checkbox" id="id">
    <span>The Label</span>
</label>

this worked for me:

label.checkbox {
    display: block;
}
.checkbox input {
    float: left;
    height: 18px;
    vertical-align: middle;
}
.checkbox span {
    float: left;
    line-height: 18px;
    margin: 0 0 0 20px;
}

Make sure the height of the is identical to the line-height of the (blocklevel) .


I don't like relative positioning because it makes element rendered above everything else on its level (it can get on top of something if you have complex layout).

I've discovered that vertical-align: sub makes checkboxes look good enough aligned in Chrome, Firefox and Opera. Can't check Safari since I don't have MacOS and IE10 is slightly off, but I've found it to be good enough solution for me.

Another solution might be to try and make specific CSS for every browser and fine-tune it with some vertical-align in %/pixels/EMs: http://css-tricks.com/snippets/css/browser-specific-hacks/


So I know this has been answered many times, but I feel I have a way more elegant solution than those that have been provided already. And not only 1 elegant solution, but 2 separate solutions to tickle your fancy. With that said, everything you need to know and see are contained in 2 JS Fiddle's, with comments.


Solution #1 relies on the native "Checkbox" of the given browser, though with a twist... Its contained in a div which is easier to position cross-browser, with an overflow: hidden to chop the excess of a 1px stretched checkbox (this is so you cant see the ugly borders of FF)

Simple HTML: (follow the link to review the css with comments, code block is to satisfy stackoverflow) http://jsfiddle.net/KQghJ/

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

Solution #2 uses the "Checkbox Toggle Hack" to toggle the CSS state of a DIV, which has been properly positioned across browser, and setup with a simple sprite for the checkbox unchecked and checked states. All that is needed is to adjust the background-position with said Checkbox Toggle Hack. This, in my opinion, is the more elegant solution as you have more control over your checkboxes & radios, and can guarantee they look the same across browser.

Simple HTML: (follow the link to review the CSS with comments, code block is to satisfy StackOverflow) http://jsfiddle.net/Sx5M2/

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

If anyone disagree's with these methods, please leave me a comment, I would love to hear some feedback on why others have not come across these solutions, or if they have, why I see no answers here regarding them? If anyone sees one of these methods fail, it would be nice to see that too, but these have been tested in the latest browsers and rely on HTML / CSS methods that are quite old, and universal as far as I have seen.


Now that flexbox is supported in all modern browsers, something like this seems like an easier approach to me.

<style>
label {
  display: flex;
  align-items: center;
}
input[type=radio], input[type=checkbox]{
  flex: none;
}
</style>
<form>
  <div>
    <label><input type="checkbox" /> Label text</label>
  </div>
</form>


Here's the complete prefixed version demo:

_x000D_
_x000D_
label {_x000D_
 display: -webkit-box;_x000D_
 display: -webkit-flex;_x000D_
 display: -ms-flexbox;_x000D_
 display: flex;_x000D_
 -webkit-box-align: center;_x000D_
 -webkit-align-items: center;_x000D_
 -ms-flex-align: center;_x000D_
 align-items: center;_x000D_
}_x000D_
input[type=radio], _x000D_
input[type=checkbox] {_x000D_
 -webkit-box-flex: 0;_x000D_
 -webkit-flex: none;_x000D_
 -ms-flex: none;_x000D_
 flex: none;_x000D_
 margin-right: 10px; _x000D_
}_x000D_
/* demo only (to show alignment) */_x000D_
form {_x000D_
  max-width: 200px_x000D_
}
_x000D_
<form>_x000D_
  <label>_x000D_
    <input type="radio" checked>_x000D_
    I am an aligned radio and label_x000D_
  </label>_x000D_
  <label>_x000D_
      <input type="checkbox" checked>_x000D_
    I am an aligned checkbox and label_x000D_
  </label>_x000D_
</form>
_x000D_
_x000D_
_x000D_


Simple solution:

<label style="display:block">
  <input style="vertical-align:middle" type="checkbox">
  <span  style="vertical-align:middle">Label</span>
</label>

Tested in Chrome, Firefox, IE9+, Safari, iOS 9+


If you're using Twitter Bootstrap, you can just use the checkbox class on the <label>:

<label class="checkbox">
    <input type="checkbox"> Remember me
</label>

I think this is the easiest way

_x000D_
_x000D_
input {_x000D_
    position: relative;_x000D_
    top: 1px;_x000D_
}
_x000D_
<form>_x000D_
    <div>_x000D_
        <label><input type="checkbox" /> Label text</label>_x000D_
    </div>_x000D_
<form>
_x000D_
_x000D_
_x000D_


try vertical-align: middle

also your code seems like it should be:

_x000D_
_x000D_
<form>_x000D_
    <div>_x000D_
        <input id="blah" type="checkbox"><label for="blah">Label text</label>_x000D_
    </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_


I found the only way I could line them up was using position absolute for the input. Playing around with input's top variable got the result I wanted.

div {
  clear:    both;
  float:    none;
  position: relative;
}

input {
  left:     5px;
  position: absolute;
  top:      3px;
}

label {
  display:     block;
  margin-left: 20px;
}

I've never had a problem with doing it like this:

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

try this code

input[type="checkbox"] {
    -moz-appearance: checkbox;
    -webkit-appearance: checkbox;
    margin-left:3px;
    border:0;
    vertical-align: middle;
    top: -1px;
    bottom: 1px;
    *overflow: hidden;
    box-sizing: border-box; /* 1 */
    *height: 13px; /* Removes excess padding in IE 7 */
    *width: 13px;
    background: #fff;
}

This works well for me:

_x000D_
_x000D_
fieldset {_x000D_
  text-align:left;_x000D_
  border:none_x000D_
}_x000D_
fieldset ol, fieldset ul {_x000D_
  padding:0;_x000D_
  list-style:none_x000D_
}_x000D_
fieldset li {_x000D_
  padding-bottom:1.5em;_x000D_
  float:none;_x000D_
  clear:left_x000D_
}_x000D_
label {_x000D_
  float:left;_x000D_
  width:7em;_x000D_
  margin-right:1em_x000D_
}_x000D_
fieldset.checkboxes li {_x000D_
  clear:both;_x000D_
  padding:.75em_x000D_
}_x000D_
fieldset.checkboxes label {_x000D_
  margin:0 0 0 1em;_x000D_
  width:20em_x000D_
}_x000D_
fieldset.checkboxes input {_x000D_
  float:left_x000D_
}
_x000D_
<form>_x000D_
  <fieldset class="checkboxes">_x000D_
    <ul>_x000D_
      <li>_x000D_
        <input type="checkbox" name="happy" value="yep" id="happy" />_x000D_
        <label for="happy">Happy?</label>_x000D_
      </li>_x000D_
      <li>_x000D_
        <input type="checkbox" name="hungry" value="yep" id="hungry" />_x000D_
        <label for="hungry">Hungry?</label>_x000D_
      </li>_x000D_
    </ul>_x000D_
  </fieldset>_x000D_
</form>
_x000D_
_x000D_
_x000D_


Now that flexbox is supported in all modern browsers, something like this seems like an easier approach to me.

<style>
label {
  display: flex;
  align-items: center;
}
input[type=radio], input[type=checkbox]{
  flex: none;
}
</style>
<form>
  <div>
    <label><input type="checkbox" /> Label text</label>
  </div>
</form>


Here's the complete prefixed version demo:

_x000D_
_x000D_
label {_x000D_
 display: -webkit-box;_x000D_
 display: -webkit-flex;_x000D_
 display: -ms-flexbox;_x000D_
 display: flex;_x000D_
 -webkit-box-align: center;_x000D_
 -webkit-align-items: center;_x000D_
 -ms-flex-align: center;_x000D_
 align-items: center;_x000D_
}_x000D_
input[type=radio], _x000D_
input[type=checkbox] {_x000D_
 -webkit-box-flex: 0;_x000D_
 -webkit-flex: none;_x000D_
 -ms-flex: none;_x000D_
 flex: none;_x000D_
 margin-right: 10px; _x000D_
}_x000D_
/* demo only (to show alignment) */_x000D_
form {_x000D_
  max-width: 200px_x000D_
}
_x000D_
<form>_x000D_
  <label>_x000D_
    <input type="radio" checked>_x000D_
    I am an aligned radio and label_x000D_
  </label>_x000D_
  <label>_x000D_
      <input type="checkbox" checked>_x000D_
    I am an aligned checkbox and label_x000D_
  </label>_x000D_
</form>
_x000D_
_x000D_
_x000D_


I've never had a problem with doing it like this:

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

For consistency with form fields across browsers we use : box-sizing: border-box

button, checkbox, input, radio, textarea, submit, reset, search, any-form-field {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

Let's finally take a look at the source of the problem

The checkboxes are rendered using images (one may set custom ones via CSS). Here is an (unchecked) checkbox in FireFox, highlighted with DOM inspector:

it's just a square

And here's the same unstyled checkbox in Chrome:

it's an uncentered square with "margins" on the right and on the bottom

You can see the margin (orange); padding is not present (would be shown green). So what's this pseudo-margin on the right and on the bottom of the checkbox? These are parts of the image used for the checkbox. That's why using just vertical-align: middle doesn't really suffice and that's the source of the cross-browser problems.

So what can we do about this?

One obvious option is – replace the images! Fortunately, one can do this via CSS and replace those with external images, base64 (in-CSS) images, in-CSS svg or just pseudo-elements. It's a robust (cross-browser!) approach, and here's an example of such adjustment stolen from this question:

_x000D_
_x000D_
.checkbox-custom {_x000D_
  opacity: 0;_x000D_
  position: absolute;_x000D_
}_x000D_
.checkbox-custom,_x000D_
.checkbox-custom-label {_x000D_
  display: inline-block;_x000D_
  vertical-align: middle;_x000D_
  margin: 5px;_x000D_
  cursor: pointer;_x000D_
}_x000D_
.checkbox-custom + .checkbox-custom-label:before {_x000D_
  content: '';_x000D_
  display: inline-block;_x000D_
  background: #fff;_x000D_
  border-radius: 5px;_x000D_
  border: 2px solid #ddd;_x000D_
  vertical-align: middle;_x000D_
  width: 10px;_x000D_
  height: 10px;_x000D_
  padding: 2px;_x000D_
  margin-right: 10px;_x000D_
  text-align: center;_x000D_
}_x000D_
.checkbox-custom:checked + .checkbox-custom-label:before {_x000D_
  width: 1px;_x000D_
  height: 5px;_x000D_
  border: solid blue;_x000D_
  border-width: 0 3px 3px 0;_x000D_
  transform: rotate(45deg);_x000D_
  -webkit-transform: rotate(45deg);_x000D_
  -ms-transform: rotate(45deg);_x000D_
  border-radius: 0px;_x000D_
  margin: 0px 15px 5px 5px;_x000D_
}
_x000D_
<div>_x000D_
  <input id="checkbox-1" class="checkbox-custom" name="checkbox-1" type="checkbox">_x000D_
  <label for="checkbox-1" class="checkbox-custom-label">First Choice</label>_x000D_
</div>_x000D_
<div>_x000D_
  <input id="checkbox-2" class="checkbox-custom" name="checkbox-2" type="checkbox">_x000D_
  <label for="checkbox-2" class="checkbox-custom-label">Second Choice</label>_x000D_
</div>
_x000D_
_x000D_
_x000D_

You may want to read some more in-depth articles about such styling like some listed here; it's out of scope of this answer.

Ok, still what about no-custom-images-or-pseudo-elements solution?

TL;DR: looks like this won't work, use custom checkbox instead

First, let's notice that if in other browsers those pseudo-margins inside checkbox icon were arbitrary, there were no consistent solution. To build one, we have to explore the anatomy of such images in existing browsers.

So what browsers do have the pseudo-margins in checkboxes? I've checked out Chrome 75, Vivaldi 2.5 (Chromium-based), FireFox 54 (don't ask why such outdated), IE 11, Edge 42, Safari ?? (borrowed one for a minute, forgot to check out the version). Only Chrome and Vivaldi has such pseudo-margins (I suspect all Chromium-based browsers as well, like Opera).

What's the size of those pseudo-margins? To figure this out one can use a zoomed checkbox:

_x000D_
_x000D_
input {_x000D_
  zoom: 10;_x000D_
  box-shadow: 0 0 1px inset #999;_x000D_
}
_x000D_
<input type=checkbox>
_x000D_
_x000D_
_x000D_

my result is ~7% of width/height and hence 0.9-1.0px in absolute units. The accuracy may be questioned, though: try different values of zoom for the checkbox. In my tests in both Chrome and Vivaldi the relative size of the pseudo-margin is very different at zoom values 10, 20 and at values 11-19 (??):

for zoom = 10 it's 7% while for zoom = 11 it's almost twice that value

scale seems to be more consistent:

_x000D_
_x000D_
input {_x000D_
  transform: scale(10) translate(50%, 50%);_x000D_
  box-shadow: 0 0 1px inset #999;_x000D_
}
_x000D_
<input type=checkbox>
_x000D_
_x000D_
_x000D_

so probably ~14% and 2px are the correct values.

Now that we know (?) the size of the pseudo-margin, let's note this is not enough. Are the sizes of the checkbox icons the same for all browsers? Alas! Here's what DOM inspector shows for unstyled checkboxes:

  • FireFox: 13.3px
  • Chromium-based: 12.8px for the whole thing, hence 12.8 (100% - 14%) = 11px for what is visually perceived as checkbox
  • IE 11, Edge: 13px
  • Safari: n/a (these should be compared on the same screen, I believe)

Now before we discuss any solutions or tricks, let's ask: what is a correct alignment? What are we trying to achieve? To certain point it's a matter of taste, but basically I can think of the following "nice" alignments' aspects:

text and checkbox on the same baseline (I deliberately don't adjust checkbox size here):

enter image description here

or have same middle line in terms of lowercase letters:

enter image description here

or same middle line in terms of capital letters (it's easier to see the difference for different font size):

enter image description here

and also we have to decide whether the size of the checkbox should be equal to the height of a lowercase letter, a capital letter or something else (bigger, smaller or between lowercase and capital).

For this discussion let's call an alignment nice if the checkbox is on the same baseline as the text and has the size of a capital letter (a highly arguable choice):

enter image description here

Now what tools do we have to:

  1. adjust checkbox size
  2. recognize Chromium with its pseudo-margined checkbox and set specific styles
  3. adjust checkbox/label vertical alignment

?

  1. Regarding the checkbox size adjustment: there are width, height, size, zoom, scale (have I missed something?). zoom and scale don't allow to set absolute size, so they may help only with adjusting to text size, not set cross-browser size (unless we can write browser-specific rules). size doesn't work with Chrome (did it work with old IE? anyway, it's not that interesting). width and height work in Chrome and other browsers, so we can set a common size, but again, in Chrome it sets the size of the whole image, not the checkbox itself. Note: it is minimum(width, height) which defines a checkbox's size (if width ? height, the area outside checkbox square is added to "pseudo-margin").

    An unfortunate thing is, the pseudo-margins in Chrome checkbox are not set to zero for any width and heights, as far as I can see.

  2. I'm afraid there's no reliable CSS-only method these days.

  3. Let's consider vertical alignment. vertical-align can't give consistent results when set to middle or baseline because of the Chrome's pseudo-margin, the only real option to get the same "coordinate system" for all the browsers is to align label and input to the top:

    comparing vertical-align: top and bottom

    (on the picture: vertical-align: top, bottom and bottom without box-shadow)

So what result do we get from this?

_x000D_
_x000D_
input[type="checkbox"] {_x000D_
    height: 0.95em;_x000D_
    width: 0.95em;_x000D_
}_x000D_
label, input {_x000D_
    vertical-align: top;_x000D_
}
_x000D_
<label><input type="checkbox">label</label>
_x000D_
_x000D_
_x000D_

The snippet above works with Chrome (Chromium-based browsers), but other browsers require a smaller size of the checkbox. It seems to be impossible to adjust both the size and vertical alignment in a way that works around Chromium's checkbox image quirk. My final suggestion is: use custom checkboxes instead – and you'll avoid frustration :)


Maybe some folk are making the same mistake I did? Which was... I had set a width for the input boxes, because they were mostly of type 'text' , but then forgotten to over-ride that width for checkboxes - so my checkbox was trying to occupy a lot of excess width and so it was tough to align a label beside it.

.checkboxlabel {
    width: 100%;
    vertical-align: middle;
}
.checkbox {
    width: 20px !important;
}
<label for='acheckbox' class='checkboxlabel'>
    <input name="acheckbox" id='acheckbox' type="checkbox" class='checkbox'>Contact me</label>

Gives clickable labels and and proper alignment as far back as IE6 (using a class selector) and in late versions of Firefox, Safari and Chrome


I usually use line height in order to adjust the vertical position of my static text:

_x000D_
_x000D_
label {_x000D_
  line-height: 18px;_x000D_
}_x000D_
input {_x000D_
  width: 13px;_x000D_
  height: 18px;_x000D_
  font-size: 12px;_x000D_
  line-height: 12px;_x000D_
}
_x000D_
<form>_x000D_
  <div>_x000D_
    <label><input type="checkbox" /> Label text</label>_x000D_
  </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_

Hope that helps.


label {
    display: inline-block;
    padding-right: 10px;
}
input[type=checkbox] {
    position: relative;
    top: 2px;
}

Simple solution:

<label style="display:block">
  <input style="vertical-align:middle" type="checkbox">
  <span  style="vertical-align:middle">Label</span>
</label>

Tested in Chrome, Firefox, IE9+, Safari, iOS 9+


I usually leave a checkbox unlabeled and then make its "label" a separate element. It's a pain, but there's so much cross-browser difference between how checkboxes and their labels are displayed (as you've noticed) that this is the only way I can come close to controlling how everything looks.

I also end up doing this in winforms development, for the same reason. I think the fundamental problem with the checkbox control is that it is really two different controls: the box and the label. By using a checkbox, you're leaving it up to the implementers of the control to decide how those two elements are displayed next to each other (and they always get it wrong, where wrong = not what you want).

I really hope someone has a better answer to your question.


I found the only way I could line them up was using position absolute for the input. Playing around with input's top variable got the result I wanted.

div {
  clear:    both;
  float:    none;
  position: relative;
}

input {
  left:     5px;
  position: absolute;
  top:      3px;
}

label {
  display:     block;
  margin-left: 20px;
}

Sometimes vertical-align needs two inline (span, label, input, etc...) elements next to each other to work properly. The following checkboxes are properly vertically centered in IE, Safari, FF, and Chrome, even if the text size is very small or large.

They all float next to each other on the same line, but the nowrap means that the whole label text always stays next to the checkbox.

The downside is the extra meaningless SPAN tags.

_x000D_
_x000D_
.checkboxes label {_x000D_
  display: inline-block;_x000D_
  padding-right: 10px;_x000D_
  white-space: nowrap;_x000D_
}_x000D_
.checkboxes input {_x000D_
  vertical-align: middle;_x000D_
}_x000D_
.checkboxes label span {_x000D_
  vertical-align: middle;_x000D_
}
_x000D_
<form>_x000D_
  <div class="checkboxes">_x000D_
    <label for="x"><input type="checkbox" id="x" /> <span>Label text x</span></label>_x000D_
    <label for="y"><input type="checkbox" id="y" /> <span>Label text y</span></label>_x000D_
    <label for="z"><input type="checkbox" id="z" /> <span>Label text z</span></label>_x000D_
  </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_

Now, if you had a very long label text that needed to wrap without wrapping under the checkbox, you'd use padding and negative text indent on the label elements:

_x000D_
_x000D_
.checkboxes label {_x000D_
  display: block;_x000D_
  padding-right: 10px;_x000D_
  padding-left: 22px;_x000D_
  text-indent: -22px;_x000D_
}_x000D_
.checkboxes input {_x000D_
  vertical-align: middle;_x000D_
}_x000D_
.checkboxes label span {_x000D_
  vertical-align: middle;_x000D_
}
_x000D_
<form>_x000D_
  <div class="checkboxes">_x000D_
    <label for="x"><input type="checkbox" id="x" /> <span>Label text x so long that it will probably wrap so let's see how it goes with the proposed CSS (expected: two lines are aligned nicely)</span></label>_x000D_
    <label for="y"><input type="checkbox" id="y" /> <span>Label text y</span></label>_x000D_
    <label for="z"><input type="checkbox" id="z" /> <span>Label text z</span></label>_x000D_
  </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_


input {
    margin: 0;
}

actually does the trick


The only perfectly working solution for me is:

input[type=checkbox], input[type=radio] {
    vertical-align: -2px;
    margin: 0;
    padding: 0;
}

Tested today in Chrome, Firefox, Opera, IE 7 and 8. Example: Fiddle


I think this is the easiest way

_x000D_
_x000D_
input {_x000D_
    position: relative;_x000D_
    top: 1px;_x000D_
}
_x000D_
<form>_x000D_
    <div>_x000D_
        <label><input type="checkbox" /> Label text</label>_x000D_
    </div>_x000D_
<form>
_x000D_
_x000D_
_x000D_


The only perfectly working solution for me is:

input[type=checkbox], input[type=radio] {
    vertical-align: -2px;
    margin: 0;
    padding: 0;
}

Tested today in Chrome, Firefox, Opera, IE 7 and 8. Example: Fiddle


If you use ASP.NET Web Forms you don't need to worry about DIVs and other elements or fixed sizes. We can align the <asp:CheckBoxList> text by setting float:left to the CheckboxList input type in CSS.

Please check the following example code:

.CheckboxList
{
    font-size: 14px;
    color: #333333;
}
.CheckboxList input
{
    float: left;
    clear: both;
}

.ASPX code:

<asp:CheckBoxList runat="server" ID="c1" RepeatColumns="2" CssClass="CheckboxList">
</asp:CheckBoxList>

CSS:

.threeCol .listItem {
    width:13.9em;
    padding:.2em;
    margin:.2em;
    float:left;
    border-bottom:solid #f3f3f3 1px;
}
.threeCol input {
    float:left;
    width:auto;
    margin:.2em .2em .2em 0;
    border:none;
    background:none;
}
.threeCol label {
    float:left;
    margin:.1em 0 .1em 0;
}

HTML:

<div class="threeCol">
    <div class="listItem">
        <input type="checkbox" name="name" id="id" value="checkbox1" />
        <label for="name">This is your checkBox</label>
    </div>
</div>

The above code will place your list items in threecols and just change widths to suit.


_x000D_
_x000D_
<form>_x000D_
    <div>_x000D_
        <label style="display: inline-block">_x000D_
            <input style="vertical-align: middle" type="checkbox" />_x000D_
            <span style="vertical-align: middle">Label text</span>_x000D_
         </label>_x000D_
    </div>_x000D_
</form>
_x000D_
_x000D_
_x000D_

The trick is to use vertical-align only in table cells or inline-block if using label tag.


Yay thanks! This too has been driving me nuts forever.

In my particular case, this worked for me:

input {
    width: 13px;
    height: 13px;
    padding: 0;
    margin:0;
    vertical-align: top;
    position: relative;
    *top: 1px;
    *overflow: hidden;
}
label {
    display: block;
    padding: 0;
    padding-left: 15px;
    text-indent: -15px;
    border: 0px solid;
    margin-left: 5px;
    vertical-align: top;
}

I am using the reset.css which might explain some of the differences, but this seems to work well for me.


I found out one way to do it that gives the same result in almost all browsers. At the very least up-to-date browsers. It works in Firefox, Chrome, Safari, Opera. In IE it will just look almost as if there were no rules applied for inputs or labels (i.e., it'll still have the label a few pixels below the input), so I think it's excusable.

HTML

<label class="boxfix"><input type="radio">Label</label>

CSS

.boxfix {
    vertical-align: bottom;
}
.boxfix input {
    margin: 0;
    vertical-align: bottom;
    position: relative;
    top: 1.999px; /* the inputs are slightly more centered in IE at 1px (they don't interpret the .999 here), and Opera will round it to 2px with three decimals */
}

<fieldset class="checks">
    <legend>checks for whatevers</legend>
    <input type="" id="x" />
    <label for="x">Label</label>
    <input type="" id="y" />
    <label for="y">Label</label>
    <input type="" id="z" />
    <label for="z">Label</label>
</fieldset>

You should wrap form controls grouped together in their own fieldsets anyways, here, it plays the wrappa. set input/label do display:block, input float left, label float right, set your widths, control spacing with left/right margins, align label text accordingly.

so

fieldset.checks {
    width:200px
}
.checks input, .checks label {
    display:block;
}
.checks input {
    float:right;
    width:10px;
    margin-right:5px
}
.checks label {
    float:left;
    width:180px;
    margin-left:5px;
    text-align:left;
    text-indent:5px
}

you probably need to set border, outline and line-height on both as well for cross-browser/media solutions.


label {
    display: inline-block;
    padding-right: 10px;
}
input[type=checkbox] {
    position: relative;
    top: 2px;
}

I usually leave a checkbox unlabeled and then make its "label" a separate element. It's a pain, but there's so much cross-browser difference between how checkboxes and their labels are displayed (as you've noticed) that this is the only way I can come close to controlling how everything looks.

I also end up doing this in winforms development, for the same reason. I think the fundamental problem with the checkbox control is that it is really two different controls: the box and the label. By using a checkbox, you're leaving it up to the implementers of the control to decide how those two elements are displayed next to each other (and they always get it wrong, where wrong = not what you want).

I really hope someone has a better answer to your question.


This is not the best way of going about solving the issue

vertical-align: middle

Adding style="position:relative;top:2px;" to the input box would move it down 2px. So depending on your font size, you can move it along.


Yay thanks! This too has been driving me nuts forever.

In my particular case, this worked for me:

input {
    width: 13px;
    height: 13px;
    padding: 0;
    margin:0;
    vertical-align: top;
    position: relative;
    *top: 1px;
    *overflow: hidden;
}
label {
    display: block;
    padding: 0;
    padding-left: 15px;
    text-indent: -15px;
    border: 0px solid;
    margin-left: 5px;
    vertical-align: top;
}

I am using the reset.css which might explain some of the differences, but this seems to work well for me.


The following gives pixel-perfect consistency across browsers, even IE9:

The approach is quite sensible, to the point of being obvious:

  1. Create an input and a label.
  2. Display them as block, so you can float them as you like.
  3. Set the height and the line-height to the same value to ensure they center and align vertically.
  4. For em measurements, to calculate the height of the elements, the browser must know the height of the font for those elements, and it must not itself be set in em measurements.

This results in a globally applicable general rule:

input, label {display:block;float:left;height:1em;line-height:1em;}

With font size adaptable per form, fieldset or element.

#myform input, #myform label {font-size:20px;}

Tested in latest Chrome, Safari, and Firefox on Mac, Windows, Iphone, and Android. And IE9.

This method is likely applicable to all input types that are not higher than one line of text. Apply a type rule to suit.


This works well for me:

_x000D_
_x000D_
fieldset {_x000D_
  text-align:left;_x000D_
  border:none_x000D_
}_x000D_
fieldset ol, fieldset ul {_x000D_
  padding:0;_x000D_
  list-style:none_x000D_
}_x000D_
fieldset li {_x000D_
  padding-bottom:1.5em;_x000D_
  float:none;_x000D_
  clear:left_x000D_
}_x000D_
label {_x000D_
  float:left;_x000D_
  width:7em;_x000D_
  margin-right:1em_x000D_
}_x000D_
fieldset.checkboxes li {_x000D_
  clear:both;_x000D_
  padding:.75em_x000D_
}_x000D_
fieldset.checkboxes label {_x000D_
  margin:0 0 0 1em;_x000D_
  width:20em_x000D_
}_x000D_
fieldset.checkboxes input {_x000D_
  float:left_x000D_
}
_x000D_
<form>_x000D_
  <fieldset class="checkboxes">_x000D_
    <ul>_x000D_
      <li>_x000D_
        <input type="checkbox" name="happy" value="yep" id="happy" />_x000D_
        <label for="happy">Happy?</label>_x000D_
      </li>_x000D_
      <li>_x000D_
        <input type="checkbox" name="hungry" value="yep" id="hungry" />_x000D_
        <label for="hungry">Hungry?</label>_x000D_
      </li>_x000D_
    </ul>_x000D_
  </fieldset>_x000D_
</form>
_x000D_
_x000D_
_x000D_


Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to css

need to add a class to an element Using Lato fonts in my css (@font-face) Please help me convert this script to a simple image slider Why there is this "clear" class before footer? How to set width of mat-table column in angular? Center content vertically on Vuetify bootstrap 4 file input doesn't show the file name Bootstrap 4: responsive sidebar menu to top navbar Stylesheet not loaded because of MIME-type Force flex item to span full row width

Examples related to cross-browser

Show datalist labels but submit the actual value Stupid error: Failed to load resource: net::ERR_CACHE_MISS Click to call html How to Detect Browser Back Button event - Cross Browser How can I make window.showmodaldialog work in chrome 37? Cross-browser custom styling for file upload button Flexbox and Internet Explorer 11 (display:flex in <html>?) browser sessionStorage. share between tabs? How to know whether refresh button or browser back button is clicked in Firefox CSS Custom Dropdown Select that works across all browsers IE7+ FF Webkit

Examples related to alignment

How do I center text vertically and horizontally in Flutter? CSS align one item right with flexbox What's the difference between align-content and align-items? align images side by side in html How to align iframe always in the center How to make popup look at the centre of the screen? Responsive image align center bootstrap 3 How to align title at center of ActionBar in default theme(Theme.Holo.Light) Center align a column in twitter bootstrap How do I position an image at the bottom of div?

Examples related to forms

How do I hide the PHP explode delimiter from submitted form results? React - clearing an input value after form submit How to prevent page from reloading after form submit - JQuery Input type number "only numeric value" validation Redirecting to a page after submitting form in HTML Clearing input in vuejs form Cleanest way to reset forms Reactjs - Form input validation No value accessor for form control TypeScript-'s Angular Framework Error - "There is no directive with exportAs set to ngForm"