How to create: split button

Learn how to create a split button dropdown menu using CSS.

Split button dropdown menu

Hover over the arrow icon to open the dropdown menu:

Try it personally

How to create split buttons

Step 1 - Add HTML:

Create a dropdown menu that appears when the user hovers over the icon.

<!-- Font Awesome icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<button class="btn">Button</button>
<div class="dropdown">
  <button class="btn" style="border-left:1px solid navy">
    <i class="fa fa-caret-down"></i>
  </button>
  <div class="dropdown-content">
    <a href="#">Link 1</a>
    <a href="#">Link 2</a>
    <a href="#">Link 3</a>
  </div>
</div>

Example Explanation:

Open the dropdown menu with any element, such as <button>, <a>, or <p> elements.

Create a dropdown menu using a container element (such as <div>) and add dropdown menu links to it.

Wrap the button and another <div> element with a <div> element to use CSS for proper positioning of the dropdown menu.

Step 2 - Add CSS:

/* Dropdown menu button */
.btn {
  background-color: #2196F3;
  color: white;
  padding: 16px;
  font-size: 16px;
  border: none;
  outline: none;
}
/* Container <div> - used to position the dropdown menu content */
.dropdown {
  position: absolute;
  display: inline-block;
}
/* Dropdown menu content (default is hidden) */
.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f1f1f1;
  min-width: 160px;
  z-index: 1;
}
/* Links in the dropdown menu */
.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}
/* Change the color of the dropdown menu link when the mouse hovers */
.dropdown-content a:hover {background-color: #ddd}
/* Display the dropdown menu when the mouse hovers */
.dropdown:hover .dropdown-content {
  display: block;
}
/* Change the background color of the dropdown button when the dropdown menu content is displayed */
.btn:hover, .dropdown:hover .btn  {
  background-color: #0b7dda;
}

Try it personally

Related Pages

Tutorial:CSS Dropdown Menu

Tutorial:How to Create Clickable Dropdown Menu