Hey everyone. Welcome to today’s tutorial. In today’s tutorial, we will learn how to create a coffee mug toggle. To build this toggle switch, we need HTML and CSS. We will be customizing and styling a checkbox to create this toggle.
I have a whole playlist on ‘how to create a customized checkbox with HTML and CSS’. You can check out this playlist here.
Video Tutorial:
If you are interested in learning by watching a video tutorial rather than reading this blog post, you can check out the video down below. Also, subscribe to my youtube channel where I post new tips, tricks and tutorials every alternate day. So don’t forget to subscribe to get access to these amazing resources.
Project Folder Structure:
Before we start coding, let us create the project folder structure. We create a folder structure with the name – “Coffee Toggle”. Inside this folder, we have two files – index.html and style.css. The first file is the HTML document. The second file is the stylesheet.
HTML:
We begin with the HTML code. First, copy the code below and paste it into your HTML document.
The HTML code creates the elements necessary to create the structure of our toggle.
In our case, the HTML code consists of a div with a class name container. Inside this div, we have an input element with the type=”checkbox”. We then create a label for the attribute corresponding to the id of the checkbox.
CSS:
Next, we style these elements to make them look like the coffee toggle. For this, copy the code below and paste it into your stylesheet. The checkbox input creates the checkbox container. To create the coffee mug, we use the ‘label’ element. We use the ‘before pseudo-class’ of the ‘label element’ to create the handle for the mug.
That’s it for this tutorial. If you face any issues while creating this tutorial, you can download the source code by clicking on the ‘Download Code’ button below. Also, I would love to hear from you guys, so if you have any queries, suggestions, or feedback, comment below.
Happy Coding.