Live Preview
Ready Ln 1, Col 1
UTF-8 HTML/JS

Neumorphic Toggle Switch with HTML & CSS | Stylish Light & Dark Mode Switch

If you’re looking to add a clean, modern toggle switch to your website interface, this tutorial is for you. In this post, you’ll learn how to create a neumorphic-style toggle switch using only HTML and CSS—with no JavaScript required.

This switch design blends subtle shadows, gradients, and smooth transitions, making it perfect for modern UIs like dark/light mode toggles or setting switches.


What Is a Toggle Switch?

A toggle switch is a user interface element that allows users to switch between two states, typically on and off. It’s commonly used for preferences, settings, and features such as:

  • Dark mode toggling

  • Notifications on/off

  • Privacy options

  • Control panels

In this case, the switch uses a visual padlock-style button that slides from one side to the other when toggled.


How This Toggle Works

This toggle switch is made up of three core elements:

  1. Hidden Checkbox Input
    The checkbox acts as the actual interactive input. It’s hidden from the UI and used to detect the on/off state.

  2. Visual Indicators
    There are two indicators (left and right) that change style depending on whether the switch is on or off. These indicators include smooth gradients and shadows, making them look sleek and three-dimensional.

  3. Sliding Button
    The main switch button slides between the two sides when toggled. It includes highlights, inner shadows, and gradient layers to enhance depth and create a neumorphism effect.


Key Features

✦ Pure CSS, No JavaScript

This toggle switch is built using just HTML and CSS, keeping your project lightweight and fast.

✦ Neumorphic Design

The style follows the neumorphism trend, giving the switch a soft, embossed appearance. It uses:

  • Inset shadows

  • Gradient backgrounds

  • Rounded corners

This gives it a tactile and modern appearance that looks great on all screen sizes.

✦ CSS Variables

Custom properties like --hue, --width, and --duration make it easy to adjust:

  • Color themes

  • Size

  • Animation speed

These variables make the switch reusable and easy to maintain in your projects.

✦ Smooth Transitions

The transition effects use a cubic-bezier curve (cubic-bezier(1, 0, 1, 1)) to create a smooth snapping animation that mimics real-world switch mechanics.


How to Use This Toggle in Your Project

You can use this toggle switch for many purposes:

  • As a light/dark mode toggle

  • As a settings switch for user preferences

  • As a feature activation toggle (e.g., enable comments, enable sound)

Simply include the provided HTML and CSS code in your project, and customize the colors or dimensions using the CSS variables.


Why This Toggle Is Great for UI/UX

This component enhances user experience by providing:

  • Clear visual feedback

  • Smooth motion that feels intuitive

  • Modern styling that matches today’s design trends

Whether you’re building a personal portfolio or a professional web app, this toggle will fit right in and elevate your interface.


Conclusion

This neumorphic toggle switch made with HTML and CSS is both beautiful and functional. With easy customization, smooth animation, and no JavaScript required, it’s a perfect fit for any modern web interface. Add it to your next project and provide your users with an engaging and stylish experience.

This code uses HTML and CSS only — no JavaScript included.

MIT License

Copyright – 2025 codepen.io/ykadosh/pen/jOwjmJe

Permission is freely granted to anyone who obtains a copy of this software and its accompanying documentation files (referred to as “the Software”), allowing them to use, copy, modify, merge, publish, distribute, sublicense, and even sell copies of the Software. Additionally, users are allowed to permit others to use the Software under these same terms.

It is required that the above copyright notices and this permission notice be included in all versions or significant portions of the Software.

Please note, the Software is provided “as is”, without any form of warranty—express or implied. This includes, but is not limited to, warranties of merchantability, fitness for a specific purpose, or non-infringement. Under no circumstances shall the original authors or rights holders be held responsible for any claims, damages, or other liabilities that may arise from the use of the Software, whether through legal action, negligence, or otherwise.

All code on Freeofcosts.com is reviewed before publishing. Each post includes a live code editor with real-time preview, so you can experiment and learn by doing. Most code is open-source and free to use or modify under respective licenses.

Leave a Reply

Your email address will not be published. Required fields are marked *