button toggle

In this example below you will see how to do a button toggle with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by bboyguil, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright bboyguil ©
  • HTML
  • CSS
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>button toggle</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <input name="test" type="checkbox" id="test"><label class="la" for="test"></label>
  
  

</body>

</html>

/*Downloaded from https://www.codeseek.co/bboyguil/button-toggle-zRRNOv */
input{
  display:none;

}
input:checked ~ .la:after{
  left: 40px;
}
input:checked ~ .la{
  box-shadow: -5px 0 0px red inset;
}
.la{
  margin: 100px auto;
  width: 100px;
  height: 40px;
  display: block;
  background: #aaa;
  background-size: 80px;
  border-radius: 50px;
  position: relative;
  transition: all .5s;
  box-shadow: -65px 0 0px red inset;
}
.la:after{
  content: "";
  position: absolute;
  top: 0px;
  left: 0;
  display: block;
  width: 60px;
  height: 40px;
  background: teal;
  border-radius: 50px;
  transition: all .5s;
}

Comments