<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Custom Radio Button</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<p>Select Gender:-</p>
<div class="btn">
<input type="radio" name="gender" id="Male" />
<label for="Male">Male</label>
</div>
<div class="btn">
<input type="radio" name="gender" id="Female" />
<label for="Female">Female</label>
</div>
</div>
</body>
</html>
@import url("https://fonts.googleapis.com/css2?family=Poppins&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.btn {
width: 100px;
height: 40px;
display: flex;
align-items: center;
margin-top: 1.2em;
padding: 0 0.5em;
}
.btn input {
position: relative;
cursor: pointer;
appearance: none;
-webkit-appearance: none;
}
.btn input::before,
.btn input::after {
content: "";
position: absolute;
width: 5px;
height: 5px;
border-radius: 50px;
}
.btn input:checked::before {
background: #ca4444;
transform: translate(-50%, -50%);
}
.btn input::after {
width: 10px;
height: 10px;
background: none;
border: 2px solid black;
border-radius: 50px;
transform: translate(-80%, -50%);
transition: all 0.4s;
}
.btn input:checked::after {
width: 100px;
height: 40px;
border-radius: 10px;
transform: translate(-15%, -50%);
z-index: 10;
}
.btn label {
margin-left: 0.5em;
cursor: pointer;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.