Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <h1>Native Sharing Web Component</h1>
<p>This web component uses the <a href="">Web Share API</a> to share a link. The sharing code was originally written for <a href="">my personal website</a>.</p>
<p>The markup is generated without Shadow DOM and can be styled from outside the component.</p>
<p>See also: <a href="">Native Sharing Web Component with is-Attribute and Polyfill</a> and <a href="">Native Sharing Web Component with Shadow DOM</a>.</p>
<p>Thanks to <a href="">Mario</a> who pointed me to this article <a href="">Web components without Shadow DOM</a>.
<p>I also wrote an <a href="">article on my blog</a>.</p>
<p>Please note: This works currently only in Safari (macOS and iOS) and Chrome on Windows and Android. Other browsers won't show a button beneath.</p>
<msme-sharing-button data-buttontext="share this page" data-sharing-url="" data-buttonclass="button" data-sharing-title="" data-sharing-text="Martins Website"></msme-sharing-button>


                .button {
  border: 1px solid black;
  color: black;
  background-color: white;
  border-radius: 1rem;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  display: flex;
  align-items: center;

  &:hover {
    background-color: black;
    color: white;

  svg {
    width: 1em;
    height: 1em;
    margin-right: 0.5em;



                class sharingButton extends HTMLElement {
  constructor() {

    if (!navigator.share) {
      console.log("msme-sharing-button: native sharing not supported.");

    if (!this.getAttribute("data-sharing-url")) {
      console.error("msme-sharing-button: no url provided.");

    // Android uses a different icon for sharing buttons
    // from devices in Apples ecosystem
    // Thanks to:
    const ua = navigator.userAgent.toLowerCase();
    const isAndroid = ua.indexOf("android") > -1;
    let icon = null;
    if (isAndroid) {
      icon = `<svg aria-hidden="true" focusable="false" xmlns="" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><line x1="8.59" y1="13.51" x2="15.42" y2="17.49"/><line x1="15.41" y1="6.51" x2="8.59" y2="10.49"/></svg>`;
    } else {
      icon = `<svg aria-hidden="true" focusable="false" xmlns="" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"/><polyline points="16 6 12 2 8 6"/><line x1="12" y1="2" x2="12" y2="15"/></svg>`;

    let text = this.getAttribute("data-buttontext") ?? "share";
    let cssClass = this.getAttribute("data-buttonclass")
      ? `class="${this.getAttribute("data-buttonclass")}"`
      : "";

    let template = document.createElement("template");
    template.innerHTML = `<button type="button" ${cssClass}>${icon} ${text}</button>`;

    this._contents = new DocumentFragment();

    // and here's the sharing-action
    let button = this._contents.querySelector("button");
    button.addEventListener("click", () => {
      const shareData = {
        title: this.getAttribute("data-sharing-title"),
        text: this.getAttribute("data-sharing-text"),
        url: this.getAttribute("data-sharing-url")

        .then(() => console.log("msme-sharing-button: sharing successful"))
        .catch((error) =>
          console.log("msme-sharing-button: error while sharing", error)


customElements.define("msme-sharing-button", sharingButton);