Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS

W3.CSS Dropdowns

Share

Hoverable Dropdowns

Dropdowns display additional content when the user hovers over or clicks an element.

W3.CSS provides classes for both hoverable and clickable dropdowns.

The w3-dropdown-hover class creates a hoverable dropdown.

The w3-dropdown-content class defines the content that appears.

Example

<div class="w3-dropdown-hover">
  <button class="w3-button">Hover Over Me!</button>
  <div class="w3-dropdown-content w3-bar-block w3-border">
    <a href="#" class="w3-bar-item w3-button">Link 1</a>
    <a href="#" class="w3-bar-item w3-button">Link 2</a>
    <a href="#" class="w3-bar-item w3-button">Link 3</a>
  </div>
</div>

Try It Yourself »

Both the hoverable element and the dropdown content element can be any HTML element.

In the example above the hover element was a <button>, and the dropdown content a <div>.

In the next example the hover element is a <p>, and the dropdown content is a <span>:

Example

<p class="w3-dropdown-hover">Hover over me!
  <span class="w3-dropdown-content w3-green">Hello World!</span>
</p>

Try it Yourself »


Dropdown Menus

Dropdowns can be placed inside a bar to create a dropdown menu:

Home About

Example

<div class="w3-bar w3-light-grey">
  <a href="#" class="w3-bar-item w3-button">Home</a>
  <a href="#" class="w3-bar-item w3-button">About</a>
  <div class="w3-dropdown-hover">
    <button class="w3-button">Dropdown ▾</button>
    <div class="w3-dropdown-content w3-bar-block w3-card-4">
      <a href="#" class="w3-bar-item w3-button">Link 1</a>
      <a href="#" class="w3-bar-item w3-button">Link 2</a>
      <a href="#" class="w3-bar-item w3-button">Link 3</a>
    </div>
  </div>
</div>

Try It Yourself »

You will learn more about Navigation Bars later in this tutorial.



Clickable Dropdowns

The w3-dropdown-click class creates a clickable dropdown.

JavaScript is used to add or remove the w3-show class:

Example

<div class="w3-dropdown-click">
  <button onclick="myFunction()" class="w3-button">Click Me</button>
  <div id="demo" class="w3-dropdown-content w3-bar-block w3-border">
    <a href="#" class="w3-bar-item w3-button">Link 1</a>
    <a href="#" class="w3-bar-item w3-button">Link 2</a>
    <a href="#" class="w3-bar-item w3-button">Link 3</a>
  </div>
</div>

<script>
function myFunction() {
  document.getElementById("demo").classList.toggle("w3-show");
}
</script>

Try It Yourself »


Right-Aligned Dropdowns

Example

<div class="w3-flex" style="justify-content:flex-end">
  <div class="w3-dropdown-hover">
    <button class="w3-button w3-black">Dropdown</button>
    <div class="w3-dropdown-content w3-bar-block w3-border" style="right:0">
      <a href="#" class="w3-bar-item w3-button">Link 1</a>
      <a href="#" class="w3-bar-item w3-button">Link 2</a>
      <a href="#" class="w3-bar-item w3-button">Link 3</a>
    </div>
  </div>
</div>

Try It Yourself »

The w3-flex class class justify the content to the right (flex-end).

right:0 makes the dropdown content align with the right edge of the button.


What You Have Learned

In this chapter you have learned how to:

  • Create hoverable dropdowns with w3-dropdown-hover
  • Create dropdown content with w3-dropdown-content
  • Create clickable dropdowns with w3-dropdown-click
  • Use dropdowns inside bars
  • Right-align dropdowns
  • Use images, cards, and animations in dropdown content

More Examples

Explore more ways to use dropdowns.


Image Dropdown

A dropdown can display a larger version of an image:

Move the mouse over the image:

Norway
Norway

Example

<div class="w3-dropdown-hover">
  <img src="img_snowtops.jpg" alt="Norway" style="width:20%">
  <div class="w3-dropdown-content" style="width:300px">
    <img src="img_snowtops.jpg" alt="Norway" style="width:100%">
  </div>
</div>

Try it Yourself »


Card Dropdowns

Move the mouse over one of the cities below:

London
London

London is the capital city of England.

It is the most populous city in the United Kingdom, with a metropolitan area of over 9 million inhabitants.

Tokyo
Tokyo

Tokyo is the capital city of Japan.

It has 13 million inhabitants.

Example

<div class="w3-dropdown-hover">London
  <div class="w3-dropdown-content w3-card-4" style="width:300px">
    <img src="img_london.jpg" alt="London" style="width:100%">
    <div class="w3-container">
      <p>London is the capital city of England.</p>
      <p>It is the most populous city in the UK.</p>
    </div>
  </div>
</div>

Try it Yourself »


Animated Dropdown

Use any of the w3-animate- classes to fade, zoom or slide in the dropdown content:

Example

<div class="w3-dropdown-click">
  <button onclick="myFunction()" class="w3-button">Click Me</button>
  <div id="Demo" class="w3-dropdown-content w3-bar-block w3-animate-zoom">
    <a href="#" class="w3-bar-item w3-button">Link 1</a>
    <a href="#" class="w3-bar-item w3-button">Link 2</a>
    <a href="#" class="w3-bar-item w3-button">Link 3</a>
  </div>
</div>

Try it Yourself »


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.