THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

W3.CSS Dropdowns


Dropdown Hover

The w3-dropdown-hover class defines an hoverable dropdown element.

The w3-dropdown-content class defines the dropdown part to be displayed.

Example

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

Try it Yourself »

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

In the previous example the hoverable part was a <button>, and the dropdown part a <div>.

In the next example the hoverable part is a <p> element, and the dropdown part is a <span>:

Example

<div class="w3-dropdown-hover">
  <p>Hover Me!
  <span class="w3-dropdown-content w3-border">
    <a href="#">Link 1</a>
    <a href="#">Link 2</a>
    <a href="#">Link 3</a>
  </div>
</div>

Try it Yourself »


Menu Dropdown

The w3-dropdown-hover class is perfect for dropdown navigation menus.

You will learn more about navigation bars in the next chapter.

Example

<ul class="w3-navbar w3-card-2 w3-light-grey">
  <li><a href="#">Home</a></li>
  <li><a href="#">Link 1</a></li>
  <li class="w3-dropdown-hover">
    <a href="#">Dropdown <i class="fa fa-caret-down"></i></a>
    <div class="w3-dropdown-content w3-white w3-card-4">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </li>
</ul>
Try It Yourself »

Clickable Dropdown

The w3-dropdown-click class is similar to w3-dropdown-hover, except that the dropdown is opened by JavaScript.

Example

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

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

Try it Yourself »


Image Dropdowns

Move the mouse over the image:

Monterosso

Norway

Example

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

Try it Yourself »


Card Dropdowns

Move the mouse over "London":

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 13 million inhabitants.

Tokyo Paris

Example

<div class="w3-dropdown-hover">London
  <div class="w3-dropdown-content w3-card-4" style="width:250px">
    <img src="img_london.png" 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>
Tokyo Paris

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-btn">Click Me</button>
  <div id="Demo" class="w3-dropdown-content w3-animate-zoom">
    <a href="#">Link 1</a>
    <a href="#">Link 2</a>
    <a href="#">Link 3</a>
  </div>
</div>

Try it Yourself »