Elementor Header #8

28. Радиокнопка

Радиокнопки в HTML используются для создания группы опций, из которых пользователь может выбрать только одну. В этом уроке мы рассмотрим, как использовать радиокнопки, их атрибуты и применение, а также предложим тестовое задание для закрепления материала.

Основы радиокнопок

Создание радиокнопки

Радиокнопки создаются с помощью тега <input> с атрибутом type="radio". Чтобы радиокнопки работали как группа, они должны иметь одинаковое значение атрибута name.

				
					<label for="gender-male">Мужчина</label>
<input type="radio" id="gender-male" name="gender" value="male">

<label for="gender-female">Женщина</label>
<input type="radio" id="gender-female" name="gender" value="female">

				
			

Атрибуты радиокнопок

Основные атрибуты

  • name: имя поля, по которому данные будут отправлены на сервер. Радиокнопки с одинаковым name группируются вместе.
  • value: значение, которое будет отправлено, если радиокнопка выбрана.
  • checked: устанавливает радиокнопку как выбранную по умолчанию.
  • disabled: делает радиокнопку недоступной для выбора.

Пример использования атрибутов

				
					<form>
  <p>Выберите ваш пол:</p>
  <input type="radio" id="gender-male" name="gender" value="male" checked>
  <label for="gender-male">Мужчина</label><br>

  <input type="radio" id="gender-female" name="gender" value="female">
  <label for="gender-female">Женщина</label><br>
</form>

				
			

Примеры использования радиокнопок

Пример 1: Выбор пола

				
					<!DOCTYPE html>
<html lang="ru">
<head>
  
  <title>Выбор пола</title>
</head>
<body>
  <form action="/submit-gender" method="POST">
    <p>Выберите ваш пол:</p>
    <input type="radio" id="gender-male" name="gender" value="male" checked>
    <label for="gender-male">Мужчина</label><br>

    <input type="radio" id="gender-female" name="gender" value="female">
    <label for="gender-female">Женщина</label><br>

    <input type="submit" value="Отправить">
  </form>
<script>"use strict";function wprRemoveCPCSS(){var preload_stylesheets=document.querySelectorAll('link[data-rocket-async="style"][rel="preload"]');if(preload_stylesheets&&0<preload_stylesheets.length)for(var stylesheet_index=0;stylesheet_index<preload_stylesheets.length;stylesheet_index++){var media=preload_stylesheets[stylesheet_index].getAttribute("media")||"all";if(window.matchMedia(media).matches)return void setTimeout(wprRemoveCPCSS,200)}var elem=document.getElementById("rocket-critical-css");elem&&"remove"in elem&&elem.remove()}window.addEventListener?window.addEventListener("load",wprRemoveCPCSS):window.attachEvent&&window.attachEvent("onload",wprRemoveCPCSS);</script><script>class RocketElementorAnimation{constructor(){this.deviceMode=document.createElement("span"),this.deviceMode.id="elementor-device-mode-wpr",this.deviceMode.setAttribute("class","elementor-screen-only"),document.body.appendChild(this.deviceMode)}_detectAnimations(){let t=getComputedStyle(this.deviceMode,":after").content.replace(/"/g,"");this.animationSettingKeys=this._listAnimationSettingsKeys(t),document.querySelectorAll(".elementor-invisible[data-settings]").forEach(t=>{const e=t.getBoundingClientRect();if(e.bottom>=0&&e.top<=window.innerHeight)try{this._animateElement(t)}catch(t){}})}_animateElement(t){const e=JSON.parse(t.dataset.settings),i=e._animation_delay||e.animation_delay||0,n=e[this.animationSettingKeys.find(t=>e[t])];if("none"===n)return void t.classList.remove("elementor-invisible");t.classList.remove(n),this.currentAnimation&&t.classList.remove(this.currentAnimation),this.currentAnimation=n;let s=setTimeout(()=>{t.classList.remove("elementor-invisible"),t.classList.add("animated",n),this._removeAnimationSettings(t,e)},i);window.addEventListener("rocket-startLoading",function(){clearTimeout(s)})}_listAnimationSettingsKeys(t="mobile"){const e=[""];switch(t){case"mobile":e.unshift("_mobile");case"tablet":e.unshift("_tablet");case"desktop":e.unshift("_desktop")}const i=[];return["animation","_animation"].forEach(t=>{e.forEach(e=>{i.push(t+e)})}),i}_removeAnimationSettings(t,e){this._listAnimationSettingsKeys().forEach(t=>delete e[t]),t.dataset.settings=JSON.stringify(e)}static run(){const t=new RocketElementorAnimation;requestAnimationFrame(t._detectAnimations.bind(t))}}document.addEventListener("DOMContentLoaded",RocketElementorAnimation.run);</script><noscript><link rel='stylesheet' id='hello-elementor-theme-style-css' href='https://codefor.tech/wp-content/themes/hello-elementor/theme.min.css?ver=3.0.2' media='all' /><link data-minify="1" rel='stylesheet' id='jet-menu-hello-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/jet-menu/integration/themes/hello-elementor/assets/css/style.css?ver=1724486282' media='all' /><link rel='stylesheet' id='sweetalert2-css' href='https://codefor.tech/wp-content/plugins/user-registration/assets/css/sweetalert2/sweetalert2.min.css?ver=10.16.7' media='all' /><link data-minify="1" rel='stylesheet' id='user-registration-general-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/user-registration/assets/css/user-registration.css?ver=1724486282' media='all' /><link data-minify="1" rel='stylesheet' id='user-registration-smallscreen-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/user-registration/assets/css/user-registration-smallscreen.css?ver=1724486282' media='only screen and (max-width: 768px)' /><link data-minify="1" rel='stylesheet' id='user-registration-my-account-layout-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/user-registration/assets/css/my-account-layout.css?ver=1724486282' media='all' /><link data-minify="1" rel='stylesheet' id='dashicons-css' href='https://codefor.tech/wp-content/cache/min/1/wp-includes/css/dashicons.min.css?ver=1724486282' media='all' /><link rel='stylesheet' id='hello-elementor-css' href='https://codefor.tech/wp-content/themes/hello-elementor/style.min.css?ver=3.0.2' media='all' /><link rel='stylesheet' id='hello-elementor-header-footer-css' href='https://codefor.tech/wp-content/themes/hello-elementor/header-footer.min.css?ver=3.0.2' media='all' /><link rel='stylesheet' id='elementor-frontend-css' href='https://codefor.tech/wp-content/plugins/elementor/assets/css/frontend-lite.min.css?ver=3.21.8' media='all' /><link rel='stylesheet' id='elementor-post-6-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-6.css?ver=1718118435' media='all' /><link data-minify="1" rel='stylesheet' id='font-awesome-all-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/jet-menu/assets/public/lib/font-awesome/css/all.min.css?ver=1724486282' media='all' /><link rel='stylesheet' id='font-awesome-v4-shims-css' href='https://codefor.tech/wp-content/plugins/jet-menu/assets/public/lib/font-awesome/css/v4-shims.min.css?ver=5.12.0' media='all' /><link data-minify="1" rel='stylesheet' id='jet-menu-public-styles-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/jet-menu/assets/public/css/public.css?ver=1724486282' media='all' /><link data-minify="1" rel='stylesheet' id='swiper-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/elementor/assets/lib/swiper/v8/css/swiper.min.css?ver=1724486282' media='all' /><link rel='stylesheet' id='elementor-pro-css' href='https://codefor.tech/wp-content/plugins/elementor-pro/assets/css/frontend-lite.min.css?ver=3.21.3' media='all' /><link rel='stylesheet' id='elementor-global-css' href='https://codefor.tech/wp-content/uploads/elementor/css/global.css?ver=1718118436' media='all' /><link rel='stylesheet' id='elementor-post-1640-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-1640.css?ver=1722908184' media='all' /><link rel='stylesheet' id='elementor-post-8-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-8.css?ver=1719760051' media='all' /><link rel='stylesheet' id='elementor-post-42-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-42.css?ver=1718469014' media='all' /><link rel='stylesheet' id='jquery-chosen-css' href='https://codefor.tech/wp-content/plugins/jet-search/assets/lib/chosen/chosen.min.css?ver=1.8.7' media='all' /><link data-minify="1" rel='stylesheet' id='jet-search-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/jet-search/assets/css/jet-search.css?ver=1724486282' media='all' /><link rel='stylesheet' id='google-fonts-1-css' href='https://fonts.googleapis.com/css?family=Roboto%3A100%2C100italic%2C200%2C200italic%2C300%2C300italic%2C400%2C400italic%2C500%2C500italic%2C600%2C600italic%2C700%2C700italic%2C800%2C800italic%2C900%2C900italic%7CRoboto+Slab%3A100%2C100italic%2C200%2C200italic%2C300%2C300italic%2C400%2C400italic%2C500%2C500italic%2C600%2C600italic%2C700%2C700italic%2C800%2C800italic%2C900%2C900italic&#038;display=swap&#038;subset=cyrillic&#038;ver=6.6.2' media='all' /><link rel="stylesheet" href="https://codefor.tech/wp-content/plugins/elementor-pro/assets/css/widget-theme-elements.min.css"><link rel="stylesheet" href="https://codefor.tech/wp-content/plugins/elementor/assets/css/widget-icon-list.min.css"><link rel='stylesheet' id='elementor-post-416-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-416.css?ver=1724268811' media='all' /><link rel='stylesheet' id='elementor-post-471-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-471.css?ver=1722847712' media='all' /><link rel='stylesheet' id='prismjs_style-css' href='https://codefor.tech/wp-content/plugins/elementor-pro/assets/css/modules/code-highlight.min.css?ver=1.23.0' media='' /><link data-minify="1" rel='stylesheet' id='mailpoet_public-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/mailpoet/assets/dist/css/mailpoet-public.c7ad0042.css?ver=1724486282' media='all' /><link rel='stylesheet' id='mailpoet_custom_fonts_0-css' href='https://fonts.googleapis.com/css?family=Abril+FatFace%3A400%2C400i%2C700%2C700i%7CAlegreya%3A400%2C400i%2C700%2C700i%7CAlegreya+Sans%3A400%2C400i%2C700%2C700i%7CAmatic+SC%3A400%2C400i%2C700%2C700i%7CAnonymous+Pro%3A400%2C400i%2C700%2C700i%7CArchitects+Daughter%3A400%2C400i%2C700%2C700i%7CArchivo%3A400%2C400i%2C700%2C700i%7CArchivo+Narrow%3A400%2C400i%2C700%2C700i%7CAsap%3A400%2C400i%2C700%2C700i%7CBarlow%3A400%2C400i%2C700%2C700i%7CBioRhyme%3A400%2C400i%2C700%2C700i%7CBonbon%3A400%2C400i%2C700%2C700i%7CCabin%3A400%2C400i%2C700%2C700i%7CCairo%3A400%2C400i%2C700%2C700i%7CCardo%3A400%2C400i%2C700%2C700i%7CChivo%3A400%2C400i%2C700%2C700i%7CConcert+One%3A400%2C400i%2C700%2C700i%7CCormorant%3A400%2C400i%2C700%2C700i%7CCrimson+Text%3A400%2C400i%2C700%2C700i%7CEczar%3A400%2C400i%2C700%2C700i%7CExo+2%3A400%2C400i%2C700%2C700i%7CFira+Sans%3A400%2C400i%2C700%2C700i%7CFjalla+One%3A400%2C400i%2C700%2C700i%7CFrank+Ruhl+Libre%3A400%2C400i%2C700%2C700i%7CGreat+Vibes%3A400%2C400i%2C700%2C700i&#038;ver=6.6.2' media='all' /><link rel='stylesheet' id='mailpoet_custom_fonts_1-css' href='https://fonts.googleapis.com/css?family=Heebo%3A400%2C400i%2C700%2C700i%7CIBM+Plex%3A400%2C400i%2C700%2C700i%7CInconsolata%3A400%2C400i%2C700%2C700i%7CIndie+Flower%3A400%2C400i%2C700%2C700i%7CInknut+Antiqua%3A400%2C400i%2C700%2C700i%7CInter%3A400%2C400i%2C700%2C700i%7CKarla%3A400%2C400i%2C700%2C700i%7CLibre+Baskerville%3A400%2C400i%2C700%2C700i%7CLibre+Franklin%3A400%2C400i%2C700%2C700i%7CMontserrat%3A400%2C400i%2C700%2C700i%7CNeuton%3A400%2C400i%2C700%2C700i%7CNotable%3A400%2C400i%2C700%2C700i%7CNothing+You+Could+Do%3A400%2C400i%2C700%2C700i%7CNoto+Sans%3A400%2C400i%2C700%2C700i%7CNunito%3A400%2C400i%2C700%2C700i%7COld+Standard+TT%3A400%2C400i%2C700%2C700i%7COxygen%3A400%2C400i%2C700%2C700i%7CPacifico%3A400%2C400i%2C700%2C700i%7CPoppins%3A400%2C400i%2C700%2C700i%7CProza+Libre%3A400%2C400i%2C700%2C700i%7CPT+Sans%3A400%2C400i%2C700%2C700i%7CPT+Serif%3A400%2C400i%2C700%2C700i%7CRakkas%3A400%2C400i%2C700%2C700i%7CReenie+Beanie%3A400%2C400i%2C700%2C700i%7CRoboto+Slab%3A400%2C400i%2C700%2C700i&#038;ver=6.6.2' media='all' /><link rel='stylesheet' id='mailpoet_custom_fonts_2-css' href='https://fonts.googleapis.com/css?family=Ropa+Sans%3A400%2C400i%2C700%2C700i%7CRubik%3A400%2C400i%2C700%2C700i%7CShadows+Into+Light%3A400%2C400i%2C700%2C700i%7CSpace+Mono%3A400%2C400i%2C700%2C700i%7CSpectral%3A400%2C400i%2C700%2C700i%7CSue+Ellen+Francisco%3A400%2C400i%2C700%2C700i%7CTitillium+Web%3A400%2C400i%2C700%2C700i%7CUbuntu%3A400%2C400i%2C700%2C700i%7CVarela%3A400%2C400i%2C700%2C700i%7CVollkorn%3A400%2C400i%2C700%2C700i%7CWork+Sans%3A400%2C400i%2C700%2C700i%7CYatra+One%3A400%2C400i%2C700%2C700i&#038;ver=6.6.2' media='all' /><link rel='stylesheet' id='elementor-post-487-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-487.css?ver=1719159596' media='all' /><link rel='stylesheet' id='elementor-post-497-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-497.css?ver=1724485504' media='all' /><link rel='stylesheet' id='elementor-post-503-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-503.css?ver=1718466482' media='all' /><link rel='stylesheet' id='elementor-post-329-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-329.css?ver=1718467092' media='all' /></noscript></body>
</html>

				
			

Пример 2: Выбор метода оплаты

				
					<!DOCTYPE html>
<html lang="ru">
<head>
  
  <title>Метод оплаты</title>
</head>
<body>
  <form action="/submit-payment" method="POST">
    <p>Выберите метод оплаты:</p>
    
    <input type="radio" id="payment-credit" name="payment" value="credit">
    <label for="payment-credit">Кредитная карта</label><br>
    
    <input type="radio" id="payment-paypal" name="payment" value="paypal">
    <label for="payment-paypal">PayPal</label><br>
    
    <input type="radio" id="payment-bank" name="payment" value="bank">
    <label for="payment-bank">Банковский перевод</label><br>

    <input type="submit" value="Отправить">
  </form>
<noscript><link rel='stylesheet' id='hello-elementor-theme-style-css' href='https://codefor.tech/wp-content/themes/hello-elementor/theme.min.css?ver=3.0.2' media='all' /><link data-minify="1" rel='stylesheet' id='jet-menu-hello-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/jet-menu/integration/themes/hello-elementor/assets/css/style.css?ver=1724486282' media='all' /><link rel='stylesheet' id='sweetalert2-css' href='https://codefor.tech/wp-content/plugins/user-registration/assets/css/sweetalert2/sweetalert2.min.css?ver=10.16.7' media='all' /><link data-minify="1" rel='stylesheet' id='user-registration-general-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/user-registration/assets/css/user-registration.css?ver=1724486282' media='all' /><link data-minify="1" rel='stylesheet' id='user-registration-smallscreen-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/user-registration/assets/css/user-registration-smallscreen.css?ver=1724486282' media='only screen and (max-width: 768px)' /><link data-minify="1" rel='stylesheet' id='user-registration-my-account-layout-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/user-registration/assets/css/my-account-layout.css?ver=1724486282' media='all' /><link data-minify="1" rel='stylesheet' id='dashicons-css' href='https://codefor.tech/wp-content/cache/min/1/wp-includes/css/dashicons.min.css?ver=1724486282' media='all' /><link rel='stylesheet' id='hello-elementor-css' href='https://codefor.tech/wp-content/themes/hello-elementor/style.min.css?ver=3.0.2' media='all' /><link rel='stylesheet' id='hello-elementor-header-footer-css' href='https://codefor.tech/wp-content/themes/hello-elementor/header-footer.min.css?ver=3.0.2' media='all' /><link rel='stylesheet' id='elementor-frontend-css' href='https://codefor.tech/wp-content/plugins/elementor/assets/css/frontend-lite.min.css?ver=3.21.8' media='all' /><link rel='stylesheet' id='elementor-post-6-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-6.css?ver=1718118435' media='all' /><link data-minify="1" rel='stylesheet' id='font-awesome-all-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/jet-menu/assets/public/lib/font-awesome/css/all.min.css?ver=1724486282' media='all' /><link rel='stylesheet' id='font-awesome-v4-shims-css' href='https://codefor.tech/wp-content/plugins/jet-menu/assets/public/lib/font-awesome/css/v4-shims.min.css?ver=5.12.0' media='all' /><link data-minify="1" rel='stylesheet' id='jet-menu-public-styles-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/jet-menu/assets/public/css/public.css?ver=1724486282' media='all' /><link data-minify="1" rel='stylesheet' id='swiper-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/elementor/assets/lib/swiper/v8/css/swiper.min.css?ver=1724486282' media='all' /><link rel='stylesheet' id='elementor-pro-css' href='https://codefor.tech/wp-content/plugins/elementor-pro/assets/css/frontend-lite.min.css?ver=3.21.3' media='all' /><link rel='stylesheet' id='elementor-global-css' href='https://codefor.tech/wp-content/uploads/elementor/css/global.css?ver=1718118436' media='all' /><link rel='stylesheet' id='elementor-post-1640-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-1640.css?ver=1722908184' media='all' /><link rel='stylesheet' id='elementor-post-8-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-8.css?ver=1719760051' media='all' /><link rel='stylesheet' id='elementor-post-42-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-42.css?ver=1718469014' media='all' /><link rel='stylesheet' id='jquery-chosen-css' href='https://codefor.tech/wp-content/plugins/jet-search/assets/lib/chosen/chosen.min.css?ver=1.8.7' media='all' /><link data-minify="1" rel='stylesheet' id='jet-search-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/jet-search/assets/css/jet-search.css?ver=1724486282' media='all' /><link rel='stylesheet' id='google-fonts-1-css' href='https://fonts.googleapis.com/css?family=Roboto%3A100%2C100italic%2C200%2C200italic%2C300%2C300italic%2C400%2C400italic%2C500%2C500italic%2C600%2C600italic%2C700%2C700italic%2C800%2C800italic%2C900%2C900italic%7CRoboto+Slab%3A100%2C100italic%2C200%2C200italic%2C300%2C300italic%2C400%2C400italic%2C500%2C500italic%2C600%2C600italic%2C700%2C700italic%2C800%2C800italic%2C900%2C900italic&#038;display=swap&#038;subset=cyrillic&#038;ver=6.6.2' media='all' /><link rel="stylesheet" href="https://codefor.tech/wp-content/plugins/elementor-pro/assets/css/widget-theme-elements.min.css"><link rel="stylesheet" href="https://codefor.tech/wp-content/plugins/elementor/assets/css/widget-icon-list.min.css"><link rel='stylesheet' id='elementor-post-416-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-416.css?ver=1724268811' media='all' /><link rel='stylesheet' id='elementor-post-471-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-471.css?ver=1722847712' media='all' /><link rel='stylesheet' id='prismjs_style-css' href='https://codefor.tech/wp-content/plugins/elementor-pro/assets/css/modules/code-highlight.min.css?ver=1.23.0' media='' /><link data-minify="1" rel='stylesheet' id='mailpoet_public-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/mailpoet/assets/dist/css/mailpoet-public.c7ad0042.css?ver=1724486282' media='all' /><link rel='stylesheet' id='mailpoet_custom_fonts_0-css' href='https://fonts.googleapis.com/css?family=Abril+FatFace%3A400%2C400i%2C700%2C700i%7CAlegreya%3A400%2C400i%2C700%2C700i%7CAlegreya+Sans%3A400%2C400i%2C700%2C700i%7CAmatic+SC%3A400%2C400i%2C700%2C700i%7CAnonymous+Pro%3A400%2C400i%2C700%2C700i%7CArchitects+Daughter%3A400%2C400i%2C700%2C700i%7CArchivo%3A400%2C400i%2C700%2C700i%7CArchivo+Narrow%3A400%2C400i%2C700%2C700i%7CAsap%3A400%2C400i%2C700%2C700i%7CBarlow%3A400%2C400i%2C700%2C700i%7CBioRhyme%3A400%2C400i%2C700%2C700i%7CBonbon%3A400%2C400i%2C700%2C700i%7CCabin%3A400%2C400i%2C700%2C700i%7CCairo%3A400%2C400i%2C700%2C700i%7CCardo%3A400%2C400i%2C700%2C700i%7CChivo%3A400%2C400i%2C700%2C700i%7CConcert+One%3A400%2C400i%2C700%2C700i%7CCormorant%3A400%2C400i%2C700%2C700i%7CCrimson+Text%3A400%2C400i%2C700%2C700i%7CEczar%3A400%2C400i%2C700%2C700i%7CExo+2%3A400%2C400i%2C700%2C700i%7CFira+Sans%3A400%2C400i%2C700%2C700i%7CFjalla+One%3A400%2C400i%2C700%2C700i%7CFrank+Ruhl+Libre%3A400%2C400i%2C700%2C700i%7CGreat+Vibes%3A400%2C400i%2C700%2C700i&#038;ver=6.6.2' media='all' /><link rel='stylesheet' id='mailpoet_custom_fonts_1-css' href='https://fonts.googleapis.com/css?family=Heebo%3A400%2C400i%2C700%2C700i%7CIBM+Plex%3A400%2C400i%2C700%2C700i%7CInconsolata%3A400%2C400i%2C700%2C700i%7CIndie+Flower%3A400%2C400i%2C700%2C700i%7CInknut+Antiqua%3A400%2C400i%2C700%2C700i%7CInter%3A400%2C400i%2C700%2C700i%7CKarla%3A400%2C400i%2C700%2C700i%7CLibre+Baskerville%3A400%2C400i%2C700%2C700i%7CLibre+Franklin%3A400%2C400i%2C700%2C700i%7CMontserrat%3A400%2C400i%2C700%2C700i%7CNeuton%3A400%2C400i%2C700%2C700i%7CNotable%3A400%2C400i%2C700%2C700i%7CNothing+You+Could+Do%3A400%2C400i%2C700%2C700i%7CNoto+Sans%3A400%2C400i%2C700%2C700i%7CNunito%3A400%2C400i%2C700%2C700i%7COld+Standard+TT%3A400%2C400i%2C700%2C700i%7COxygen%3A400%2C400i%2C700%2C700i%7CPacifico%3A400%2C400i%2C700%2C700i%7CPoppins%3A400%2C400i%2C700%2C700i%7CProza+Libre%3A400%2C400i%2C700%2C700i%7CPT+Sans%3A400%2C400i%2C700%2C700i%7CPT+Serif%3A400%2C400i%2C700%2C700i%7CRakkas%3A400%2C400i%2C700%2C700i%7CReenie+Beanie%3A400%2C400i%2C700%2C700i%7CRoboto+Slab%3A400%2C400i%2C700%2C700i&#038;ver=6.6.2' media='all' /><link rel='stylesheet' id='mailpoet_custom_fonts_2-css' href='https://fonts.googleapis.com/css?family=Ropa+Sans%3A400%2C400i%2C700%2C700i%7CRubik%3A400%2C400i%2C700%2C700i%7CShadows+Into+Light%3A400%2C400i%2C700%2C700i%7CSpace+Mono%3A400%2C400i%2C700%2C700i%7CSpectral%3A400%2C400i%2C700%2C700i%7CSue+Ellen+Francisco%3A400%2C400i%2C700%2C700i%7CTitillium+Web%3A400%2C400i%2C700%2C700i%7CUbuntu%3A400%2C400i%2C700%2C700i%7CVarela%3A400%2C400i%2C700%2C700i%7CVollkorn%3A400%2C400i%2C700%2C700i%7CWork+Sans%3A400%2C400i%2C700%2C700i%7CYatra+One%3A400%2C400i%2C700%2C700i&#038;ver=6.6.2' media='all' /><link rel='stylesheet' id='elementor-post-487-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-487.css?ver=1719159596' media='all' /><link rel='stylesheet' id='elementor-post-497-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-497.css?ver=1724485504' media='all' /><link rel='stylesheet' id='elementor-post-503-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-503.css?ver=1718466482' media='all' /><link rel='stylesheet' id='elementor-post-329-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-329.css?ver=1718467092' media='all' /></noscript></body>
</html>

				
			

Распространенные ошибки

1. Отсутствие атрибута name

Без атрибута name данные поля не будут отправлены на сервер и радиокнопки не будут группироваться.

				
					<!-- Неправильно -->
<input type="radio" id="gender-male" value="male">
<input type="radio" id="gender-female" value="female">

<!-- Правильно -->
<input type="radio" id="gender-male" name="gender" value="male">
<input type="radio" id="gender-female" name="gender" value="female">

				
			

2. Отсутствие атрибута value

Атрибут value должен быть указан, чтобы знать, какое значение отправляется при выборе радиокнопки.

				
					<!-- Неправильно -->
<input type="radio" id="gender-male" name="gender">
<input type="radio" id="gender-female" name="gender">

<!-- Правильно -->
<input type="radio" id="gender-male" name="gender" value="male">
<input type="radio" id="gender-female" name="gender" value="female">

				
			

3. Забытие атрибута checked

Если необходимо, чтобы радиокнопка была выбрана по умолчанию, используйте атрибут checked.

				
					<!-- Неправильно -->
<input type="radio" id="gender-male" name="gender" value="male">
<input type="radio" id="gender-female" name="gender" value="female">

<!-- Правильно -->
<input type="radio" id="gender-male" name="gender" value="male" checked>
<input type="radio" id="gender-female" name="gender" value="female">

				
			

Заключение

В этом уроке мы рассмотрели, как использовать радиокнопки в HTML, их атрибуты и примеры использования. Радиокнопки позволяют пользователям выбирать один вариант из группы, что делает формы более интерактивными и удобными.

Тестовое задание

Создайте веб-страницу, которая содержит форму с следующими элементами:

  1. Группу радиокнопок для выбора типа доставки (например, стандартная доставка, экспресс-доставка).
  2. Группу радиокнопок для выбора предпочтительного времени доставки (например, утро, день, вечер).
  3. Кнопку для отправки формы.
				
					<!DOCTYPE html>
<html lang="ru">
<head>
  
  <title>Форма доставки</title>
</head>
<body>
  <form action="/submit-delivery" method="POST">
    <p>Выберите тип доставки:</p>
    <input type="radio" id="delivery-standard" name="delivery" value="standard" checked>
    <label for="delivery-standard">Стандартная доставка</label><br>

    <input type="radio" id="delivery-express" name="delivery" value="express">
    <label for="delivery-express">Экспресс-доставка</label><br>

    <p>Выберите предпочтительное время доставки:</p>
    <input type="radio" id="time-morning" name="time" value="morning" checked>
    <label for="time-morning">Утро</label><br>
    
    <input type="radio" id="time-afternoon" name="time" value="afternoon">
    <label for="time-afternoon">День</label><br>
    
    <input type="radio" id="time-evening" name="time" value="evening">
    <label for="time-evening">Вечер</label><br>

    <input type="submit" value="Отправить">
  </form>
<noscript><link rel='stylesheet' id='hello-elementor-theme-style-css' href='https://codefor.tech/wp-content/themes/hello-elementor/theme.min.css?ver=3.0.2' media='all' /><link data-minify="1" rel='stylesheet' id='jet-menu-hello-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/jet-menu/integration/themes/hello-elementor/assets/css/style.css?ver=1724486282' media='all' /><link rel='stylesheet' id='sweetalert2-css' href='https://codefor.tech/wp-content/plugins/user-registration/assets/css/sweetalert2/sweetalert2.min.css?ver=10.16.7' media='all' /><link data-minify="1" rel='stylesheet' id='user-registration-general-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/user-registration/assets/css/user-registration.css?ver=1724486282' media='all' /><link data-minify="1" rel='stylesheet' id='user-registration-smallscreen-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/user-registration/assets/css/user-registration-smallscreen.css?ver=1724486282' media='only screen and (max-width: 768px)' /><link data-minify="1" rel='stylesheet' id='user-registration-my-account-layout-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/user-registration/assets/css/my-account-layout.css?ver=1724486282' media='all' /><link data-minify="1" rel='stylesheet' id='dashicons-css' href='https://codefor.tech/wp-content/cache/min/1/wp-includes/css/dashicons.min.css?ver=1724486282' media='all' /><link rel='stylesheet' id='hello-elementor-css' href='https://codefor.tech/wp-content/themes/hello-elementor/style.min.css?ver=3.0.2' media='all' /><link rel='stylesheet' id='hello-elementor-header-footer-css' href='https://codefor.tech/wp-content/themes/hello-elementor/header-footer.min.css?ver=3.0.2' media='all' /><link rel='stylesheet' id='elementor-frontend-css' href='https://codefor.tech/wp-content/plugins/elementor/assets/css/frontend-lite.min.css?ver=3.21.8' media='all' /><link rel='stylesheet' id='elementor-post-6-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-6.css?ver=1718118435' media='all' /><link data-minify="1" rel='stylesheet' id='font-awesome-all-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/jet-menu/assets/public/lib/font-awesome/css/all.min.css?ver=1724486282' media='all' /><link rel='stylesheet' id='font-awesome-v4-shims-css' href='https://codefor.tech/wp-content/plugins/jet-menu/assets/public/lib/font-awesome/css/v4-shims.min.css?ver=5.12.0' media='all' /><link data-minify="1" rel='stylesheet' id='jet-menu-public-styles-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/jet-menu/assets/public/css/public.css?ver=1724486282' media='all' /><link data-minify="1" rel='stylesheet' id='swiper-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/elementor/assets/lib/swiper/v8/css/swiper.min.css?ver=1724486282' media='all' /><link rel='stylesheet' id='elementor-pro-css' href='https://codefor.tech/wp-content/plugins/elementor-pro/assets/css/frontend-lite.min.css?ver=3.21.3' media='all' /><link rel='stylesheet' id='elementor-global-css' href='https://codefor.tech/wp-content/uploads/elementor/css/global.css?ver=1718118436' media='all' /><link rel='stylesheet' id='elementor-post-1640-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-1640.css?ver=1722908184' media='all' /><link rel='stylesheet' id='elementor-post-8-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-8.css?ver=1719760051' media='all' /><link rel='stylesheet' id='elementor-post-42-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-42.css?ver=1718469014' media='all' /><link rel='stylesheet' id='jquery-chosen-css' href='https://codefor.tech/wp-content/plugins/jet-search/assets/lib/chosen/chosen.min.css?ver=1.8.7' media='all' /><link data-minify="1" rel='stylesheet' id='jet-search-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/jet-search/assets/css/jet-search.css?ver=1724486282' media='all' /><link rel='stylesheet' id='google-fonts-1-css' href='https://fonts.googleapis.com/css?family=Roboto%3A100%2C100italic%2C200%2C200italic%2C300%2C300italic%2C400%2C400italic%2C500%2C500italic%2C600%2C600italic%2C700%2C700italic%2C800%2C800italic%2C900%2C900italic%7CRoboto+Slab%3A100%2C100italic%2C200%2C200italic%2C300%2C300italic%2C400%2C400italic%2C500%2C500italic%2C600%2C600italic%2C700%2C700italic%2C800%2C800italic%2C900%2C900italic&#038;display=swap&#038;subset=cyrillic&#038;ver=6.6.2' media='all' /><link rel="stylesheet" href="https://codefor.tech/wp-content/plugins/elementor-pro/assets/css/widget-theme-elements.min.css"><link rel="stylesheet" href="https://codefor.tech/wp-content/plugins/elementor/assets/css/widget-icon-list.min.css"><link rel='stylesheet' id='elementor-post-416-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-416.css?ver=1724268811' media='all' /><link rel='stylesheet' id='elementor-post-471-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-471.css?ver=1722847712' media='all' /><link rel='stylesheet' id='prismjs_style-css' href='https://codefor.tech/wp-content/plugins/elementor-pro/assets/css/modules/code-highlight.min.css?ver=1.23.0' media='' /><link data-minify="1" rel='stylesheet' id='mailpoet_public-css' href='https://codefor.tech/wp-content/cache/min/1/wp-content/plugins/mailpoet/assets/dist/css/mailpoet-public.c7ad0042.css?ver=1724486282' media='all' /><link rel='stylesheet' id='mailpoet_custom_fonts_0-css' href='https://fonts.googleapis.com/css?family=Abril+FatFace%3A400%2C400i%2C700%2C700i%7CAlegreya%3A400%2C400i%2C700%2C700i%7CAlegreya+Sans%3A400%2C400i%2C700%2C700i%7CAmatic+SC%3A400%2C400i%2C700%2C700i%7CAnonymous+Pro%3A400%2C400i%2C700%2C700i%7CArchitects+Daughter%3A400%2C400i%2C700%2C700i%7CArchivo%3A400%2C400i%2C700%2C700i%7CArchivo+Narrow%3A400%2C400i%2C700%2C700i%7CAsap%3A400%2C400i%2C700%2C700i%7CBarlow%3A400%2C400i%2C700%2C700i%7CBioRhyme%3A400%2C400i%2C700%2C700i%7CBonbon%3A400%2C400i%2C700%2C700i%7CCabin%3A400%2C400i%2C700%2C700i%7CCairo%3A400%2C400i%2C700%2C700i%7CCardo%3A400%2C400i%2C700%2C700i%7CChivo%3A400%2C400i%2C700%2C700i%7CConcert+One%3A400%2C400i%2C700%2C700i%7CCormorant%3A400%2C400i%2C700%2C700i%7CCrimson+Text%3A400%2C400i%2C700%2C700i%7CEczar%3A400%2C400i%2C700%2C700i%7CExo+2%3A400%2C400i%2C700%2C700i%7CFira+Sans%3A400%2C400i%2C700%2C700i%7CFjalla+One%3A400%2C400i%2C700%2C700i%7CFrank+Ruhl+Libre%3A400%2C400i%2C700%2C700i%7CGreat+Vibes%3A400%2C400i%2C700%2C700i&#038;ver=6.6.2' media='all' /><link rel='stylesheet' id='mailpoet_custom_fonts_1-css' href='https://fonts.googleapis.com/css?family=Heebo%3A400%2C400i%2C700%2C700i%7CIBM+Plex%3A400%2C400i%2C700%2C700i%7CInconsolata%3A400%2C400i%2C700%2C700i%7CIndie+Flower%3A400%2C400i%2C700%2C700i%7CInknut+Antiqua%3A400%2C400i%2C700%2C700i%7CInter%3A400%2C400i%2C700%2C700i%7CKarla%3A400%2C400i%2C700%2C700i%7CLibre+Baskerville%3A400%2C400i%2C700%2C700i%7CLibre+Franklin%3A400%2C400i%2C700%2C700i%7CMontserrat%3A400%2C400i%2C700%2C700i%7CNeuton%3A400%2C400i%2C700%2C700i%7CNotable%3A400%2C400i%2C700%2C700i%7CNothing+You+Could+Do%3A400%2C400i%2C700%2C700i%7CNoto+Sans%3A400%2C400i%2C700%2C700i%7CNunito%3A400%2C400i%2C700%2C700i%7COld+Standard+TT%3A400%2C400i%2C700%2C700i%7COxygen%3A400%2C400i%2C700%2C700i%7CPacifico%3A400%2C400i%2C700%2C700i%7CPoppins%3A400%2C400i%2C700%2C700i%7CProza+Libre%3A400%2C400i%2C700%2C700i%7CPT+Sans%3A400%2C400i%2C700%2C700i%7CPT+Serif%3A400%2C400i%2C700%2C700i%7CRakkas%3A400%2C400i%2C700%2C700i%7CReenie+Beanie%3A400%2C400i%2C700%2C700i%7CRoboto+Slab%3A400%2C400i%2C700%2C700i&#038;ver=6.6.2' media='all' /><link rel='stylesheet' id='mailpoet_custom_fonts_2-css' href='https://fonts.googleapis.com/css?family=Ropa+Sans%3A400%2C400i%2C700%2C700i%7CRubik%3A400%2C400i%2C700%2C700i%7CShadows+Into+Light%3A400%2C400i%2C700%2C700i%7CSpace+Mono%3A400%2C400i%2C700%2C700i%7CSpectral%3A400%2C400i%2C700%2C700i%7CSue+Ellen+Francisco%3A400%2C400i%2C700%2C700i%7CTitillium+Web%3A400%2C400i%2C700%2C700i%7CUbuntu%3A400%2C400i%2C700%2C700i%7CVarela%3A400%2C400i%2C700%2C700i%7CVollkorn%3A400%2C400i%2C700%2C700i%7CWork+Sans%3A400%2C400i%2C700%2C700i%7CYatra+One%3A400%2C400i%2C700%2C700i&#038;ver=6.6.2' media='all' /><link rel='stylesheet' id='elementor-post-487-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-487.css?ver=1719159596' media='all' /><link rel='stylesheet' id='elementor-post-497-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-497.css?ver=1724485504' media='all' /><link rel='stylesheet' id='elementor-post-503-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-503.css?ver=1718466482' media='all' /><link rel='stylesheet' id='elementor-post-329-css' href='https://codefor.tech/wp-content/uploads/elementor/css/post-329.css?ver=1718467092' media='all' /></noscript></body>
</html>

				
			

Проверьте свою работу на наличие ошибок и убедитесь, что страница корректно отображается в браузере.

logo