Most demos need a newer browser

They use :has() and container queries. Update your browser, or on an iPhone update iOS to 16.4 or later.

CSS Split Button Menu

A split button built with two native buttons and a popover menu. Anchor positioning places the menu under the arrow with no JavaScript required.

Level
Intermediate
Published
Updated
Reading time
5 min

Try it

1 live demo

Your browser can't run this demo

It needs :has(), color-mix(), popover and anchor positioning, which this browser doesn't support yet. It works in Chrome 125+, Edge 125+, Firefox 147+ and Safari 27+.

Needs :has(), color-mix(), popover and anchor positioning

One main action, more behind the arrow

Build it

2 snippets to copy

CSS Split Button Menu

HTML

<div class="sb-group">
  <button class="sb-main" type="button">Publish</button>
  <button class="sb-toggle" type="button" popovertarget="sb-menu"
          aria-label="More publish options">
    <svg class="sb-chevron" viewBox="0 0 12 12" aria-hidden="true">
      <path fill="currentColor" d="M6 8.5 1.5 4h9z"/>
    </svg>
  </button>
  <div class="sb-menu" id="sb-menu" popover>
    <button class="sb-item" type="button" popovertarget="sb-menu"
            popovertargetaction="hide">Schedule for later</button>
    <button class="sb-item" type="button" popovertarget="sb-menu"
            popovertargetaction="hide">Save as draft</button>
  </div>
</div>

CSS

.sb-group {
  display: inline-flex;
}

.sb-main,
.sb-toggle {
  border: 0;
  font-weight: 600;
  color: #16210a;
  background: #b8ff57;
  cursor: pointer;
  transition: background-color .15s, box-shadow .15s;
}

/* each half answers on its own */
.sb-main:hover,
.sb-toggle:hover {
  background: #93cc46;
}

/* pressed, and the toggle held down while its menu is open */
.sb-main:active,
.sb-toggle:active,
.sb-toggle:has(+ :popover-open) {
  background: #78a639;
  box-shadow: inset 0 2px 5px rgb(0 0 0 / .35);
}

.sb-main:focus-visible,
.sb-toggle:focus-visible {
  outline: 2px solid #f0f0f0;
  outline-offset: 2px;
}

.sb-main {
  padding: .6rem 1rem;
  border-radius: 10px 0 0 10px;
}

.sb-toggle {
  display: grid;
  place-items: center;
  padding: .6rem;
  margin-left: 1px;
  border-radius: 0 10px 10px 0;
  anchor-name: --sb-toggle;
}

.sb-chevron {
  width: 12px;
  height: 12px;
  transition: rotate .2s;
}

/* the toggle sits right before the popover,
   so this reads the popover's state */
.sb-toggle:has(+ :popover-open) .sb-chevron {
  rotate: 180deg;
}

.sb-menu {
  padding: .3rem;
  border: 1px solid #2a2a2d;
  border-radius: 10px;
  color: #f0f0f0;
  background: #141415;
}

/* Without anchor positioning a popover opens in the
   middle of the screen, which still works. */
@supports (anchor-name: --sb-toggle) {
  .sb-menu {
    position-anchor: --sb-toggle;
    inset: auto;
    top: anchor(bottom);
    right: anchor(right);
    margin: .35rem 0 0;
  }
}

.sb-item {
  display: block;
  width: 100%;
  padding: .4rem .75rem;
  border: 0;
  border-radius: 6px;
  text-align: left;
  color: inherit;
  background: none;
  cursor: pointer;
}

.sb-item:hover {
  background: #2a2a2d;
}

Understand it

How it works and 7 properties

The split button pattern makes one action the immediate default and puts the alternatives behind a second, smaller control. The left button holds the primary action; a click on the arrow opens a menu. The two share a visual group so they read as related, but they are separate HTML elements and activate different things.

The menu here is a native popover, so the browser handles open, close, light dismiss, and the Escape key with no script. Anchor positioning then places the menu directly under the arrow button behind a @supports guard, so the layout works even in browsers that do not yet support the positioning API.

How it works

Clicking the arrow button fires popovertarget, which opens the popover div with the matching id. Each menu item has popovertargetaction="hide" pointing back at the same popover, so selecting an item closes the menu. Where the browser supports anchor positioning, top: anchor(bottom) and right: anchor(right) drop the menu under the toggle's bottom edge and align its right side to the toggle's right side.

The popover API gives the menu several behaviors that would otherwise need script. The element appears in the browser's top layer, above the document's normal stacking contexts, so ancestor overflow: hidden or z-index cannot clip or bury it. Light dismiss is built in: clicking anywhere outside the menu closes it. Escape closes it too.

Without anchor positioning, the browser's own [popover] style uses position: fixed; inset: 0; margin: auto, which centers the menu in the viewport. The @supports (anchor-name: --sb-toggle) guard then overrides that: inset: auto clears the centering, top: anchor(bottom) pins the top of the menu to the bottom of the toggle, and right: anchor(right) lines the right edges up. The menu hangs to the left under the arrow button, not centered under the whole group.

The open animation is not in the copyable snippet. It sets opacity: 0 and translate: 0 -4px as the closed state, then opacity: 1; translate: 0 0 when :popover-open matches. allow-discrete on display and overlay keeps the element rendered and in the top layer while the closing transition plays out.

The menu items are plain <button> elements inside the popover. Focus moves through them with Tab in DOM order. Arrow key navigation is not built in and would require script. The browser handles focus and activation natively.

Accessibility notes

The main action and the toggle are two separate buttons, which is the correct structure for a split button. The toggle has an aria-label naming its purpose, because its only visible content is a small chevron icon.

When the popover opens, focus does not move to the menu automatically. A keyboard user pressing Tab from the toggle lands on the first menu item, following DOM order. The popover follows the toggle in source, and top-layer placement does not change the reading order.

Mistakes worth avoiding

  • Inserting any element between the toggle and the popover in the HTML. The chevron flip depends on .sb-toggle:has(+ :popover-open), which requires the two to be adjacent siblings in the DOM.
  • Shipping to browsers below Chrome 114, Firefox 125, or Safari 17 without a fallback. Without popover support, the browser ignores the popover attribute and the copyable CSS leaves the menu visible on screen.
  • Expecting the menu to center under the group. right: anchor(right) aligns the menu's right edge to the toggle's right edge, so the menu hangs left under the arrow. Different alignment needs a different inset combination.
  • Leaving menu items as non-actions. Each item needs a link, a form submission, or a script handler. The items in this demo are placeholders.

Ship it

4 features in 4 browsers, 5 questions

Browser support

Feature Chrome Firefox Safari Edge
popover11412517114
anchor positioning12514727125
:has()10512115.4105
@starting-style11712917.5117

Popover support starts at Chrome 114, Firefox 125, and Safari 17. Anchor positioning (Chrome 125, Firefox 147, Safari 27) is an enhancement on top; without it the menu opens centered in the viewport and still works. @starting-style (Chrome 117, Firefox 129, Safari 17.5) and :has() (Chrome 105, Firefox 121, Safari 15.4) govern the animation and the chevron flip; both degrade to a static state.

What you can build with it

  • Form submission with alternatives. Publish as the default, with options to schedule, save as draft, or preview behind the arrow.
  • File downloads. One-click download for the most common format; less common formats sit in the menu out of the way.
  • Email or message sending. Send is the one-click default; scheduling, forwarding, or reply-all sit in the menu one step behind.
  • Version control actions. A development workflow where Commit is one click; push, stash, and amend need a second step.

Frequently asked questions

What is a split button?
A split button puts a primary action on the left part of a button group and a smaller control on the right that opens a menu of related options. The two halves share visual styling but are separate buttons, so the primary action is one click and the alternatives are one more click away.
How does the HTML popover API work?
Adding popover to an element registers it as a popover. A button with popovertarget pointing at its id opens and closes it. The browser handles light dismiss (clicking outside closes it) and the Escape key, with no JavaScript.
Why does my popover menu open in the middle of the screen?
That is the browser's default popover style: position: fixed; inset: 0; margin: auto centers it in the viewport. Anchor positioning overrides those values to place the menu relative to a specific element. The @supports guard in this demo adds the anchor rules only where the browser supports them.
How do I flip an arrow when a popover is open?
:has(+ :popover-open) on the toggle matches when its adjacent sibling is in the open state.
Does this work without JavaScript?
Yes. The popover API is browser-native. The toggle's popovertarget opens the menu and each item's popovertargetaction="hide" closes it.