JSFiddle - React, Tailwind, and code Playground

by Sergey Linnick

HTML

<div class="switch switch--horizontal">
  <input id="radio-a" type="radio" name="first-switch" checked="checked" />
  <label for="radio-a">Off</label>
  <input id="radio-b" type="radio" name="first-switch" />
  <label for="radio-b">On</label><span class="toggle-outside"><span class="toggle-inside"></span></span>
</div>

CSS

*,
*:before,
*:after {
  box-sizing: border-box;
}

body{
  background: silver;
}



.switch {
  position: relative;
}

.switch input {
  position: absolute;
  top: 0;
  z-index: 2;
  opacity: 0;
  cursor: pointer;
}

.switch input:checked {
  z-index: 1;
}

.switch input:checked+label {
  opacity: 1;
  cursor: default;
}

.switch input:not(:checked)+label:hover {
  opacity: 0.5;
}

.switch label {
  color: #fff;
  opacity: 0.33;
  transition: opacity 0.25s ease;
  cursor: pointer;
}

.switch .toggle-outside {
  height: 100%;
  border-radius: 2rem;
  padding: 0.25rem;
  overflow: hidden;
  transition: 0.25s ease all;
}

.switch .toggle-inside {
  border-radius: 5rem;
  background: #4a4a4a;
  position: absolute;
  transition: 0.25s ease all;
}

.switch--horizontal {
  width: 18rem;
  height: 3rem;
  margin: 0 auto;
  font-size: 0;
  margin-bottom: 1rem;
}

.switch--horizontal input {
  height: 3rem;
  width: 6rem;
  left: 6rem;
  margin: 0;
}

.switch--horizontal label {
  font-size: 1.5rem;
  line-height: 3rem;
  display: inline-block;
  width: 6rem;
  height: 100%;
  margin: 0;
  text-align: center;
}

.switch--horizontal label:last-of-type {
  margin-left: 6rem;
}

.switch--horizontal .toggle-outside {
  background: #fff;
  position: absolute;
  width: 6rem;
  left: 6rem;
}

.switch--horizontal .toggle-inside {
  height: 2.5rem;
  width: 2.5rem;
}

.switch--horizontal input:checked~.toggle-outside .toggle-inside {
  left: 0.25rem;
}

.switch--horizontal input~input:checked~.toggle-outside .toggle-inside {
  left: 3.25rem;
}

.switch--vertical {
  width: 12rem;
  height: 6rem;
}

.switch--vertical input {
  height: 100%;
  width: 3rem;
  right: 0;
  margin: 0;
}

.switch--vertical label {
  font-size: 1.5rem;
  line-height: 3rem;
  display: block;
  width: 8rem;
  height: 50%;
  margin: 0;
  text-align: center;
}

.switch--vertical .toggle-outside {
  background: #fff;
  position: absolute;
  width: 3rem;
  height: 100%;
  right: 0;
  top:...