"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Align Radio Buttons and Labels on the Same Line in HTML?

How to Align Radio Buttons and Labels on the Same Line in HTML?

Published on 2024-11-09
Browse:900

How to Align Radio Buttons and Labels on the Same Line in HTML?

Positioning Radio Buttons and Labels on the Same Line

In HTML forms, aligning radio buttons and their associated labels on a single line can be challenging. To achieve this, several CSS techniques can be employed.

The suggested HTML structure positions the label and input elements:


To align them horizontally, add the following CSS rules:

label {
  float: left;
  clear: none;
  display: block;
  padding: 0px 1em 0px 8px;
}

input[type=radio],
input.radio {
  float: left;
  clear: none;
  margin: 2px 0 0 2px;
}

This positions the label and radio button next to each other. To ensure that multiple radio buttons are aligned on the same line, use the following markup:

With the appropriate CSS rules, the radio buttons and labels will be aligned on the same line.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3