CSS Share Menu Button

A share button that slides out X, LinkedIn and email links on hover or keyboard focus, no JavaScript.

  • social share
  • focus-within
  • reveal
  • links
  • hover
HTML
<div class="share-menu">
  <button class="share-menu-toggle" type="button">
    <svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><path d="m8.6 13.5 6.8 4M15.4 6.5l-6.8 4"/></svg>
    Share
  </button>
  <ul class="share-menu-list">
    <li><a href="#" aria-label="Share on X"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M18.9 1.15h3.68l-8.04 9.19L24 22.85h-7.41l-5.8-7.58-6.64 7.58H.47l8.6-9.83L0 1.15h7.59l5.24 6.93zm-1.29 19.5h2.04L6.49 3.24H4.3z"/></svg></a></li>
    <li><a href="#" aria-label="Share on LinkedIn"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M20.45 20.45h-3.56v-5.57c0-1.33-.02-3.04-1.85-3.04-1.85 0-2.14 1.45-2.14 2.94v5.67H9.35V9h3.41v1.56h.05c.48-.9 1.64-1.85 3.37-1.85 3.6 0 4.27 2.37 4.27 5.46zM5.34 7.43a2.06 2.06 0 1 1 0-4.13 2.06 2.06 0 0 1 0 4.13zM7.12 20.45H3.56V9h3.56zM22.22 0H1.77C.79 0 0 .77 0 1.73v20.54C0 23.23.79 24 1.77 24h20.45c.98 0 1.78-.77 1.78-1.73V1.73C24 .77 23.2 0 22.22 0z"/></svg></a></li>
    <li><a href="#" aria-label="Share by email"><svg class="share-menu-stroke" viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/></svg></a></li>
  </ul>
</div>
CSS
.share-menu {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.share-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border: 0;
  border-radius: 999px;
  background: #0369a1;
  color: #fff;
  font: 600 15px/1 system-ui, sans-serif;
  cursor: pointer;
}

.share-menu-toggle svg,
.share-menu-stroke {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.share-menu-list {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Hidden links stay out of the tab order until the menu opens */
.share-menu-list li {
  opacity: 0;
  visibility: hidden;
  transform: translateX(-12px) scale(0.8);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s 0.2s;
}

.share-menu:hover li,
.share-menu:focus-within li {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0s;
}

.share-menu li:nth-child(2) { transition-delay: 0.05s; }
.share-menu li:nth-child(3) { transition-delay: 0.1s; }

.share-menu-list a {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  color: #0c4a6e;
  box-shadow: 0 2px 8px #0c4a6e26;
}

.share-menu-list svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.share-menu-list a:hover {
  background: #e0f2fe;
}

.share-menu-toggle:focus-visible,
.share-menu-list a:focus-visible {
  outline: 2px solid #0369a1;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .share-menu-list li { transform: none; }
}

About this CSS Share Menu Button

This CSS Share Menu Button is 87 lines of pure CSS (1.6 KB) with no JavaScript and no dependencies. It uses transitions, transforms, box shadows and CSS Grid. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

The colors in this snippet. Search and replace them to match your brand:

  • #0369a1
  • #fff
  • #0c4a6e
  • #0c4a6e26
  • #e0f2fe

How to use this share menu button

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .share-menu class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback