I assumed it is a radio button that’s made to look like a toggle
You're right (at least to think of using radio buttons), these are two input
s of type radio
with an associated label
for each one that are (the label
s) styled using CSS
.
To be short, here's a live demo of the end result :
.wrapper {
display: flex;
padding: 4px;
background-color: #24ef43;
}
.custom-input {
flex-grow: 1;
}
.custom-input input[type=radio] {
display: none;
}
.custom-input label {
display: block;
padding: 6px 8px;
color: #fff;
font-weight: bold;
text-align: center;
transition : all .4s 0s ease;
}
.custom-input input[type=radio]:checked + label {
background-color: #f5f5f5;
color: #000;
border-radius: 4px;
}
<div class="wrapper">
<div class="custom-input">
<input type="radio" id="female" name="gender">
<label for="female">Female</label>
</div>
<div class="custom-input">
<input type="radio" id="male" name="gender">
<label for="male">Male</label>
</div>
</div>
Disclaimer: I tried to be as short as possible in my answer, also wanted to put the OP on the track thus I didn't use any best practices or patterns nor give attention to accessibility in the code above. Also, I didn't make any clarifications about the code being used so it up to the OP to ask for any further assistance and am glad to provide some help.