Components

Checkbox

A control that allows the user to toggle between checked and not checked.

HTML
<div class="checkbox-container">
    <label class="checkbox" for="spam">
        <input type="checkbox" id="spam" name="spam">
        <span></span>
    </label>
    <label id="checkbox-label" for="spam">Yes! Send me regular email spam</label>
</div>
                                
CSS
.checkbox-container {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 0.7rem;
}

input[type="checkbox"] {
    display: none;
}

.checkbox span {
    width: 18px; 
    height: 18px; 
    border: 1.5px solid white; 
    background-color: transparent; 
    display: inline-block;
    border-radius: 4px;
    position: relative;
    transition: background-color 0.2s ease;
}
    
.checkbox span::after {
    content: "";
    position: absolute;
    width: 5px;
    height: 11px;
    border: solid black;
    border-width: 0 1px 1px 0;
    transform: rotate(45deg);
    left: 5px;
    opacity: 0;
    transition: opacity 0.2s ease;
}
    
input[type="checkbox"]:checked + span {
    background-color: white;
}
    
input[type="checkbox"]:checked + span::after {
    color: black;
    opacity: 1;
}

#checkbox-label {
    font-size: 1rem;
    font-weight: 300;
    color: white;
}