How to create a custom radio button
Tags: html, css, beginners, tutorial
Published: 2021-03-08 08:05:46

***Hello, guys in this tutorial we will create a custom radio button using HTML & CSS***

###What radio button means?###
In HTML, a radio button is a graphical control element that allows the user to choose only one of a predefined set of mutually exclusive options. **The radio button is also known as the option button**

A radio button in HTML can be defined using the `<input>` tag, like below example
```html
<input type="radio" name="answer">
```
***Note: The input tag only creates a radio button. if you want to add a label also then you have to insert the label yourself.***

###Common Query###
1. How to create a radio button
2. How to create a custom radio button
3. How to create a radio button in HTML

Hello, guys In this <a href="https://blog.stackfindover.com/category/tutorials/">tutorial</a> we will try to solve above mention query. and also we will learn how to create a custom radio button using <a href="https://blog.stackfindover.com/category/html-css/">HTML & CSS</a>

First, we need to create three files **index.html** and **style.css** then we need to do code for it.

###Step:1###
***Add below code inside index.html***

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Custom Radio Buttons</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <link rel="stylesheet" href="style.css" />
  <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@500&display=swap" rel="stylesheet">
</head>
<body>
  <div class="wrapper">
    <input type="radio" name="select" id="one" checked>
    <input type="radio" name="select" id="two">

    <label for="one" class="option option-1">
      <span>One</span>
    </label>
    <label for="two" class="option option-2">
      <span>Two</span>
    </label>
  </div>
</body>
</html>
```
###Step:2###
Then we need to add code for **style.css** which code I provide in the below screen.

```css
* {
  padding: 0;
  margin: 0;
  outline: 0;
  color: #444;
  box-sizing: border-box;
  font-family: 'IBM Plex Sans', sans-serif;
}
html, body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: #180f2f;
}
.wrapper {
  display: inline-flex;
  background: #fff;
  height: 100px;
  width: 250px;
  align-items: center;
  justify-content: space-evenly;
  border-radius: 5px;
  padding: 20px 15px;
  box-shadow: 5px 5px 30px rgb(0 0 0 / 20%);
}
.wrapper .option {
  background: #fff;
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  cursor: pointer;
  border-radius: 5px;
  padding: 0 10px;
  border: 2px solid #180f2f;
  transition: all 0.5s ease;
  margin: 0 10px;
}
input[type="radio"] {
  display: none;
}
input#one:checked ~ .option-1,
input#two:checked ~ .option-2 {
  background: #180f2f;
  border-color: #180f2f;
}

input#one:checked ~ .option-1 span,
input#two:checked ~ .option-2 span {
  color: #fff;
}
.wrapper .option span {
  font-size: 20px;
}
```

###How to create a custom radio button Video output:###
{% youtube NST69c2FGJw %}

###How to create a custom radio button codepen output:###
{% codepen https://codepen.io/stack-findover/pen/GRremYd %}