HTML:HTML Form Controls: Checkboxes, Radio Buttons, and <select>
HTML•Form Controls

HTML Form Controls: Checkboxes, Radio Buttons, and <select>

Learn how to group radio buttons with name attributes and construct dropdown menus with <option>.

Syntax

<select name="tier"> <option value="free">Free</option> </select>

Parameters & Values

Key components and acceptable values for this structure:

ParameterTypeDescription
name (radio group)AttributeShares single selection mutually exclusively across radios.

Ready-to-Run Code Example

Executable in Compilra

Run this complete, working example directly without installing HTML locally:

<!DOCTYPE html>
<html>
<head>
  <style>
    body { font-family: sans-serif; padding: 20px; line-height: 1.6; }
    .group { margin-bottom: 12px; }
    select { padding: 8px; border-radius: 6px; border: 1px solid #cbd5e1; }
  </style>
</head>
<body>
  <h2>Compiler Environment Configuration</h2>
  <div class="group">
    <label><strong>Select Language Engine:</strong></label><br />
    <select id="engine">
      <option value="python">Python 3.12</option>
      <option value="cpp">C++ (GCC 14)</option>
      <option value="rust">Rust 1.85</option>
    </select>
  </div>
  <div class="group">
    <label><input type="checkbox" checked /> Include Pre-Supplied Standard Input (stdin)</label>
  </div>
</body>
</html>
Expected Output:
[Rendered Dropdown Select with Languages and Checked Checkbox Option]

How It Works: Step-by-Step

  • Lines 12-18: <select> dropdown populated with <option> items.
  • Line 20: type="checkbox" with default checked state.

Key Concepts

  • Radio buttons with identical name values are mutually exclusive.
  • Checkboxes allow independent multi-value boolean selections.

Common Mistake: Giving radio buttons different name attributes

Radio buttons only group together when they share the exact same name attribute.

❌ Incorrect
<input type="radio" name="opt1" /> <input type="radio" name="opt2" /> // Both can be checked!
✅ Correct
<input type="radio" name="opt" value="1" /> <input type="radio" name="opt" value="2" />

Related HTML Tutorials & Compiler

Run and test HTML on Compilra

Execute this code snippet with pre-supplied standard input (stdin) in Compilra’s cloud compiler.

HTML Online Compiler