<button>
  Copy URL To Clipboard
</button>
body {
  display: grid;
  justify-items: center;
  align-items: center;
  height: 100vh;
}

button {
  appearance: none;
  border: none;
  padding: 1em 2em;
  background: #eee;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.3s;
  
  &:hover {
    background: #ddd;
  }
  
  &:focus {
    background: #ccc;    
  }
}
View Compiled
document.querySelector('button').addEventListener('click', (e) => {
  e.preventDefault();

  const input = document.createElement("input"); 
  input.value = location.href;
  document.body.appendChild(input);
  input.select();  
  document.execCommand("copy");
  input.remove();

  alert('done');
});
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.