CSS on/off button

by Jayson Buquia

HTML

<input type="checkbox" id="switch">
<label for="switch"></label>

SCSS

#switch {
    display: none; 
    
    &:checked + label {
       background: #9f9;
            
       &:before {
           background: #9f9;
           left: 20px;
       }
       &:after {
           color: #0a0; 
           content: 'on'
       }
            
    }
    
}

label[for="switch"] {
    display: inline-block;
    background: #eee;
    position: relative;
    width: 50px;
    height: 20px;
    border-radius: 9999px;
    margin-top: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: inset 2px 2px 6px rgba(0,0,0,0.1);
    font-family: sans-serif;
    
    &:before {
        content: '';
        display: inline-block;
        background: #ddd;
        position: absolute;
        top: -5px;
        left: 0;
        width: 30px;
        height: 30px;
        border-radius: 999999px;
        transition: inherit;
        box-shadow: 2px 2px 8px rgba(0,0,0,0.2),
                    inset 0 -1px 7px rgba(0,0,0,0.2);
        
    }   
        
    &:after {
        content: 'off';
        display: inline-block;        
        position: absolute;
        left: 110%;
        color: #aaa;
        transition: inherit;
        text-shadow: inset 1px 1px 1px rgba(0,0,0,0.5);
            
    }  
}