We use cookies to ensure you get the best experience on our website. Read our privacy policy

Skip to main content

Directory

Copy to Clipboard

The Copy to Clipboard script is a tool that helps you copy text to the clipboard. It is a tool that will help you copy text to the clipboard.

First add a content dataset attribute to the element with the data you want to copy to the clipboard.

<p data-content="Hello World">Copy Me</p>

Next add the js-copy-clipboard class to the element. Now when the element is clicked the data will be copied to the clipboard.

<p class="js-copy-clipboard">Copy Me</p>

When using a script to append this data you can add ClipboardElement to the element for intellisense.

const copyButton = document.querySelector<HTMLButtonElement & ClipboardElement>('button');
copyButton.dataset.content = 'Hello World';
North Star Themes Logo

Subscribe to our newsletter

Get the latest AstroJS tips and tricks right to your inbox

Email: [email protected]

© 2025 North Star Themes

Web Kit Provided By North Star Themes