Skip to main content
Login

Sign in to access your account

Share - National Design System

A set of buttons that share a page link to X, LinkedIn, WhatsApp and other sites, through the device's share sheet, or copy it to the clipboard

Overview

Share is a .nds-share wrapper of share buttons, in a Dropmenu or in a row. Five buttons are built in: X, LinkedIn, WhatsApp, Copy Link, and Device Share, which opens the device’s own share sheet for any app on a phone. The script finds each one by its class. data-share-href adds any other target, such as Facebook or email. By default, every button shares the current page.

Pick another component when:

  • the user copies a value that is not a link, such as a reference number: Copy
  • the menu holds other actions, such as Print or Download: Dropmenu

Markup

Options
Structure
Size
Custom Target
More
Preview
<div class="nds-share nds-dropmenu"> <button class="nds-btn nds-secondary-outline nds-dropmenu-trigger" aria-label="Share Page" data-i18n-aria-label="share.share_page"> <i class="nds-icon nds-hgi-share-01" aria-hidden="true"></i> <span class="nds-label" data-i18n="share.share_page">Share Page</span> </button> <div class="nds-dropmenu-menu" hidden> <button class="nds-btn nds-subtle nds-dropmenu-item nds-share-x" type="button" aria-label="Share on X" data-i18n-aria-label="share.share_on_x"> <i class="nds-icon nds-hgi-new-twitter" aria-hidden="true"></i> <span class="nds-label">X</span> </button> <button class="nds-btn nds-subtle nds-dropmenu-item nds-share-linkedin" type="button" aria-label="Share on LinkedIn" data-i18n-aria-label="share.share_on_linkedin"> <i class="nds-icon nds-hgi-linkedin-02" aria-hidden="true"></i> <span class="nds-label">LinkedIn</span> </button> <button class="nds-btn nds-subtle nds-dropmenu-item nds-share-whatsapp" type="button" aria-label="Share on WhatsApp" data-i18n-aria-label="share.share_on_whatsapp"> <i class="nds-icon nds-hgi-whatsapp" aria-hidden="true"></i> <span class="nds-label">WhatsApp</span> </button> <button class="nds-btn nds-subtle nds-dropmenu-item nds-share-copy" type="button" aria-label="Copy Link" data-i18n-aria-label="share.copy_link" data-copy-label data-no-auto-close> <i class="nds-icon nds-hgi-link-04" aria-hidden="true"></i> <span class="nds-label" data-i18n="share.copy_link">Copy Link</span> </button> </div> </div>

Behavior

Copy Link in a Menu

data-no-auto-close on the Copy Link item keeps the menu open after the click. The item shows the checkmark for 2 seconds, then the script closes the menu. In the Inline structures, nothing closes, so the attribute is not needed.

data-share-url and data-share-title on .nds-share replace the page link and the page title. A relative link, such as /news/12, becomes a full link on the current site. A link whose scheme is not http, https, mailto or tel is ignored, and the buttons share the current page.

Device Share

.nds-share-device opens the device’s own share sheet with the link and the title. The user picks any app on the device, not only the built-in targets. The button ships with hidden, and the script shows it only where the browser has navigator.share: most phones, and Chrome and Edge on Windows. Elsewhere it stays hidden, and Copy Link still covers every app. Closing the sheet does nothing.

Custom Target

data-share-href on a button in .nds-share adds a target that the built-in buttons do not cover. It holds the target’s share link. The script replaces {url} and {title} with the encoded link and title, then opens the link in a 600×400 window. A mailto: or tel: link opens the mail or phone app instead. The Custom Target options in the builder show the links for Facebook, Telegram and email.

Built-in Features

  • Automatic Start

    One click listener on the page serves every share button, including the buttons you add later. You write no script.

  • Social Targets

    X, LinkedIn and WhatsApp open their share page in a 600×400 window. X and WhatsApp send the title with the link. LinkedIn sends the link only.

  • Copy Link Feedback

    Copy Link uses the Copy script: a checkmark for 2 seconds, the label swap and a screen reader announcement.

  • Multiple Instances

    A page can hold any number of .nds-share wrappers. Each reads its own data-share-url and data-share-title.

  • Named Menu

    The script adds .nds-share-menu to each share menu, a class to style that menu by.

Best Practices

  • Use the default, with no attributes, to share the current page, such as in the hero. It reads the link and title of each page, so no page needs its own setting.
  • Use Custom Link to share one item on a page: a news card, a search result, a file.
  • In a list, put one share in each row. Do not put a page share next to a row share.
  • Give the trigger an aria-label that names what is shared: “Share Page”, “Share Article”, “Share Report”.
  • Give every icon-only button a Tooltip: nds-tooltip, data-tooltip-hover="500" and a title with the same words as the aria-label. The label is hidden, so the tooltip shows a sighted user what the icon does.
  • Keep data-no-auto-close on the Copy Link item in a menu. Without it, the menu closes before the user sees the checkmark.
  • Keep data-copy-label on the Copy Link item, with no value. The label confirms the copy to a sighted user in the page’s language, and a screen reader says the same word.
  • Keep the nds-share-* class on each built-in button. The script finds each one by its class. Leave out a button you do not need.
  • Give a custom target an icon, a label and an aria-label, like the built-in buttons.
  • The Inline buttons take any Button style, such as nds-subtle, and size, such as nds-sm. Use one style and one size for all of them.

API

Classes

Class Element Effect
.nds-share the wrapper Holds the buttons in a row with a small gap. Add .nds-dropmenu for the Menu structure
.nds-share-x a button in .nds-share Opens the X share page with the title and the link
.nds-share-linkedin a button in .nds-share Opens the LinkedIn share page with the link
.nds-share-whatsapp a button in .nds-share Opens WhatsApp with the title and the link in one message
.nds-share-copy a button in .nds-share Copies the link and shows the checkmark
.nds-share-device a button in .nds-share Opens the device’s share sheet with the title and the link. Write it hidden: init() shows it where the browser has navigator.share
.nds-share-menu the .nds-dropmenu-menu in .nds-share The script adds it at init(). Labels in the menu stay on one line

Data Attributes

Attribute Element Effect
data-share-url .nds-share The link to share. Default: the current page. A relative link becomes a full link. A scheme other than http, https, mailto or tel falls back to the current page
data-share-title .nds-share The title that X and WhatsApp send, and that fills {title}. Default: document.title
data-share-href a button in .nds-share The share link of a custom target. The script replaces {url} and {title} with the encoded values. A scheme other than http, https, mailto or tel does nothing. An nds-share-* class on the same button wins
data-copy-label .nds-share-copy The label text while the checkmark shows. With no value: “Copied” in the page’s language. Read by Copy
data-copy-announce .nds-share-copy The text the live region announces after the copy. Default: data-copy-label, then “Copied” («تم النسخ» on an Arabic page). Read by Copy
data-no-auto-close .nds-share-copy in a menu Read by Dropmenu: a click on the item leaves the menu open. Share closes the menu when the checkmark ends
data-status="success" .nds-share-copy Copy sets it after a copy, and removes it after 2 seconds. While it is set, the button shows the success color
aria-disabled="true" .nds-share-copy Copy sets and removes it with data-status

JavaScript

The NDS.Share script loads after the page shows. Until it loads, each call loads it and returns a promise of the result, so await a call whose result you use.

Method Effect
NDS.Share.init() Adds .nds-share-menu to every share menu and listens for clicks on the share buttons. The loader calls it. A second call replaces the listener

Share fires no events. After you add a share menu to the page, call init() again, so the new menu gets .nds-share-menu. New buttons need no call.

var card = document.querySelector('#news-card-12'); card.insertAdjacentHTML('beforeend', shareMenuHtml); NDS.Share.init();

The full API is in the banner of _js/nds-share.js.

Last Modified Date: 05/11/2026 - 12:40 AM
Was this page useful?
60% of users said Yes from 2843 Feedbacks