How to make a drop-down menu in HTML without using CSS

 How to make a drop-down menu in HTML without using CSS



Copy source code:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.dropbtn {
  background-color#3b0172;
  colorwhite;
  padding16px;
  font-size16px;
  bordernone;
  cursorpointer;
}

.dropbtn:hover.dropbtn:focus {
  background-color#2980B9;
}

.dropdown {
  positionrelative;
  displayinline-block;
}

.dropdown-content {
  displaynone;
  positionabsolute;
  background-color#f1f1f1;
  min-width160px;
  overflowauto;
  box-shadow0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index1;
}

.dropdown-content a {
  colorblack;
  padding12px 16px;
  text-decorationnone;
  displayblock;
}

.dropdown a:hover {background-color#ddd;}

.show {displayblock;}
</style>
</head>
<body>

<h1><center>Clickable Dropdown</center></h1>
<center><p>Click on the button to open the dropdown menu.</center></p>

<center><div class="dropdown">
  <button onclick="myFunction()" class="dropbtn">Dropdown</button>
  <div id="myDropdown" class="dropdown-content">
    <a href="https://www.youtube.com/channel/UCkC22hvj7jadyJL5_8SRUOQ">Home</a>
    <a href="https://www.youtube.com/channel/UCkC22hvj7jadyJL5_8SRUOQ/videos">Videos</a>
    <a href="https://www.youtube.com/channel/UCkC22hvj7jadyJL5_8SRUOQ/about">About</a>
  </div>
</div></center>

<script>
/* When the user clicks on the button, 
toggle between hiding and showing the dropdown content */
function myFunction() {
  document.getElementById("myDropdown").classList.toggle("show");
}

// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
  if (!event.target.matches('.dropbtn')) {
    var dropdowns = document.getElementsByClassName("dropdown-content");
    var i;
    for (i = 0i < dropdowns.lengthi++) {
      var openDropdown = dropdowns[i];
      if (openDropdown.classList.contains('show')) {
        openDropdown.classList.remove('show');
      }
    }
  }
}
</script>

</body>
</html>


Important:

Copy the above code and paste it into your HTML editor; notepad, notepad++, Visual Studio Code, etc. Then save it with ".html" format.