DEV Community

Vikram Ramanujam
Vikram Ramanujam

Posted on • Edited on

4 1

Completely configurable, flexible, re-usable CSS-only checkbox toggles

Configurable using CSS Custom properties!. Found a lot of great examples of toggles around the web, but all of them had some form of hard-coded values. Check out the code. Uses line-height and follows the natural sizing given to it. Feel free to steal :)

  <input class="switch" id="switch-55" type="checkbox"/>
  <label for="switch-55" style="
    --switch-width: 3rem; /* optional properties */
    --switch-knob-size: .8rem;
  ">Toggle</label>
/* the following properties are configurable by simply overriding them: */
:{  
  --switch-background: silver;
  --switch-background-active: mediumseagreen;
  --switch-width: 3ch;
  --switch-knob-size: calc(var(--switch-width) / 3);
  --switch-knob-offset: calc(50% - (var(--switch-knob-size) / 2));
  --switch-knob-color: white;
  --switch-transition-duration: 0.3s;
}

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

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

Okay