Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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.


Save Automatically?

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>Copy me!</h1>
  <div class="click-to-copy-container">
      title="Click to Copy Email Address"
  <a href="" class="click-to-copy-fallback">


                /* Styling and layout purposes only */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";

main {
  background: #F9F5FF;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  min-height: 100vh;

main h1 {
  font-weight: 600;
  font-size: 34px;
  letter-spacing: -0.4px;
  color: #07070A;
  margin-bottom: 1rem;

.click-to-copy-container {
  position: relative;
}, {
  background: #21FA90;
  border: none;
  box-shadow: none;
  padding: 1rem;
  border-radius: .25rem;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
  color: #07070A;
  transition: all .2s ease-in-out;
  text-decoration: none;
}, hover {
  opacity: .8;
} + span {
  /* We make the span hidden by default. In this case, using display: none; isn't an issue from an accessibility standpoint, since we don't want screen readers to pick this up unless the user clicks on the button */
  display: none;
  /* From here on, just styling purposes 👇🏻 */
  margin-left: 1rem;
  background: #DADADA;
  padding: .5rem;
  border-radius: .2rem;
  position: absolute;
  top: .75rem;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .4px;
  font-weight: 600;
  color: #666;

/* Styles for the tooltip arrow */ + span:after {
	right: 100%;
	top: 50%;
	border: solid transparent;
	content: "";
	height: 0;
	width: 0;
	position: absolute;
	pointer-events: none;
	border-color: rgba(218, 218, 218, 0);
	border-right-color: #DADADA;
	border-width: 6px;
	margin-top: -6px;

/* When the click event is fired, and the .is-copied class is added to the button, show the tooltip */ + span {
  display: initial;

/* Hide the fallback version on desktop resolutions */ {
  display: none;

/* Toggle fallback version for mobile, where the native email apps are way more used and mailto link become way more relevant. I'm using an iPad portrait resolution as the breakpoint, but feel free to play with it! */
@media screen and (max-width: 768px) {
  /* Hide the desktop button */ {
    display: none;
  /* Show its replacement */ {
    display: block;


                // Select the button from the markup
const button = document.querySelector('.click-to-copy');

// Function that runs on click. It: 
// 1) Prevents the default behavior of the button (refresh the page);
// 2) Runs the copyToClipboard function;
// 3) Adds and removes some CSS classes, used for styling and notifying the user about the copy event
const clickToCopy = (e) => {
  setTimeout(() => {'is-copied') }, 1200);

// Copy to clipboard function, taken from
const copyToClipboard = (str) => {
  const el = document.createElement('textarea');
  el.value = str;
  el.setAttribute('readonly', ''); = 'absolute'; = '-9999px';
  const selected =
    document.getSelection().rangeCount > 0 
      ? document.getSelection().getRangeAt(0)
      : false;;
  if (selected) {

// Fire the event on click
button.addEventListener('click', clickToCopy);