Clone Project

CSS only dark mode toggle with the :has() selector

Created by
WebBae
Similar Projects
Oops! Something went wrong while submitting the form.

0 Comments

Be the first to leave a comment.
Loading
User is typing...
No Name
Set
4 years ago
Moderator
This is the actual comment. It's can be long or short. And must contain only text information.
(Edited)
No Name
Set
2 years ago
Moderator
This is the actual comment. It's can be long or short. And must contain only text information.
(Edited)
Load More
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Load More
Description:  
AI Description

This component allows users to toggle between dark mode and light mode using only HTML and CSS, leveraging the new :has() selector. It is designed to work across all major browsers, including Firefox, which added support in December 2023.

Key Features:

  • Utilizes the CSS :has() selector for theme toggling without JavaScript.
  • Includes a checkbox input to control the theme switch.
  • Custom styles for dark and light modes defined using CSS variables.

Design Elements:

  • Toggle switch styled with a rounded background and a circular knob that moves when toggled.
  • Color scheme changes based on the selected theme, with defined CSS variables for primary colors and text.
  • Responsive design elements that adapt to various screen sizes.

Potential Use Cases:

  • Web applications that require user-friendly theme switching.
  • E-commerce sites looking to enhance user experience with dark mode options.
  • Personal blogs or portfolios that want to offer customizable viewing options.

Conclusion: This component provides a straightforward and efficient way to implement a dark mode toggle, making it a valuable addition for developers aiming to enhance user experience on their websites.

Description from Webflow:  
The CSS :has() selector can be used to toggle dark mode, light mode, and themes with zero Javascript, just HTML and CSS. :has() finally arrived in all major browsers, having dropped in Firefox December 2023.
Tags from Webflow: 
css,  darkmode,  darktheme,  toggle,  darkmodetoggle,  customcode,  lightdarkmodetoggle,  lightmodetoggle,  togglebutton,  toggleswitch,  checkbox
.