Copy to Clipboard

Add copy-to-clipboard functionality to any element. Let users easily copy text or code snippets with a click.

Copy the Copy to Clipboard <script> and paste into the <head> of your page.

<!-- [WebTricks by CodeRaccoons] - Copy to Clipboard --> <script async src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/WebTricks@1/Dist/Functional/CopyToClipboard.min.js"></script>

Required attributes

ctc copy element text target

Attribute to add

Namewt-copycb-element
Valuetarget

Instructions

Add this to the element that has the text that you want to get copied, please note that this functionality will only copy the text that is within this element.

How does it look?

ctc copy element text target example
ctc trigger element

Attribute to add

Namewt-copycb-element
Valuetrigger

Instructions

This does not have a default functionality, it should be set along with a target attribute to work.

How does it look?

ctc trigger element example

Optional attributes

Optionalctc copied message text target

Attribute to add

Namewt-copycb-element
Valuetexttarget

Instructions

When using the Copy to Clipboard functionality you can select an element to show a message, add this attribute to the text that you want to display this text change

How does it look?

ctc copied message text target example
Optionalctc active class

Attribute to add

Namewt-copycb-active
Valueclassname

Instructions

Add a class to change the style of the trigger element when the content is copied.

How does it look?

ctc active class example
Optionalctc copied message

Attribute to add

Namewt-copycb-message
ValueCopied!

Instructions

Replaces the message to show the element got copied to clipboard,

How does it look?

ctc copied message example

Working examples

 See the Pen  WT - CopyToClipboard by Code Raccoons (@jorchie)  on CodePen.