GitHub 6956★

Have you seen CSS Scan?

The fastest and easiest way to check, copy and edit CSS.

Learn more →

CSS Scan logo

Switch

The checkbox is placed inside a label. So when clicking on the label, the checkbox will be checked even though it's hidden.

HTML

<label class="switch switch--on">
<input type="checkbox" class="switch__input" />

<!-- Circle -->
<div class="switch__circle"></div>
</label>

<label class="switch switch--off">
<input type="checkbox" class="switch__input" />

<!-- Circle -->
<div class="switch__circle"></div>
</label>

CSS

.switch {
display: flex;

/* Rounded border */
border-radius: 9999px;

/* Size */
height: 2rem;
width: 4rem;

/* Demo */
margin-bottom: 0.5rem;
}

.switch__input {
/* Hide the input */
display: none;
}

.switch__circle {
/* Rounded border */
border-radius: 9999px;

/* Size */
width: 2rem;

background-color: #fff;
}

The switch comes with two variants:

/* ON status */
.switch--on {
background-color: #357edd;
border: 1px solid #357edd;

/* Push the circle to the right */
justify-content: flex-end;
}

/* OFF status */
.switch--off {
background-color: #d1d5db;
border: 1px solid #d1d5db;
}
.switch--off .switch__circle {
border: 1px solid #d1d5db;
}
Demo
Follow me on and to get more useful contents.