113

I have a form with radio buttons that are on the same line as their labels. The radio buttons are however not aligned vertically with their labels as shown in the screenshot below.

The radio buttons.

How can I vertically align the radio buttons with their labels?

Edit:

Here's the html code:

<input checked="checked" type="radio" name="user_level" id="rd1" value="1"/>
<label for="rd1">radio 1</label><br/>
<input type="radio" name="user_level" id="rd2" value="2"/>
<label for="rd2">radio 2</label><br/>
<input type="radio" name="user_level" id="rd3" value="3"/>
<label for="rd3">radio 3</label><br/>

And the css code:

label{
    padding:5px;
    color:#222;
    font-family:corbel,sans-serif;
    font-size: 14px;
    margin: 10px;
}
isherwood
  • 58,414
  • 16
  • 114
  • 157
ninjacoder
  • 1,464
  • 2
  • 10
  • 13

15 Answers15

177

Try this:

input[type="radio"] {
  margin-top: -1px;
  vertical-align: middle;
}
zxqx
  • 5,115
  • 2
  • 20
  • 28
  • 9
    This worked for me however I had to add a `height= 100%;` since my parent element did not explicitly set the height. – DaKaZ Dec 05 '14 at 17:11
  • 1
    This seemed to give me the most consistent approach between Mac, Windows, and Linux, using Chrome, Firefox, or IE. Also, I noticed that if I give padding on my label and put the radio inside the label, then I may need to set margin-top to a value less than -1px (like -3px) based on how much padding I was using on that label. (I like to give my radio box labels a hover color and rounded border effect to make them look cooler.) – Volomike May 09 '16 at 00:26
  • 3
    To explain why this is the only correct answer: Some elements in HTML have default margin or padding values, like the

    or

  • elements or radio buttons. You can see this if you go into developer mode (F12) and hover your mouse over the tag. Actually, this is a good behaviour, because the browser himself use CSS to position predefined elements which the user then can reset. But it can be confusing if you don't know why something is misaligned in the first place. So always try to overwrite settings which you didn't set, if it looks weird by default.
  • – StanE Oct 09 '16 at 19:52
  • This doesn't seem to work when you increase or decrease font size. Please prove me wrong with a working example, though! – Protector one Jun 19 '17 at 12:34