AnimationsButtonsTutorials

Animated Toggle Buttons

Animated Toggle Buttons

Animated Toggle Buttons

Before We Start to Animated Toggle Buttons

Animated Toggle Buttons can be used to animate Forms, Buttons, etc. and create user attractive UI components.

So if you are a person who wishes to develop a website, you have to know how to create animations properly. Check out our tutorial and you can learn this techniques and use it on your web development. Below sections shows how to develop this animations.

How to create? We are here to solve your problem. In this article we discuss how to create a hover effect animations. Before we start please read the below articles which easier you to understand the process, if you are new to development.

Step 1 – Add HTML

It’s too easy and simple. Just copy and paste below code in your HTML editor between <body> </body> tag as below.

<body>
<div class="ondisplay">

        <section title="Slide One">
            <!-- Slide One Start -->
            <div class="slideOne">
                <input type="checkbox" value="None" id="slideOne" name="check" checked />
                <label for="slideOne"></label>
            </div>
            <!-- Slide One End -->
        </section>

        <section title="Slide Two">
            <!-- Slide Two Start -->
            <div class="slideTwo">
                <input type="checkbox" value="None" id="slideTwo" name="check" checked />
                <label for="slideTwo"></label>
            </div>
            <!-- Slide Two End -->
        </section>

        <section title="Slide Three">
            <!-- Slide Three Start -->
            <div class="slideThree">
                <input type="checkbox" value="None" id="slideThree" name="check" checked />
                <label for="slideThree"></label>
            </div>
            <!-- Slide Thr Endee -->
        </section>

        <section title="Rounded One">
            <!-- Rounded One Start -->
            <div class="roundedOne">
                <input type="checkbox" value="None" id="roundedOne" name="check" checked />
                <label for="roundedOne"></label>
            </div>
            <!-- Rounded One End -->
        </section>

        <section title="Rounded Two">
            <!-- Rounded Two Start -->
            <div class="roundedTwo">
                <input type="checkbox" value="None" id="roundedTwo" name="check" checked />
                <label for="roundedTwo"></label>
            </div>
            <!-- Rounded Two End -->
        </section>

        <section title="Squared One">
            <!-- Squared One Start -->
            <div class="squaredOne">
                <input type="checkbox" value="None" id="squaredOne" name="check" checked />
                <label for="squaredOne"></label>
            </div>
            <!-- Squared One End -->
        </section>

        <section title="Squared Two">
            <!-- Squared Two Start -->
            <div class="squaredTwo">
                <input type="checkbox" value="None" id="squaredTwo" name="check" checked />
                <label for="squaredTwo"></label>
            </div>
            <!-- Squared Two End -->
        </section>

        <section title="Squared Three">
            <!-- Squared Three Start -->
            <div class="squaredThree">
                <input type="checkbox" value="None" id="squaredThree" name="check" checked />
                <label for="squaredThree"></label>
            </div>
            <!-- Squared Three End -->
        </section>

        <section title="Squared Four">
            <!-- Squared Four Start -->
            <div class="squaredFour">
                <input type="checkbox" value="None" id="squaredFour" name="check" checked />
                <label for="squaredFour"></label>
            </div>
            <!-- Squared Four End -->
        </section>

    </div>
</body>

Step 2 – Add CSS

Copy and paste below code in your HTML editor between <style></style> tag as below.

<style>
        body {
            background: #22714e;
            font-weight: 300;
        }

        body .ondisplay {
            text-align: center;
            padding: 20px 0;
        }

        body .ondisplay section {
            width: 100px;
            height: 100px;
            background: #555;
            display: inline-block;
            position: relative;
            text-align: center;
            margin-top: 5px;
            border: 1px solid gray;
            border-radius: 5px;
            box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
        }

        body .ondisplay section:after {
            content: attr(title);
            position: absolute;
            width: 100%;
            left: 0;
            bottom: 3px;
            color: #fff;
            font-size: 12px;
            font-weight: 400;
            -webkit-font-smoothing: antialiased;
            text-shadow: 0px 1px #000;
        }

        /* Slide One Start */
        .slideOne {
            width: 50px;
            height: 10px;
            background: #333;
            margin: 20px auto;
            position: relative;
            border-radius: 50px;
            box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5), 0px 1px 0px rgba(255, 255, 255, 0.2);
        }

        .slideOne label {
            display: block;
            width: 16px;
            height: 16px;
            position: absolute;
            top: -3px;
            left: -3px;
            cursor: pointer;
            background: #fcfff4;
            background: linear-gradient(to bottom, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
            border-radius: 50px;
            box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.3);
            transition: all 0.4s ease;
        }

        .slideOne input[type=checkbox] {
            visibility: hidden;
        }

        .slideOne input[type=checkbox]:checked+label {
            left: 37px;
        }

        /* Slide One End */

        /* Slide Two Start */
        .slideTwo {
            width: 80px;
            height: 30px;
            background: #333;
            margin: 20px auto;
            position: relative;
            border-radius: 50px;
            box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5), 0px 1px 0px rgba(255, 255, 255, 0.2);
        }

        .slideTwo:after {
            content: '';
            position: absolute;
            top: 14px;
            left: 14px;
            height: 2px;
            width: 52px;
            background: #111;
            border-radius: 50px;
            box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5), 0px 1px 0px rgba(255, 255, 255, 0.2);
        }

        .slideTwo label {
            display: block;
            width: 22px;
            height: 22px;
            cursor: pointer;
            position: absolute;
            top: 4px;
            z-index: 1;
            left: 4px;
            background: #fcfff4;
            border-radius: 50px;
            transition: all 0.4s ease;
            box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.3);
            background: linear-gradient(to bottom, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
        }

        .slideTwo label:after {
            content: '';
            width: 10px;
            height: 10px;
            position: absolute;
            top: 6px;
            left: 6px;
            background: #333;
            border-radius: 50px;
            box-shadow: inset 0px 1px 1px black, 0px 1px 0px rgba(255, 255, 255, 0.9);
        }

        .slideTwo input[type=checkbox] {
            visibility: hidden;
        }

        .slideTwo input[type=checkbox]:checked+label {
            left: 54px;
        }

        .slideTwo input[type=checkbox]:checked+label:after {
            background: #27ae60;
        }

        /* Slide Two End */

        /* Slide Three Start */
        .slideThree {
            width: 80px;
            height: 26px;
            background: #333;
            margin: 20px auto;
            position: relative;
            border-radius: 50px;
            box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5), 0px 1px 0px rgba(255, 255, 255, 0.2);
        }

        .slideThree:after {
            content: 'OFF';
            color: #000;
            position: absolute;
            right: 10px;
            z-index: 0;
            font: 12px/26px Arial, sans-serif;
            font-weight: bold;
            text-shadow: 1px 1px 0px rgba(255, 255, 255, 0.15);
        }

        .slideThree:before {
            content: 'ON';
            color: #27ae60;
            position: absolute;
            left: 10px;
            z-index: 0;
            font: 12px/26px Arial, sans-serif;
            font-weight: bold;
        }

        .slideThree label {
            display: block;
            width: 34px;
            height: 20px;
            cursor: pointer;
            position: absolute;
            top: 3px;
            left: 3px;
            z-index: 1;
            background: #fcfff4;
            background: linear-gradient(to bottom, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
            border-radius: 50px;
            transition: all 0.4s ease;
            box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.3);
        }

        .slideThree input[type=checkbox] {
            visibility: hidden;
        }

        .slideThree input[type=checkbox]:checked+label {
            left: 43px;
        }

        /* Slide Three End */

        /* Rounded One Start */
        .roundedOne {
            width: 28px;
            height: 28px;
            position: relative;
            margin: 20px auto;
            background: #fcfff4;
            background: linear-gradient(to bottom, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
            border-radius: 50px;
            box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
        }

        .roundedOne label {
            width: 20px;
            height: 20px;
            cursor: pointer;
            position: absolute;
            left: 4px;
            top: 4px;
            background: linear-gradient(to bottom, #222222 0%, #45484d 100%);
            border-radius: 50px;
            box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5), 0px 1px 0px white;
        }

        .roundedOne label:after {
            content: '';
            width: 16px;
            height: 16px;
            position: absolute;
            top: 2px;
            left: 2px;
            background: #27ae60;
            background: linear-gradient(to bottom, #3fe786 0%, #26ff82 100%);
            opacity: 0;
            border-radius: 50px;
            box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
        }

        .roundedOne label:hover::after {
            opacity: 0.3;
        }

        .roundedOne input[type=checkbox] {
            visibility: hidden;
        }

        .roundedOne input[type=checkbox]:checked+label:after {
            opacity: 1;
        }

        /* Rounded One End */

        /* Rounded Two Start */
        .roundedTwo {
            width: 28px;
            height: 28px;
            position: relative;
            margin: 20px auto;
            background: #fcfff4;
            background: linear-gradient(to bottom, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
            border-radius: 50px;
            box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
        }

        .roundedTwo label {
            width: 20px;
            height: 20px;
            position: absolute;
            top: 4px;
            left: 4px;
            cursor: pointer;
            background: linear-gradient(to bottom, #222222 0%, #45484d 100%);
            border-radius: 50px;
            box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5), 0px 1px 0px white;
        }

        .roundedTwo label:after {
            content: '';
            width: 10px;
            height: 5px;
            position: absolute;
            top: 6px;
            left: 5px;
            border: 3px solid #fcfff4;
            border-top: none;
            border-right: none;
            background: transparent;
            opacity: 0;
            transform: rotate(-45deg);
        }

        .roundedTwo label:hover::after {
            opacity: 0.3;
        }

        .roundedTwo input[type=checkbox] {
            visibility: hidden;
        }

        .roundedTwo input[type=checkbox]:checked+label:after {
            opacity: 1;
        }

        /* Rounded Two End */

        /* Squared One Start */
        .squaredOne {
            width: 28px;
            height: 28px;
            position: relative;
            margin: 20px auto;
            background: #fcfff4;
            background: linear-gradient(to bottom, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
            box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
        }

        .squaredOne label {
            width: 20px;
            height: 20px;
            position: absolute;
            top: 4px;
            left: 4px;
            cursor: pointer;
            background: linear-gradient(to bottom, #222222 0%, #45484d 100%);
            box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5), 0px 1px 0px white;
        }

        .squaredOne label:after {
            content: '';
            width: 16px;
            height: 16px;
            position: absolute;
            top: 2px;
            left: 2px;
            background: #27ae60;
            background: linear-gradient(to bottom, #3fe786 0%, #26ff82 100%);
            box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
            opacity: 0;
        }

        .squaredOne label:hover::after {
            opacity: 0.3;
        }

        .squaredOne input[type=checkbox] {
            visibility: hidden;
        }

        .squaredOne input[type=checkbox]:checked+label:after {
            opacity: 1;
        }

        /* Squared One End */

        /* Squared Two Start */
        .squaredTwo {
            width: 28px;
            height: 28px;
            position: relative;
            margin: 20px auto;
            background: #fcfff4;
            background: linear-gradient(to bottom, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
            box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
        }

        .squaredTwo label {
            width: 20px;
            height: 20px;
            cursor: pointer;
            position: absolute;
            left: 4px;
            top: 4px;
            background: linear-gradient(to bottom, #222222 0%, #45484d 100%);
            box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5), 0px 1px 0px white;
        }

        .squaredTwo label:after {
            content: '';
            width: 10px;
            height: 5px;
            position: absolute;
            top: 6px;
            left: 5px;
            border: 3px solid #fcfff4;
            border-top: none;
            border-right: none;
            background: transparent;
            opacity: 0;
            transform: rotate(-45deg);
        }

        .squaredTwo label:hover::after {
            opacity: 0.3;
        }

        .squaredTwo input[type=checkbox] {
            visibility: hidden;
        }

        .squaredTwo input[type=checkbox]:checked+label:after {
            opacity: 1;
        }

        /* Squared Two End */

        /* Squared Three Start */
        .squaredThree {
            width: 20px;
            position: relative;
            margin: 20px auto;
        }

        .squaredThree label {
            width: 20px;
            height: 20px;
            cursor: pointer;
            position: absolute;
            top: 0;
            left: 0;
            background: linear-gradient(to bottom, #222222 0%, #45484d 100%);
            border-radius: 4px;
            box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5), 0px 1px 0px rgba(255, 255, 255, 0.4);
        }

        .squaredThree label:after {
            content: '';
            width: 10px;
            height: 5px;
            position: absolute;
            top: 6px;
            left: 5px;
            border: 3px solid #fcfff4;
            border-top: none;
            border-right: none;
            background: transparent;
            opacity: 0;
            transform: rotate(-45deg);
        }

        .squaredThree label:hover::after {
            opacity: 0.3;
        }

        .squaredThree input[type=checkbox] {
            visibility: hidden;
        }

        .squaredThree input[type=checkbox]:checked+label:after {
            opacity: 1;
        }

        /* Squared Three End */

        /* Squared Four Start */
        .squaredFour {
            width: 20px;
            position: relative;
            margin: 20px auto;
        }

        .squaredFour label {
            width: 20px;
            height: 20px;
            cursor: pointer;
            position: absolute;
            top: 0;
            left: 0;
            background: #fcfff4;
            background: linear-gradient(to bottom, #fcfff4 0%, #dfe5d7 40%, #b3bead 100%);
            border-radius: 4px;
            box-shadow: inset 0px 1px 1px white, 0px 1px 3px rgba(0, 0, 0, 0.5);
        }

        .squaredFour label:after {
            content: '';
            width: 10px;
            height: 5px;
            position: absolute;
            top: 6px;
            left: 5px;
            border: 3px solid #333;
            border-top: none;
            border-right: none;
            background: transparent;
            opacity: 0;
            transform: rotate(-45deg);
        }

        .squaredFour label:hover::after {
            opacity: 0.5;
        }

        .squaredFour input[type=checkbox] {
            visibility: hidden;
        }

        .squaredFour input[type=checkbox]:checked+label:after {
            opacity: 1;
        }

        /* Squared Four End */

        * {
            box-sizing: border-box;
        }
    </style>

At the end we will have something like this. You can change fonts, colors, backgrounds and all things that you want. Enjoy it.

Step 3 – Add JavaScript

We use some external JS to this code. No need to worry about this, copy and paste below code to the bottom of <body></body> tag. Before </body> closing tag.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/jquery-3.7.1.js"></script>

Copy and paste below code in your HTML editor between <script></script> tag.

<script>
        // This jquery used for presentation only. Not required to work the radio buttons.
        $(document).ready(function() {
            // Commenting out the variable below will be hide the border
            var $on = "section";
            $($on).css({
                background: "none",
                border: "none",
                "box-shadow": "none"
            });
        });
    </script>

Out Put

Video Tutorial

Please watch this video to better understand this tutorial and don’t forget to subscribe to our channel.


Help others to find out about this article on Social Media sites. If you have any doubt or any problem, don’t hesitate to contact us. Thereafter we will be able to help you and also make sure you bookmark our site on your browser.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button