A modern-day front-end developer is almost always expected to be able to implement User interfaces (UIs) into working code with a pixel-perfect standard. Over time there have been various CSS libraries that help us achieve this standard more efficiently and require much less code.
In this article, we would be paying attention to Bulma, a free, open-source CSS library that enables frontend developers to style their markup code, and how we can implement a dark mode feature with it.
As mentioned earlier, Bulma is a CSS library built to help frontend developers better style their markup code and build responsive web layouts not only by providing utility classes that can be used on your frontend project for various effects but also by providing ready-to-use frontend components.
For more information on Bulma and how to get started, click here
Although there is no required knowledge to get started with Bulma, there are a few things you should be expected to already know to follow along smoothly which include:
Now we’ve been able to familiarize ourselves with what Bulma is and why we love and use it so much, let’s dive into how we can implement dark mode using Bulma using. To get started, first we need to:
For us to utilize the features of Bulma in our project, we have to install Bulma and set up our project file directory. There are various methods to install Bulma and get started which are:
For the sake of this article, we shall be downloading Bulma's official compiled file and embedding it in our project directory.
In the image above you will notice our Bulma file in our assets folder. Then we will import Bulma into our HTML file.
To learn more about other installation options for Bulma click here
Now that we have Bulma available to us in our project, the next step is customizing each theme using Bulma’s Saas variables. Although this process is beginner-friendly, knowledge of Saas will be required for easy follow-along.
If you are unfamiliar with the sass installation process, you can find out more here
From the piece of code above you will notice we now have access to Bulma’s global variables and are updating them with our custom brand colors. We have also added some styling for both light and dark themes which is being distinguished by a .dark class.
Congratulations, you have made it this far. At this point, we have both themes ready. We will be adding a button to toggle the themes once clicked using JavaScript.
If everything is done right, you should achieve a similar experience to this
Congrats! You have made it to the end and I hope you were able to learn this awesome feature with Bulma. Take it up as a challenge and explore other wonderful features that come with Bulma and perhaps do something even more awesome with it.
You can find the complete code for this on GitHub
The live demo can also be found here