Does anyone know how make a toggle switch like the YouTube AutoPlay one that has the "play" and "pause" icon on its on/off state on the knob?
I have the following for a regular switch but not sure how to change the knob background dynamically?
.label {
position: relative;
width: 90px;
height: 36px;
}
input {
transform: scale(0);
}
.background {
position: absolute;
left: 0;
height: 100%;
width: 100%;
border-radius: 20px;
background: #6b6d6f;
transition: background 0.4s;
}
.knob {
position: absolute;
top: 2px;
left: 2px;
width: 32px;
height: 32px;
border-radius: 50%;
background: #f7f7f7;
transition: transform 0.4s;
}
input:checked + .background {
background: blue;
}
input:checked + .background .knob {
transform: translateX(52px);
}
<label class="label">
<input type="checkbox" />
<span class="background">
<span class="knob"></span>
</span>
</label>

