About this snippet

Display source code beautifully with this syntax-highlighted style block. It includes a functional "Copy" button in the top right corner, making it easy for developers to grab your snippets.

Size
1.6 KB
Uses
HTML, CSS, JavaScript
Loads
Nothing external
Views
428
<div class="code-wrapper">
  <div class="code-header">
    <span class="lang-label">CSS</span>
    <button class="copy-code-btn">Copy</button>
  </div>
  <pre><code id="codeSource">.element {
  display: flex;
  justify-content: center;
  color: #3b82f6;
}</code></pre>
</div>
.code-wrapper {
  font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  background: #1e293b;
  border-radius: 12px;
  overflow: hidden;
  max-width: 500px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}
.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: #0f172a;
  border-bottom: 1px solid #334155;
}
.lang-label {
  color: #94a3b8;
  font-size: 0.85rem;
  font-weight: 600;
}
.copy-code-btn {
  background: #334155;
  border: none;
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s;
}
.copy-code-btn:hover {
  background: #475569;
}
pre {
  margin: 0;
  padding: 20px;
  overflow-x: auto;
}
code {
  font-family: monospace;
  color: #e2e8f0;
  font-size: 0.9rem;
  line-height: 1.5;
}
const copyCodeBtn = document.querySelector(".copy-code-btn");
const codeSource = document.getElementById("codeSource");

copyCodeBtn.addEventListener("click", () => {
  navigator.clipboard.writeText(codeSource.innerText).then(() => {
    const originalText = copyCodeBtn.innerText;
    copyCodeBtn.innerText = "Copied!";
    setTimeout(() => {
      copyCodeBtn.innerText = originalText;
    }, 2000);
  });
});
Esc
↑↓ moveEnter select

Start from a template

Open an .html file, or HTML, CSS, JS, Markdown, Less or TypeScript files. You can also drop them here. Styles and scripts go into their panes.

Share

Source

Keyboard shortcuts

Save