Skip to content

Social Share Buttons

Pure CSS social share card with brand-colored X, Facebook and LinkedIn buttons, a copy-link field with clipboard feedback and a native share fallback.

Also known as: share this article, copy link button, share card

Social Share Buttons live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

A social share card in pure CSS and vanilla JavaScript with brand-colored buttons for X, Facebook and LinkedIn, a copy-link field and an optional native share button. Place it at the end of blog posts, case studies, product pages or documentation articles.

How it works

The root aside.ssb-share carries two data attributes: data-ssb-url (the address to share) and data-ssb-text (the post text used by X and the native share sheet). Inside, .ssb-preview shows a small article teaser, ul.ssb-list holds the .ssb-link buttons and .ssb-copy-row combines a read-only .ssb-url field with a .ssb-copy button. Each button gets its brand color from a modifier such as .ssb-link--facebook, which sets the local --ssb-brand property used for the background and the colored shadow.

On DOMContentLoaded the script reads the URL (falling back to the current page address) and rebuilds the href of every link with a data-ssb-network value from the NETWORKS templates in script.js. The links already contain working share URLs in the markup, so they still work without JavaScript. Clicking .ssb-copy writes the link with the Clipboard API, falls back to document.execCommand('copy') in older or restricted browsers, and briefly switches the button to a green "Copied" state with the .is-copied class. If copying is blocked, the URL is selected so the visitor can copy it by hand. When navigator.share exists (most phones and some desktop browsers), the hidden .ssb-native button next to the copy button is revealed and opens the system share sheet.

Customization

  • data-ssb-url and data-ssb-text on .ssb-share: set the shared address and text per instance; remove data-ssb-url to share the current page.
  • --ssb-x, --ssb-facebook and --ssb-linkedin: the brand colors of the three buttons.
  • NETWORKS in script.js: add another network, for example a Reddit or email template, then add a matching .ssb-link with that data-ssb-network value.
  • grid-template-columns in .ssb-list: the buttons stack on phones and sit in three columns from 480px; use repeat(4, 1fr) after adding a fourth network.
  • --ssb-radius: corner radius of buttons and the copy field; use 999px for pill buttons.
  • --ssb-bg, --ssb-border and --ssb-accent: the card background, the dividers and the "Article" kicker color.
  • Remove .ssb-preview to keep only the buttons and the copy row.

Use cases

  • Blog posts: readers share the article to X, Facebook or LinkedIn from a card at the end
  • Case studies: a preview teaser sits above brand-colored share buttons and a copy-link field
  • Product pages: visitors copy the page address with one click and see a green copied confirmation
  • Documentation articles: phones show a native share button that opens the system share sheet

Accessibility

The card is an aside labelled by its heading. Every share link has visible text plus a visually hidden .ssb-sr note that it opens in a new tab, and decorative icons are aria-hidden. The icon-only .ssb-native button is named with aria-label. The URL field has a hidden label. .ssb-status is a role="status" live region that announces the copy result. Links and buttons show a 3px :focus-visible outline in --ssb-focus, and hover lift effects are disabled with prefers-reduced-motion: reduce.

Usage notes

Several cards can share a page; each one uses its own data attributes. The Clipboard API needs a secure context (HTTPS), which is why the fallback exists.

Social Share Buttons at a glance

Framework
Pure CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
None
Layout
Responsive, works on mobile
Category
Social Buttons
License
Free for personal and commercial use

Questions about this template

Can I use the Social Share Buttons code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Social Share Buttons – free Pure CSS social button template
Social Share Buttons · free Pure CSS social button template

More Social Buttons

Social Login Buttons – free Tailwind CSS social button template

Social Login Buttons

Dark Tailwind CSS social login buttons for Google, Apple and GitHub with full-width and icon-only variants and a loading spinner state.

Sticky Social Share Sidebar – free Tailwind CSS social button template

Sticky Social Share Sidebar

Tailwind CSS article layout with a sticky vertical social share bar that turns into a fixed bottom bar on mobile, with copy link.