The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join
Snippet · HTML

Copy Text Button

Shared by Darshit Rajyaguru · May 14, 2026

36 views
1 upvote
Back to Snippets

Adds a simple copy-to-clipboard button for users.

<input type="text" value="Copy this text" id="copyText">

<button onclick="copyText()">Copy</button>

<script>
function copyText() {
	const copyInput = document.getElementById('copyText');

	copyInput.select();
	copyInput.setSelectionRange(0, 99999);

	navigator.clipboard.writeText(copyInput.value);

	alert('Copied successfully!');
}
</script>
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments

Proudly supported by