Radio buttons and checkboxes let users pick options on a form. They help collect choices easily.
Radio buttons and checkboxes in HTML
<input type="radio" name="group1" value="option1"> Option 1 <input type="checkbox" name="check1" value="optionA"> Option A
Radio buttons with the same name belong to one group; only one can be selected.
Checkboxes work independently; users can select many or none.
<input type="radio" name="color" value="red"> Red <input type="radio" name="color" value="blue"> Blue
<input type="checkbox" name="fruit" value="apple"> Apple <input type="checkbox" name="fruit" value="banana"> Banana
checked.<input type="radio" name="size" value="small" checked> Small <input type="radio" name="size" value="large"> Large
<input type="checkbox" name="subscribe" value="yes" checked> Subscribe to newsletter
This page shows a form with two groups: one for picking a single favorite color using radio buttons, and one for selecting multiple hobbies using checkboxes. Labels make it easy to click the option text. The form is accessible and responsive.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Radio and Checkbox Example</title> <style> body { font-family: Arial, sans-serif; padding: 1rem; max-width: 400px; margin: auto; } fieldset { margin-bottom: 1.5rem; border: 1px solid #ccc; padding: 1rem; border-radius: 0.5rem; } legend { font-weight: bold; padding: 0 0.5rem; } label { display: block; margin-bottom: 0.5rem; cursor: pointer; } </style> </head> <body> <main> <form aria-label="Favorite options form"> <fieldset> <legend>Choose your favorite color</legend> <label><input type="radio" name="color" value="red"> Red</label> <label><input type="radio" name="color" value="green"> Green</label> <label><input type="radio" name="color" value="blue"> Blue</label> </fieldset> <fieldset> <legend>Select your hobbies</legend> <label><input type="checkbox" name="hobby" value="reading"> Reading</label> <label><input type="checkbox" name="hobby" value="sports"> Sports</label> <label><input type="checkbox" name="hobby" value="music"> Music</label> </fieldset> <button type="submit">Submit</button> </form> </main> </body> </html>
Always use <label> tags with inputs for better accessibility and easier clicking.
Use the same name attribute for radio buttons in one group to link them.
Checkboxes can have the same or different name depending on how you want to collect data.
Radio buttons let users pick only one option from a group.
Checkboxes let users pick any number of options, including none.
Labels improve usability and accessibility for both controls.