How can I simply align my checkbox with Label text using HTML CSS, so that it works in all browsers consistently?
I am facing this issue in some browsers, if it works in chrome, it doesn't work in IE or if it works properly in Firefox it doesn't align properly in chrome.
So want to align Checkbox with Label text properly which can work in all browsers equally? Reference code
<div>
<label>
<input type="checkbox" /> Checkbox Label
</label>
</div>
thanks
If you want to go with above HTML code only, i.e. means html would be without wrapping label text, your HTML /CSS code to align checkbox with Label properly can be
input[type=checkbox], input[type=radio] {
vertical-align: middle;
position: relative;
bottom: 1px;
}
input[type=radio] {
bottom: 2px;
}
<label>
<input type="checkbox">
Label text
</label>
Another simple Inline CSS code would be
<input type="checkbox" />
<label style="font-size: 16px;position: relative;top: -2px;">This is the label</label>
Using bottom property and veritcal align in CSS, we can align checkbox
.font2, .font2 input {font-family:Arial; font-size:32px} /* sample large fonts */
input[type=checkbox], input[type=radio] {
vertical-align: middle;
position: relative;
bottom: .08em; /* this is helpful */
}
and considering HTML
<form>
<label>
<input type="radio" checked>
I am an aligned radio and label
</label>
<label>
<input type="checkbox" checked>
I am an aligned checkbox and label
</label>
</form><label><input type="checkbox" /> Simple text</label>
<p class="font2">
<label><input type="checkbox"/> Large Label text</label>
</p>
You can check fiddle here: https://jsfiddle.net/zdwjr068/
This should also work, thanks
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly