<div class="toggle-container">
        <input type="checkbox" id="toggle" name="toggle">
        <label for="toggle"></label>
    </div>

    <h1>Long Live Rock 'n Roll</h1>
       <p>Rock and Roll ain't noise pollution! Rock and Roll will never die! I like that old time Rock and Roll!</p>
*{
    box-sizing: border-box;
}

body{
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;

    min-height: 100vh;
    flex-direction: column;
    padding: 5rem;
    transition: background 0.4s linear, color 0.4s linear;
    font-size: 2rem;
}

body.dark{
    background: #201e1e;
    color: white;
}

label{
    user-select: none;
    cursor: pointer;
    background-color: #201e1e;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: inline-block;
    transition: background 0.4s linear;
}

body.dark label{
    background-color: #ffff;
}

.toggle-container{
    position: fixed;
    top: 10px;
    right:10px
}

input{
    visibility: hidden;
}
const toggle = document.getElementById("toggle")


toggle.addEventListener('change', (e)=>{
document.body.classList.toggle('dark',e.target.checked)

}) 

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.