:root { /* style */ --switch-width: 48px; --switch-height: 24px; --switch-padding: 3px; /* animation */ --switch-animation-duration: 0.2s; } .switch { display: flex; flex-shrink: 0; align-items: center; width: 48px; width: var(--switch-width); height: 24px; height: var(--switch-height); border-radius: 50em; padding: 3px 0; padding: var(--switch-padding) 0; position: absolute; top: 65px; right: 20px; @include respond-to('m-large') { position:relative; top: unset; right: unset; } } .switch-input, .switch-label { position: absolute; left: 0; top: 0; } .switch-input { margin: 0; padding: 0; opacity: 0; height: 0; width: 0; pointer-events: none; } .switch-input:checked + .switch-label { background-color: hsl(228, 74%, 61%); background-color: var(--color-primary); } .switch-input:checked + .switch-label + .switch-marker { left: calc(100% - 29px); left: calc(100% - var(--switch-height) + var(--switch-padding)); } .switch-input:focus + .switch-label, .switch-input:active + .switch-label { --color-shadow: hsla(228, 74%, 61%, 0.2); box-shadow: undefined; box-shadow: 0 0 0 3px var(--color-shadow); } .switch-input:focus + .switch-label, .switch-input:active + .switch-label { box-shadow: 0 0 0 3px hsla(228, 74%, 61%, 0.2); box-shadow: 0 0 0 3px var(--color-shadow); } .switch-label { width: 100%; height: 100%; color: transparent; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; background-color: hsl(240, 1%, 83%); background-color: var(--color-contrast-low); border-radius: inherit; z-index: 1; transition: background 0.2s; transition: background var(--switch-animation-duration); } .switch-marker { position: relative; background-color: hsl(0, 0%, 100%); background-color: var(--color-contrast-high); width: 20px; width: calc(var(--switch-height) - var(--switch-padding)*2); height: 20px; height: calc(var(--switch-height) - var(--switch-padding)*2); border-radius: 50%; z-index: 2; pointer-events: none; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25); left: 3px; left: var(--switch-padding); transition: left 0.2s; transition: left var(--switch-animation-duration); will-change: left; }