<div class="container">
  <h3>Toggle Me!</h3>
  <div class="checkbox-container yellow">
    <input type="checkbox" checked id="toggle" />
    <label for="toggle"></label>
    <div class="active-circle"></div>
  </div>
</div>

<div class="container">
  <h3>No! Toggle me instead!</h3>
  <div class="checkbox-container green">
    <input type="checkbox" checked id="toggle2" />
    <label for="toggle2"></label>
    <div class="active-circle"></div>
  </div>
</div>

<div class="container">
  <h3>Why not me?</h3>
  <div class="checkbox-container purple">
    <input type="checkbox" checked id="toggle3" />
    <label for="toggle3"></label>
    <div class="active-circle"></div>
  </div>
</div>

<footer>
  <p>
    Created with <i class="fa fa-heart"></i> by
    <a target="_blank" href="https://florin-pop.com">Florin Pop</a>
    - More on
    <a target="_blank" href="https://github.com/florinpop17">Github</a>
    - Follow me on
    <a target="_blank" href="https://twitter.com/florinpop1705">Twitter</a>
  </p>
</footer>
@import url('https://fonts.googleapis.com/css?family=ZCOOL+XiaoWei');


* {
  box-sizing: border-box;
}

body {
  background: #34495e;
  font-family: 'ZCOOL XiaoWei', serif;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  margin: 0;
}

.container {
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  overflow: hidden;
  text-align: center;
  width: 280px;
  height: 170px;
}

.container h3 {
  color: #111;
  margin: 0 0 25px;
  position: relative;
  z-index: 2;
}

.checkbox-container {
  display: inline-block;
  position: relative;
}

.checkbox-container label {
  background-color: #aaa;
  border: 1px solid #fff;
  border-radius: 20px;
  display: inline-block;
  position: relative;
  transition: all 0.3s ease-out;
  width: 45px;
  height: 25px;
  z-index: 2;
}

.checkbox-container label::after {
  content: ' ';
  background-color: #fff;
  border-radius: 50%;
  position: absolute;
  top: 1.5px;
  left: 1px;
  transform: translateX(0);
  transition: transform 0.3s linear;
  width: 20px;
  height: 20px;
  z-index: 3;
}

.checkbox-container input {
  visibility: hidden;
  position: absolute;
  z-index: 2;
}

.checkbox-container input:checked + label + .active-circle {
  transform: translate(-50%, -50%) scale(15);
}

.checkbox-container input:checked + label::after {
  transform: translateX(calc(100% + 0.5px));
}

.active-circle {
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(calc(-50% - 10px), calc(-50% - 2px)) scale(0);
  transition: transform 0.6s ease-out;
  width: 30px;
  height: 30px;
  z-index: 1;
}

.checkbox-container.green .active-circle,
.checkbox-container.green input:checked + label {
  background-color: #47B881;
}

.checkbox-container.yellow .active-circle,
.checkbox-container.yellow input:checked + label {
  background-color: #F7D154;
}

.checkbox-container.purple .active-circle,
.checkbox-container.purple input:checked + label {
  background-color: #735DD0;
}

@media (max-width: 840px) {
  body {
    flex-direction: column;
  }
}

footer {
    background-color: #222;
    color: #fff;
    font-size: 14px;
    bottom: 0;
    position: fixed;
    left: 0;
    right: 0;
    text-align: center;
    z-index: 999;
}

footer p {
    margin: 10px 0;
}

footer i {
    color: red;
}

footer a {
    color: #3c97bf;
    text-decoration: none;
}

External CSS

  1. https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.0/css/all.min.css

External JavaScript

This Pen doesn't use any external JavaScript resources.