All effectsClick & switch

Split Action Button

分体按钮与备选操作

A primary action runs immediately, while an adjacent trigger reveals alternatives.

Run the primary action, then choose an alternative

Where to use it

Pair a frequent action with related export, save, or send variants. Make the default action explicit on the main half and keep its variants one step away on the arrow half.

Practical example

A diagram editor puts “Export PNG” on the main button and “Export SVG” and “Export PDF” under its arrow. Clicking the label exports PNG immediately, and clicking the arrow opens the format list.

AI prompt

Build a split action button for [task]. Give the primary action and the menu trigger separate accessible names and states. Close on selection, Escape, and outside click, then restore focus to the trigger when appropriate.

Example code

Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.

View HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Split Action Button</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .ui { width: min(100%, 238px); display: grid; gap: 8px; position: relative; font-size: 12px; line-height: 1.35; }
    .ui .surface { min-width: 0; border: 1px solid #676591; border-radius: 10px; background: #282744; padding: 8px; }
    .ui .bar { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
    .ui .actions { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 5px; }
    .ui .muted { color: #cecae9; font-size: 11px; }
    .ui .center { text-align: center; }
    .ui .mono { font: 11px ui-monospace, monospace; font-variant-numeric: tabular-nums; }
    .ui p { margin: 0; }
    .ui .button { min-height: 30px; padding: 4px 7px; border-radius: 7px; border: 1px solid #79779f; background: #3d3a60; color: #f9f5ff; font-size: 11px; font-weight: 650; cursor: pointer; }
    .ui .button:hover { background: #4e4976; }
    .ui .primary { background: #c5eeec; border-color: #dafaee; color: #17213b; }
    .ui .primary:hover { background: #e3fff9; }
    .ui .button:disabled { opacity: .6; cursor: default; }
    .ui .field { min-width: 0; width: 100%; border: 1px solid #79779f; border-radius: 6px; background: #1b1a31; color: #faf5ff; padding: 5px 7px; font-size: 12px; }
    .ui .field::placeholder { color: #c2bcdd; }
    .ui input[type="range"] { accent-color: #b8ebe0; width: 100%; min-width: 0; margin: 0; }
    .ui button { font: inherit; }
    .ui [hidden] { display: none !important; }
    .ui progress { accent-color: #b8ebe0; }
    @media (prefers-reduced-motion: reduce) {
      .ui *, .ui *::after, .ui *::before { transition-duration: 0s !important; animation-duration: 0s !important; scroll-behavior: auto !important; }
    }
    .ui{min-height:131px;align-content:start;padding-top:7px}.split-action{display:flex;width:max-content;justify-self:center;position:relative}.run{border-radius:7px 0 0 7px!important}.toggle{border-radius:0 7px 7px 0!important;margin-left:-1px}.formats{position:absolute;min-width:128px;right:0;top:34px;z-index:1;display:grid;gap:4px;padding:4px!important}.formats button{text-align:left;min-height:25px!important}
  </style>
</head>
<body>
  <main class="demo">
    <div class="ui"><div class="split-action"><button class="button primary run" type="button">Export PDF</button><button class="button toggle" type="button" aria-expanded="false" aria-haspopup="menu" aria-controls="formats" aria-label="Other formats">▾</button><div class="surface formats" id="formats" role="menu" hidden><button class="button" type="button" role="menuitem">Export SVG</button><button class="button" type="button" role="menuitem">Export PNG</button></div></div><p class="muted center" role="status">Choose export format</p></div>
  </main>
  <script>
    const wrap = document.querySelector('.split-action');
    const trigger = wrap.querySelector('.toggle');
    const menu = wrap.querySelector('.formats');
    const items = [...menu.querySelectorAll('button')];
    function toggle(open, focus = true) { menu.hidden = !open; trigger.setAttribute('aria-expanded', String(open)); if (focus) (open ? items[0] : trigger).focus(); }
    trigger.addEventListener('click', () => toggle(menu.hidden));
    trigger.addEventListener('keydown', (event) => { if (event.key === 'ArrowDown') { event.preventDefault(); toggle(true); } });
    wrap.addEventListener('click', (event) => { const choice = event.target.closest('.run,[role=menuitem]'); if (choice) { document.querySelector('[role=status]').textContent = choice.textContent; if (!menu.hidden) toggle(false); } });
    menu.addEventListener('keydown', (event) => {
      const current = items.indexOf(document.activeElement);
      if (event.key === 'Escape') { event.preventDefault(); toggle(false); }
      if (event.key === 'Tab') toggle(false, false);
      if (event.key === 'ArrowDown' || event.key === 'ArrowUp') { event.preventDefault(); items[(current + items.length + (event.key === 'ArrowDown' ? 1 : -1)) % items.length].focus(); }
    });
    document.addEventListener('click', (event) => { if (!menu.hidden && !wrap.contains(event.target)) toggle(false, false); });
  </script>
</body>
</html>

Original example by UI Skills

Further examples