<div class="demo">
  <p id="icerik">Lorem ipsum dolor sit amet.</p>
  <button id="kopyala">Kopyala</button>
</div>
html,
body {
  margin: 0;
  padding: 0;
}
.demo {
  margin: 1rem auto;
  display: flex;
  justify-content: center;
  align-content: center;
  align-items: center;
  flex-direction: column;
}

#kopyala {
  border: 0.5rem solid #eee;
  background: #eee;
  border-radius: 1rem;
  width: 10rem;
}
const contentCp = document.getElementById("icerik");
const copyBtn = document.getElementById("kopyala");

copyBtn.onclick = copyToClipboard;

function copyToClipboard() {
  navigator.clipboard
    .writeText(contentCp.innerText)
    .then(() => alert("Kopyalandı"))
    .catch((e) => alert(e.message));
}

External CSS

  1. https://codepen.io/wolkanca/pen/wvgOPWb

External JavaScript

  1. https://codepen.io/wolkanca/pen/wvgOPWb