Skip to content
Related Articles
Open in App
Not now

Related Articles

How to make checkbox visible when hover or select the element?

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 31 Jan, 2020
Improve Article
Save Article

The problem here is how to make a checkbox visible only when:

  1. It is hovered over
  2. Selected

The checkbox shouldn’t be visible when not selected. It only becomes visible when hovered over again.
The solution to the problem is simple. We can use the opacity property of the checkbox element and manipulate that. Just change the opacity value of the checkbox to 1 when the checkbox element is hovered over or when it is selected, using CSS. The default value of opacity should be 0.


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
            border:2px solid black;
        .cardcheckbox {
        opacity: 0;
        .cardcheckbox:checked {
            opacity: 1;
    <div id="box">
            <input type="checkbox"


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!