How do I change this hover function to a clickable one?

The above page explains how to show a dropdown menu by hovering over a link:

.dropdown {
  position: relative;
  display: inline-block;

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  padding: 12px 16px;
  z-index: 1;

.dropdown:hover .dropdown-content {
  display: block;

<div class="dropdown">
  <span>Mouse over me</span>
  <div class="dropdown-content">
  <p>Hello World!</p>

However, I want to execute the code when it is clicked on. How do I change it? Changing hover to click doesn’t work.

1 Like

I found a clickable version here:

1 Like

Yes generally you will need JS for click actions but you can utilise the checkbox hack if you want to avoid JS.

Semantics are debatable though but a more accessible version for keyboards is to use :target instead.

JS is still probably the way to go though.