Coding classic

html, css, javascript, react, python

Animated Checkbox using css and html

This blog post is all about crafting your own CSS for checkboxes, adding animation flair with HTML and CSS. In the fast-paced realm of web design, user experience holds significant sway, drawing and keeping audience interest intact. Creatives and developers are always on the lookout for fresh approaches to spruce up UIs, and one standout is the animated custom checkbox, increasingly lauded for its UX-boosting prowess.

Let’s take a step back and revisit the basic checkbox before we dive into the details of customizing it with animation. Checkboxes, in their traditional form, serve as straightforward tools for binary choices on web forms. Foundational to web design, they empower users to select options or indicate preferences with ease. As web design progresses, user expectations evolve accordingly. This leads to the emergence of custom checkboxes with animation, injecting a modern twist that turns the ordinary checkbox into an attractive and interactive feature.

What is a styled Checkbox?

A styled checkbox differs from the standard one by its tailored appearance, tailored to fit the website or app’s aesthetics. Unlike default browser checkboxes, custom ones grant designers the liberty to tweak their look, ensuring they blend seamlessly with the design scheme.

These custom checkboxes usually come to life through HTML, CSS, and JavaScript. They enable designers to play around with shapes, colors, and animations, fostering a more unified and branded user journey.

Introducing animation to custom checkboxes elevates the user experience, going beyond just aesthetics. It introduces interactivity, making the interface more immersive and pleasurable for users.

Various animations, such as transitions, fades, and transforms, are commonly applied to custom checkboxes. For example, a gentle fade-in when a box is checked or a seamless transition between checked and unchecked states can greatly enhance visual appeal. These animations aren’t merely decorative; they enhance user interaction, making it smoother and more intuitive.

HTML CODE (index.html) with explanation using comment.

<!DOCTYPE html>
<html lang="en">

<head>
    <!-- Meta tag specifying character encoding -->
    <meta charset="UTF-8">
    <!-- Meta tag ensuring compatibility with Internet Explorer -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Meta tag setting viewport properties for responsive design -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Title of the webpage -->
    <title>Animated Checkbox</title>
    <!-- Link to an external stylesheet for additional styling -->
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <!-- Label wrapping the checkbox input and its text -->
    <label>
        <!-- Checkbox input element -->
        <input type="checkbox">
        <!-- Empty span element used for custom checkbox styling -->
        <span class="input-check"></span>
        <!-- Text displayed next to the checkbox -->
        Checkbox
    </label>
</body>

</html>

this HTML code sets up a basic webpage with checkbox. It includes meta tags for specifying character encoding, ensuring compatibility, and setting viewport properties for responsiveness. The title of the webpage is defined, and an external stylesheet (“style.css”) is linked for additional styling. Within the body, a label wraps a checkbox input and its accompanying text.

CSS code (style.css) with explanation using comment.

/* Importing the Google Fonts stylesheet for the 'Poppins' font with weight 600 */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@600&display=swap');

/* Global reset and styling */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Setting the default font family to 'Poppins', sans-serif */
    font-family: 'Poppins', sans-serif;
}

/* Styling for the body */
body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #150707; /* Setting background color */
}

/* Styling for the label */
label {
    position: relative;
    font-size: 25px;
    color: #2de918; /* Setting text color */
    cursor: pointer;
}

/* Styling for the checkbox input */
label input {
    position: absolute;
    opacity: 0; /* Hiding the checkbox input */
}

/* Styling for the custom checkbox */
.input-check {
    position: relative;
    display: inline-block;
    top: 5px;
    width: 30px;
    height: 30px;
    border: 2px solid #ccc; /* Setting border color */
    border-radius: 4px; /* Adding border radius */
    margin-right: 5px;
    transition: .5s; /* Adding transition effect */
}

/* Styling for the custom checkbox when checked */
label input:checked~.input-check {
    background: #07ce14; /* Changing background color */
    border-color: #04af07; /* Changing border color */
    animation: animate .7s ease; /* Applying animation */
}

/* Keyframes for the animation */
@keyframes animate {
    0% {
        transform: scale(1); /* Initial scale */
    }
    /* Adding animation keyframes for scale */
}

/* Styling for the checkmark inside the custom checkbox */
.input-check::before {
    content: ''; /* Adding empty content */
    position: absolute;
    top: 6px;
    left: 4px;
    width: 15px;
    height: 6px;
    border-bottom: 4px solid #fff; /* Styling checkmark */
    border-left: 4px solid #fff; /* Styling checkmark */
    transform: scale(0) rotate(-45deg); /* Initial transformation */
    transition: .5s; /* Adding transition effect */
}

/* Styling for the checkmark when the custom checkbox is checked */
label input:checked~.input-check::before {
    transform: scale(1) rotate(-45deg); /* Transforming the checkmark */
}

conclusion

Investing effort in crafting visually appealing and interactive checkboxes merges design with functionality, elevating the user experience. Designers who dedicate time to these details contribute to interfaces that are more engaging and memorable. In the ever-evolving landscape of web design, such nuanced elements will become even more vital in distinguishing interfaces and leaving lasting impressions on users. Embrace the opportunity to experiment with custom checkboxes and animation – your users will appreciate the effort.

Animated Checkbox using css and html

Leave a Reply

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

Scroll to top