Към основното съдържание
← 📄 HTML & the platform·Модул A3 · Урок 9
ЗадачаBuild a billing-cycle picker: two radios with name='cycle', values 'monthly' and 'yearly'. Yearly is pre-selected (checked). Each has an inline label.

<input type=radio>: изключителен избор

75 XP6 min
Теория

Radio = exactly one choice from a group

<input type="radio" id="m" name="plan" value="monthly" />
<label for="m">$9/mo</label>

<input type="radio" id="y" name="plan" value="yearly" checked />
<label for="y">$90/yr (save 17%)</label>
  • All radios with the same name are mutually exclusive — clicking one unchecks the others.
  • value is what gets submitted (plan=yearly). Text is what the user reads.
  • checked on one of them is the default.

When to use radio vs select

Use radio whenUse select when
2-5 options6+ options
Choices are short (1-3 words each)Choices are long or wordy
All choices should be visible at onceSaving vertical space matters

Plan picker, gender, size (S/M/L), payment method — radio. Country, year, language — select.

Layout

Radios are inline by default. For a vertical stack:

label { display: block; padding: 4px 0; }

For "card-style" radios (where the whole card is clickable), put the radio inside the label:

<label>
  <input type="radio" name="plan" value="yearly" />
  <strong>Yearly</strong>
  <p>$90/year — save 17%</p>
</label>
🔒

Регистрирай се за да започнеш да кодираш

Теорията е отворена за всички. Редакторът, живият преглед и проверката се отключват с 7-дневен безплатен пробен период — нужна е карта.

Регистрация — безплатен пробен период →

Първите 10 урока във всеки път са безплатни. Без карта.

← НазадСледващ урок →

Един съвет за Python или уеб на ден — на имейл

Кратко, ръчно написано, без спам. Отписване с едно кликване.