Skip to content

Share row

A "Share" label and a plain link to each service's own share intent, ruled off under a post's lead.

<div class="cap-share" id="share-default" role="group" aria-label="Share this page">
  <span class="cap-share-label" aria-hidden="true">Share</span>
  <a class="cap-share-link" href="https://x.com/intent/tweet?text=Spring+update&amp;url=https%3A%2F%2Fexample.com%2Fspring-update" aria-label="Share on X (opens another site)" rel="external noopener noreferrer"><svg class="cap-icon" viewBox="0 0 24 24" data-fill="" aria-hidden="true" focusable="false"><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.93zM17.61 20.64h2.04L6.49 3.24H4.3z"/></svg>X</a>
  <a class="cap-share-link" href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fexample.com%2Fspring-update" aria-label="Share on LinkedIn (opens another site)" rel="external noopener noreferrer"><svg class="cap-icon" viewBox="0 0 24 24" data-fill="" aria-hidden="true" focusable="false"><path d="M6.94 5a1.94 1.94 0 1 1-3.88 0 1.94 1.94 0 0 1 3.88 0zM3.5 8.5h3.3V21H3.5zm5.6 0h3.16v1.7h.05c.44-.83 1.5-1.7 3.1-1.7 3.32 0 3.93 2.18 3.93 5v6.5h-3.3v-5.76c0-1.37-.02-3.14-1.9-3.14-1.92 0-2.2 1.5-2.2 3.04V21H9.1z"/></svg>LinkedIn</a>
  <button type="button" class="cap-btn">Copy link</button>
</div>

Installation

// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/share-row.css";
import { shareHref } from "capsomer/behavior/share-row";

Usage

<div class="cap-share" role="group" aria-label="Share this page">
  <span class="cap-share-label" aria-hidden="true">Share</span>
  <a class="cap-share-link" href="https://x.com/intent/tweet?text=...&url=..." aria-label="Share on X" rel="external noopener"><svg aria-hidden="true">...</svg>X</a>
  <a class="cap-share-link" href="https://www.linkedin.com/sharing/share-offsite/?url=..." aria-label="Share on LinkedIn" rel="external noopener"><svg aria-hidden="true">...</svg>LinkedIn</a>
  <!-- the copy button -->
</div>

Examples

Every service (React)

<div data-mount="all"></div>

API reference

ShareRow

PropTypeRequiredDoes
urlstringYesThe page's own address and title.
titlestringYes
targetsShareTarget[]The services, in order. Default: X and LinkedIn.
labelReactNode
childrenReactNodeMore controls after the links: Capsomer's copy button for "Copy link".

Functions

FunctionSignatureDoes
shareHref(target: ShareTarget, url: string, title: string): string

Parts and data attributes

ClassIs
.cap-shareits own class
.cap-share-labelits own class
.cap-share-linkits own class
AttributeValues
data-fillpresent or absent
data-flippresent or absent
StateRead from
:hoverthe platform

Accessibility

KeyDoes
TabMoves through the services, then the copy button
EnterOpens the service's share page
  • Every link is at least --target tall and its text reaches 4.5:1 (checked in the spec).
  • Marks are aria-hidden; the names are text.