DEV Community

Cover image for Theme Toggler
Prashant Pandey
Prashant Pandey

Posted on

1 2

Theme Toggler

A theme change toggler.

So I was just doing some work yesturday and I think let's make a theme toggler button using a checkbox, and I found that it was pretty simple to create one.
Here I am sharing it to you.
We just need some small steps to create it,

Step1: Create a wire frame for checkbox in HTML

<input type='checkbox' id='check' />
<label for='check'></label>
Enter fullscreen mode Exit fullscreen mode

Step2: Create css for it just use some css selector properties to tackle the checked and unchecked checkbox.

body{
  top: 50%;
  left: 50%;
  position: absolute;
  background-color: #000;
}
input[type=checkbox]{
  display:none;
}
label{
  cursor: pointer;
  width: 100px;
  height: 50px;
  background: linear-gradient(to right, hsl(210, 78%, 56%), hsl(146, 68%, 55%));;
  display: block;
  border-radius: 100px;
  position: relative;

}
label::after{
  content: '';
  position: absolute;
  width: 40px;
  height: 40px;
  top: 5px;
  left: 5px;
  background-color: #fff;
  border-radius: 50%; 
  transition: all 0.5s;
  transform: translateX(0px);
}


input[type=checkbox]:checked + label::after{
    transition: all 0.5s;
    transform: translateX(50px);
    background-color: #000;
}


.dark{
  postion: absolute;
  margin-top: 34px
}

Enter fullscreen mode Exit fullscreen mode

That's it , here is the result from this little code.

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (1)

Collapse
 
w3hls profile image
John

Hello
How do I email you please?

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay