Posts

Showing posts with the label Dark mode

Dark Theme Switcher with Bootstrap 5.3

Image
  A few years ago I posted an article on how to make a CSS theme switcher using CSS and I had a post on how to switch modes when using TailWinds.   With Bootstrap 5.3 there is a quick and easy way to change the application theme from light to dark and vice versa. You can still use the CSS method and it does give you more flexibility, but you have to do all the CSS styling yourself. In the CSS model, you would dynamically change the overall style sheet.  While with the Tailwinds solution, you had to set a dark attribute on the elements to control the theme. In Bootstrap 5.3 and beyond, you just use a new data attribute on the body element in App.razor:                <body data-bs-theme:"dark"> With Bootstrap, you have to use JavaScript to do the actual switching of the data attribute. These are the parts you have to implement to have just switch the dark mode on and off:      1. Service to handle the state...

Light Mode and Dark Mode

Image
  Many of today’s websites provide the option to view a website in either a light mode or a dark mode. While other websites honor the system default to decide to use light mode or dark mode. Personally, I think a website should just use the system default. I can understand that a user might want to view your website in dark mode, or maybe they just want to view it in a different mode just once. If you prefer system default or allow the user to set the mode,   it is a nice feature to allow the user to switch to either dark or light mode. With Tailwind, this is a straightforward process.   How it works To implement the light-dark mode switch feature, a user simply clicks on a switch that selects which mode they want: Implementation There are five steps that must be implemented in other to support this feature.  1. In the TailwindCss configuration set the dark Mode under the Export modules to class. If this is not defined Tailwinds will use the system defau...