Social Share Buttons

A set of 9 animated social share buttons (clipboard, mail, Facebook, Pinterest, WhatsApp, Reddit, LinkedIn, X, Telegram) driven by data attributes. Hovering one button scales down siblings using CSS :has(). Each platform opens a pre-built share URL; clipboard uses the Async Clipboard API.

socialshareclipboardcssjavascripthoveranimation

Code

index.html
html
<div data-social-share data-social-share-link="https://example.com" data-social-share-title="Check this out">

  <button data-social-share-type="clipboard">
    <!-- clipboard icon -->
    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
      <path stroke-linecap="round" stroke-linejoin="round" d="M15.666 3.888A2.25 2.25 0 0 0 13.5 2.25h-3c-1.03 0-1.9.693-2.166 1.638m7.332 0c.055.194.084.4.084.612v0a.75.75 0 0 1-.75.75H9a.75.75 0 0 1-.75-.75v0c0-.212.03-.418.084-.612m7.332 0c.646.049 1.288.11 1.927.184 1.1.128 1.907 1.077 1.907 2.185V19.5a2.25 2.25 0 0 1-2.25 2.25H6.75A2.25 2.25 0 0 1 4.5 19.5V6.257c0-1.108.806-2.057 1.907-2.185a48.208 48.208 0 0 1 1.927-.184" />
    </svg>
  </button>

  <button data-social-share-type="mail">
    <!-- mail icon -->
    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
      <path stroke-linecap="round" stroke-linejoin="round" d="M21.75 6.75v10.5a2.25 2.25 0 0 1-2.25 2.25h-15a2.25 2.25 0 0 1-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0 0 19.5 4.5h-15a2.25 2.25 0 0 0-2.25 2.25m19.5 0v.243a2.25 2.25 0 0 1-1.07 1.916l-7.5 4.615a2.25 2.25 0 0 1-2.36 0L3.32 8.91a2.25 2.25 0 0 1-1.07-1.916V6.75" />
    </svg>
  </button>

  <button data-social-share-type="facebook">
    <!-- facebook icon -->
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
      <path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z" />
    </svg>
  </button>

  <button data-social-share-type="pinterest">
    <!-- pinterest icon -->
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
      <path d="M12 0C5.373 0 0 5.373 0 12c0 5.084 3.163 9.426 7.627 11.174-.105-.949-.2-2.405.042-3.441.218-.937 1.407-5.965 1.407-5.965s-.359-.719-.359-1.782c0-1.668.967-2.914 2.171-2.914 1.023 0 1.518.769 1.518 1.69 0 1.029-.655 2.568-.994 3.995-.283 1.194.599 2.169 1.777 2.169 2.133 0 3.772-2.249 3.772-5.495 0-2.873-2.064-4.882-5.012-4.882-3.414 0-5.418 2.561-5.418 5.207 0 1.031.397 2.138.893 2.738a.36.36 0 0 1 .083.345l-.333 1.36c-.053.22-.174.267-.402.161-1.499-.698-2.436-2.889-2.436-4.649 0-3.785 2.75-7.262 7.929-7.262 4.163 0 7.398 2.967 7.398 6.931 0 4.136-2.607 7.464-6.227 7.464-1.216 0-2.359-.632-2.75-1.378l-.748 2.853c-.271 1.043-1.002 2.35-1.492 3.146C9.57 23.812 10.763 24 12 24c6.627 0 12-5.373 12-12S18.627 0 12 0z" />
    </svg>
  </button>

  <button data-social-share-type="whatsapp">
    <!-- whatsapp icon -->
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
      <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 0 1-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 0 1-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 0 1 2.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0 0 12.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 0 0 5.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 0 0-3.48-8.413Z" />
    </svg>
  </button>

  <button data-social-share-type="reddit">
    <!-- reddit icon -->
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
      <path d="M12 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0zm5.01 4.744c.688 0 1.25.561 1.25 1.249a1.25 1.25 0 0 1-2.498.056l-2.597-.547-.8 3.747c1.824.07 3.48.632 4.674 1.488.308-.309.73-.491 1.207-.491.968 0 1.754.786 1.754 1.754 0 .716-.435 1.333-1.01 1.614a3.111 3.111 0 0 1 .042.52c0 2.694-3.13 4.87-7.004 4.87-3.874 0-7.004-2.176-7.004-4.87 0-.183.015-.366.043-.534A1.748 1.748 0 0 1 4.028 12c0-.968.786-1.754 1.754-1.754.463 0 .898.196 1.207.49 1.207-.883 2.878-1.43 4.744-1.487l.885-4.182a.342.342 0 0 1 .14-.197.35.35 0 0 1 .238-.042l2.906.617a1.214 1.214 0 0 1 1.108-.701zM9.25 12C8.561 12 8 12.562 8 13.25c0 .687.561 1.248 1.25 1.248.687 0 1.248-.561 1.248-1.249 0-.688-.561-1.249-1.249-1.249zm5.5 0c-.687 0-1.248.561-1.248 1.25 0 .687.561 1.248 1.249 1.248.688 0 1.249-.561 1.249-1.249 0-.687-.562-1.249-1.25-1.249zm-5.466 3.99a.327.327 0 0 0-.231.094.33.33 0 0 0 0 .463c.842.842 2.484.913 2.961.913.477 0 2.105-.056 2.961-.913a.361.361 0 0 0 .029-.463.33.33 0 0 0-.464 0c-.547.533-1.684.73-2.512.73-.828 0-1.979-.196-2.512-.73a.326.326 0 0 0-.232-.095z" />
    </svg>
  </button>

  <button data-social-share-type="linkedin">
    <!-- linkedin icon -->
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
      <path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.062 2.062 0 0 1-2.063-2.065 2.064 2.064 0 1 1 2.063 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z" />
    </svg>
  </button>

  <button data-social-share-type="x">
    <!-- x icon -->
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
      <path d="M18.901 1.153h3.68l-8.04 9.19L24 22.846h-7.406l-5.8-7.584-6.638 7.584H.474l8.6-9.83L0 1.154h7.594l5.243 6.932ZM17.61 20.644h2.039L6.486 3.24H4.298Z" />
    </svg>
  </button>

  <button data-social-share-type="telegram">
    <!-- telegram icon -->
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
      <path d="M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z" />
    </svg>
  </button>

</div>
styles.css
css
[data-social-share] {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

[data-social-share] button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: #e5e7eb;
  color: #374151;
  transition: background 0.2s ease, color 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

[data-social-share] button svg {
  width: 1.1rem;
  height: 1.1rem;
  pointer-events: none;
}

/* Scale siblings down when hovering one button */
[data-social-share]:has(button:hover) button:not(:hover) {
  transform: scale(0.85);
  opacity: 0.5;
}

[data-social-share] button:hover {
  transform: scale(1.15);
}

/* Brand colours on hover */
[data-social-share-type="clipboard"]:hover { background: #6b7280; color: #fff; }
[data-social-share-type="mail"]:hover       { background: #ea4335; color: #fff; }
[data-social-share-type="facebook"]:hover   { background: #1877f2; color: #fff; }
[data-social-share-type="pinterest"]:hover  { background: #e60023; color: #fff; }
[data-social-share-type="whatsapp"]:hover   { background: #25d366; color: #fff; }
[data-social-share-type="reddit"]:hover     { background: #ff4500; color: #fff; }
[data-social-share-type="linkedin"]:hover   { background: #0a66c2; color: #fff; }
[data-social-share-type="x"]:hover          { background: #000;    color: #fff; }
[data-social-share-type="telegram"]:hover   { background: #0088cc; color: #fff; }

/* Clipboard success state */
[data-social-share-success] [data-social-share-type="clipboard"] {
  background: #22c55e;
  color: #fff;
}
script.js
javascript
document.querySelectorAll("[data-social-share]").forEach((container) => {
  const rawLink = container.dataset.socialShareLink || window.location.href;
  const rawTitle = container.dataset.socialShareTitle || document.title;

  const link = encodeURIComponent(rawLink);
  const title = encodeURIComponent(rawTitle);

  const urls = {
    mail:      `mailto:?subject=${title}&body=${link}`,
    facebook:  `https://www.facebook.com/sharer/sharer.php?u=${link}`,
    pinterest: `https://pinterest.com/pin/create/button/?url=${link}&description=${title}`,
    whatsapp:  `https://wa.me/?text=${title}%20${link}`,
    reddit:    `https://www.reddit.com/submit?url=${link}&title=${title}`,
    linkedin:  `https://www.linkedin.com/sharing/share-offsite/?url=${link}`,
    x:         `https://x.com/intent/tweet?url=${link}&text=${title}`,
    telegram:  `https://t.me/share/url?url=${link}&text=${title}`,
  };

  container.querySelectorAll("[data-social-share-type]").forEach((btn) => {
    const type = btn.dataset.socialShareType;

    btn.addEventListener("click", async () => {
      if (type === "clipboard") {
        try {
          await navigator.clipboard.writeText(rawLink);
          container.setAttribute("data-social-share-success", "");
          setTimeout(() => container.removeAttribute("data-social-share-success"), 2000);
        } catch (err) {
          console.error("Clipboard write failed", err);
        }
        return;
      }

      const url = urls[type];
      if (url) window.open(url, "_blank", "noopener,noreferrer,width=600,height=500");
    });
  });
});

Guide

Container

Add data-social-share to the wrapper element. Set data-social-share-link to the URL you want to share (defaults to window.location.href if omitted). Set data-social-share-title to the share text or page title (defaults to document.title).

Buttons

Each button needs data-social-share-type set to one of: clipboard, mail, facebook, pinterest, whatsapp, reddit, linkedin, x, telegram. The script reads this value to build the correct share URL.

Clipboard Button

Uses the Async Clipboard API (navigator.clipboard.writeText). On success, data-social-share-success is temporarily added to the container for 2 seconds — use it to show visual feedback. The attribute is removed automatically.

Group Hover Effect

The CSS :has() selector scales down all non-hovered buttons when one is hovered, creating a focus effect. The hovered button scales up to 1.15× while siblings scale down to 0.85× with reduced opacity.

Brand Colours

Each platform button gets its brand background and white icon on hover via attribute selectors. Customise or remove these rules to match your design.

Share Window

All non-clipboard platforms open in a small popup (600×500px) with noopener and noreferrer for security. The mail type opens the default email client via a mailto: URI.