Utilities✨ Premium

Share Buttons

Round buttons that really share: X, Facebook, LinkedIn and WhatsApp links pre-filled with the address and title, the phone's share sheet, link copy.

CSSHoverSocial

Updated

This effect is part of Effect.Labs — 840 vanilla effects, some free, some premium. Utilities has 43 effects, including 3 free. Explore the category →

3 usage examples

"Challenge your friends" under a quiz score — Share Buttons example 1

① "Challenge your friends" under a quiz score

WhenThe player finishes a volcano quiz with 8/10; under the score, the row of buttons offers to send the challenge, with a message already written: "I got 8/10 on the Volcanoes of Europe quiz, your turn!".
WhyThe proud moment is the moment people share. The link points to a challenge page for that score, not to the result screen's address, thanks to data-shb-url.
Settingsdata-shb-url="https://strevinque.quiz/defi/volcans-8-10", data-shb-title = the challenge sentence, --shb-size: 46px, --shb-gap: 12px, demo frame set to zero. In the capture, the scene clicks "Copy link" every 2.6 s and lends the capture browser a clipboard (it has none).
Vertical share bar in the margin of a long read — Share Buttons example 2

② Vertical share bar in the margin of a long read

WhenWhile reading a long piece about a lighthouse, the column of small buttons stays in the left margin; the reader copies the link to send it to a friend.
WhyIn a column, the buttons use an empty margin instead of breaking the text; the label opens to the right, towards the article, without covering the next button.
Settingsshb-col class on the root, --shb-size: 36px, --shb-gap: 9px, column aligned left in a 160 px margin. "Copy link" clicked by the scene every 3.3 s in the capture.
Spreading the word about an audiobook on release day — Share Buttons example 3

③ Spreading the word about an audiobook on release day

WhenOn an audiobook's launch page, under the cover, the title and the excerpt to listen to, the buttons fill the bottom of the block with the call "Spread the word".
WhyHere sharing is the point of the page: the buttons are the main action, larger and tinted in the publisher's colours, without borrowing the networks' colours.
Settings--shb-size: 54px, --shb-gap: 9px, --shb-bg: linear-gradient(135deg, #0f766e, #4338ca), left-aligned. Link copy clicked every 2.6 s in the capture.

How it works

The four round buttons are real <a> links that open in a new tab. On load, the script writes their href from the address to share (data-shb-url on the root, otherwise the page's <link rel="canonical">, otherwise its address) and its title (data-shb-title, otherwise the page title), encoded: x.com/intent/tweet?url=…&text=…, facebook.com/sharer/sharer.php?u=…, linkedin.com/sharing/share-offsite/?url=…, wa.me/?text=…. The data-shb="email" value also gives a mailto: link.

The fifth button depends on the browser. If it knows navigator.share (Safari, Chrome on Android and recent desktop Chrome), "Share…" opens the system share sheet, with every app on the device. Otherwise, "Copy link" puts the address in the clipboard (execCommand('copy') fallback if the API is missing) and the label shows "Link copied" for 2.5 s, or "Copy blocked".

On hover and on keyboard focus alike, the button rises 8 px and grows 15 % with a small bounce (0.3 s), and its label (data-tip) appears above it. The buttons carry initials (X, Fb, In, Wa) on a neutral indigo gradient: no logo, no brand colour. The shb-col class on the root stacks them in a column, label on the right.

Each .fx-0740-root works on its own. The fx0740:share event (detail.via: x, facebook, native, copy…, detail.url) leaves the root on every share, for your analytics.

Accessibility

  • Names: each button has a full aria-label ("Share on LinkedIn", "Copy link"); the initials and icons are hidden from screen readers. Links announce "link"; "Share…" or "Copy link", depending on the browser, announces "button".
  • Label on focus: the label shows on keyboard focus (:focus-visible), not only on hover, with a lavender ring. In Safari on Mac, Tab only stops on links and buttons with the system keyboard option (otherwise Option + Tab).
  • Copy announced: "Link copied" or "Copy blocked" is read by the role="status" area.
  • New tab: links open a tab (target="_blank"); if many of your visitors use screen readers, add "(new tab)" at the end of the aria-labels.
  • Reduced motion: no jump or growth; the label appears in place, without sliding.

Browser compatibility

HTML links and 4.8 KB of commented, dependency-free JavaScript. Measured in Chromium 151, Firefox 153 and WebKit 26.5 (Playwright): code pasted twice, correct links in each copy, a click on Facebook that does open the share tab with the encoded address, link copy, blocked copy, label visible on keyboard focus, touch at 390 px, reduced motion, 0 errors. WebKit offers "Share…"; the test Chromium and Firefox, with no share sheet, show "Copy link".

Chrome 86+✓ Full (measured); "Share…" from Chrome 128
Firefox 85+✓ Full (measured), with "Copy link"
Safari 15.4+✓ Full (measured in WebKit), with "Share…"
Edge 93+✓ Full (Chromium engine), with "Share…"
Mobile iOS 15.4+✓ WebKit engine, not checked on a device
Android Chrome 86+✓ System share sheet (touch measured)

Without JavaScript, the links have no address and go nowhere: write the full hrefs in the HTML in that case. navigator.share exists in Safari 12.1, Chrome Android 61, Edge 93 and desktop Chrome 128 (before, only on Windows and ChromeOS); desktop Firefox does not have it. The label on focus needs :focus-visible (Chrome 86, Firefox 85, Safari 15.4).

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0740-root" data-shb-url="https://example.com/article" data-shb-title="…" data-shb-copied="Link copied" data-shb-failed="Copy blocked">
  <div class="shb-demo">
    <a class="shb-btn" data-shb="x" data-tip="X" aria-label="Share on X" target="_blank" rel="noopener noreferrer"><span class="shb-mono" aria-hidden="true">X</span></a>
    <a class="shb-btn" data-shb="facebook" data-tip="Facebook" aria-label="Share on Facebook" …><span class="shb-mono" aria-hidden="true">Fb</span></a>
    <a class="shb-btn" data-shb="linkedin" data-tip="LinkedIn" aria-label="Share on LinkedIn" …>…</a>
    <a class="shb-btn" data-shb="whatsapp" data-tip="WhatsApp" aria-label="Share on WhatsApp" …>…</a>
    <button type="button" class="shb-btn shb-native" data-tip="Share…" aria-label="Share…" hidden><svg aria-hidden="true">…</svg></button>
    <button type="button" class="shb-btn shb-copy" data-tip="Copy link" aria-label="Copy link"><svg aria-hidden="true">…</svg></button>
  </div>
  <span class="shb-status" role="status" aria-live="polite"></span>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Shared address (HTML — data-shb-url on the root) the canonical link, otherwise the page address Share a specific page (challenge, product) or an address without tracking parameters.
Shared title (HTML — data-shb-title) the page title Text used by X and WhatsApp, and email subject for data-shb="email".
Networks (HTML — data-shb on each <a class="shb-btn">) x, facebook, linkedin, whatsapp Remove a link, change the order, or add email; the initials and data-tip are edited in the HTML.
Copy texts (HTML — data-shb-copied, data-shb-failed) "Link copied" · "Copy blocked" Shown in the button's label and announced to screen readers.
Size and spacing (CSS — --shb-size, --shb-gap) 50 px · 15 px The initials follow the size (30 % of the diameter).
Button background (CSS — --shb-bg) linear-gradient(135deg, #4f46e5, #7c3aed) A colour or gradient from your brand; keep at least 4.5:1 with the white initials.
Layout (HTML — shb-col class on the root) in a row Stacks the buttons; the label opens to the right.
Frame (CSS — --shb-height, --shb-page, --shb-panel, --shb-pad) 300 px · #0a0a0f · #1a1a2e · 20 px 0 and transparent to place the row in your own layout.

FAQ

The networks' logos and colours are trademarks, with their own usage rules. Neutral initials fit any site; you can put your own icon in place of the <span class="shb-mono">, the aria-label keeps the spoken name.
Yes if your browser has no share sheet: desktop Firefox, or Chrome before version 128 outside Windows. The "Copy link" button then shows in its place. On phones, "Share…" is almost always there.
With no setting, the script takes the page's canonical link if there is one, otherwise the displayed address, parameters included. Add a <link rel="canonical"> or put the clean address in data-shb-url.