Here you will learn how to create a Toggle Switch with Text using CSS. Here I will discuss with you what CSS Toggle Switch is and how it can be made.
There are many tutorials on making this Toggle button on the internet but here you will find some extras. I will discuss the issues that arise when creating Toggle Switch HTML CSS. With that, I have shared all the source code here.
But don’t worry if you are a beginner. I have shared with you the complete step-by-step tutorial on making this CSS Toggle Switch with Text.
In the meantime, I have shared a tutorial that will help you to know how to integrate this Toggle Switch with your project.
CSS Toggle Switch with Text
This type of HTML Toggle Switch is created using HTML checkboxes. Here too I used the checkbox and then designed it by CSS.
See the Pen
Gender Toggle Button by Shantanu Jana (@shantanu-jana)
on CodePen.
As you can see, an area was first created on the webpage. Which will basically serve as the background of the checkbox button.
Then there is a small button on it. In general design, the button moves from left to right when you click on that checkbox. However, in the case of this design, the position of the button does not change.
It is on the left and will be on the left after you click. However, some other changes can be seen here. Basically, this button will select either male or female.
How To Create a Toggle Switch with Text
I used HTML CSS to create this. No JavaScript or external links are used here. Now is the time to learn step-by-step how I created Toggle Switch with Text. For this, you must have an idea about HTML CSS.
Under normal circumstances, when you open this Toggle Switch with Text, the text “male” will appear. When you click on it, that text will change to “female” text. Some changes can be seen through the animation.
HTML code of Toggle Switch with Text
I have created the basic structure of this Toggle Switch using the following HTML code. Below are all the HTML codes required for this project.
First I created a check box using input. Then the button is created and two texts are added at the end.
The basic design of Toggle Switch
Now some amount of CSS has been used and more of this project has been designed. First I designed the webpage.
Here a light blue color is used in the background of the webpage. Even when an area has been created in which this Toggle Switch can be seen.
Now I have designed the background of that button. As we have seen there is a small area in which the buttons and text can be seen. This button uses background width: 243px, height: 90px and background color white.
Design the button inside the switch
Now a small toggle button has been created in the area of that switch. In general design, the button changes position from left to right and from right to left.
However, in this case, the position will not change. Button width: 90px, height: 90px and border-radius: 50% are used for rounding.
You need to design the text in this CSS Toggle Switch. Under normal circumstances, only “male” text can be seen. The text above will be hidden. Left: -115px has been used to hide the above text.
Activate Toggle Switch using CSS
Here’s a look at some of the changes you’ll make when you click on that button. I have added all the information for this using “: checked”.
This is a simple Toggle Switch with Text design yet I have shared step-by-step tutorials here. I hope you do not have any difficulty in understanding. Many may not be able to combine these codes together. For them, I have provided a download button below.
Please comment on how you like this Toggle Switch with Text design. I have already designed many more types of Toggle Switch CSS. Please let me know any questions or comments that you have.