+ 1

How can i organise radio buttons to the straight left sided line while keeping them at the center?

<!-- I tried to change text alignment to center, display to flex, etc. but didn't work --> <div> <form> <p class="heading2">Are you cool?:</p> <input type="radio" id="yes" name="cool" value="Yes"> <label for="yes">Yes</label><br> <input type="radio" id="no" name="cool" value="No" > <label for="no">No</label><br> </form> </div>

2nd Apr 2025, 6:27 AM
Doniyor Xudoyqulov
Doniyor Xudoyqulov - avatar
7 Answers
+ 5
Use display:flex with justify-content:centre; align-items:centre; This will align both horizontally and vertically
2nd Apr 2025, 10:59 AM
Penguin Coder 🐧
Penguin Coder  🐧 - avatar
2nd Apr 2025, 8:45 AM
Ausgrindtube
Ausgrindtube - avatar
+ 4
You can try this CSS: div { display: flex; justify-content: center; /* Centers horizontally */align-items: center; /* Centers vertically */ height: 100 vh; /* Optional: 100vh makes the div container element fill the full viewport height */ gap: 10 px */Optional: this defines the gap between the radio button and its label. It merely enhances readability, so you can stick to the default spacing*/ } form { display: flex; flex-direction: column; align-items: flex-start; }
2nd Apr 2025, 11:27 AM
Ushasi Bhattacharya
+ 3
display:flex; align-items:centre;
2nd Apr 2025, 9:59 AM
Ushasi Bhattacharya
+ 3
There is, in fact, another alternative method: CSS Grid. Since you want the form to be center-aligned and the radio buttons left-aligned, you can try this out as well. Nest ALL THE RADIO BUTTONS inside a <div class="radio_grp">. The CSS code is: div { */This is for the div tag that has enclosed the entire form*/ display:grid; place-items:center */This will center-align the text both horizontally and vertically */ } form{ display:grid; place-items:left; */This will align the form elements to the left.*/ } .radio_grp{ */This is for the div tag enclosing the radio buttons */ display:grid; grid-template-columns: auto 1fr; */ This will make the radio button go in one column and the label in the adjacent one */
2nd Apr 2025, 11:46 AM
Ushasi Bhattacharya
+ 3
<style> .container, form, .cb{ margin: auto; } .heading2{ text-align:center; } form, .cb{ width:fit-content; } </style> <div class="container"> <form> <p class="heading2">Are you cool?:</p> <div class="cb"> <input type="radio" id="yes" name="cool" value="Yes"> <label for="yes">Yes</label> <br> <input type="radio" id="no" name="cool" value="No" > <label for="no">No</label><br> </div> </form> </div>
2nd Apr 2025, 2:04 PM
Bob_Li
Bob_Li - avatar
+ 2
U can use the method shown by Ushasi Bhattacharya, additionally, assigning display: block; margin:auto; Will do the work too
2nd Apr 2025, 10:43 AM
Unknown Decoder (Ayush Kumar Singh)
Unknown Decoder (Ayush Kumar Singh) - avatar