Skip to content

Diff Highlight

A copy-paste code & terminal component in pure HTML & CSS. Zero dependencies, framework-agnostic, MIT-licensed.

Code & TerminalHTMLCSSany framework
-const x = 1+const x = 2 const y = 3+console.log(x)

Copy into your project

HTML
<!-- Diff Highlight — added/removed lines with prefix gutter -->
<pre class="nuda-diff">
  <code>
    <span class="nuda-diff__line is-rem"><i>-</i>const x = 1</span>
    <span class="nuda-diff__line is-add"><i>+</i>const x = 2</span>
    <span class="nuda-diff__line"><i> </i>const y = 3</span>
    <span class="nuda-diff__line is-add"><i>+</i>console.log(x)</span>
  </code>
</pre>
CSS
/* Diff Highlight
   Git-style added (+) / removed (-) lines with colored gutter accents.
   Lines fade in with a small stagger.
   Customize: --diff-add, --diff-rem, --diff-bg */

.nuda-diff {
  --diff-add: #e4ff54;
  --diff-rem: #ff6363;
  --diff-bg: #0a0a0a;
  margin: 0;
  padding: 10px 0;
  background: var(--diff-bg);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  font: 500 0.85rem ui-monospace, monospace;
  color: #fafafa;
  width: 100%;
  max-width: 480px;
  overflow: hidden;
}

.nuda-diff code {
  display: flex;
  flex-direction: column;
}

.nuda-diff__line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 14px;
  color: #a1a1aa;
  border-left: 2px solid transparent;
  animation: nuda-diff-in 0.4s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.nuda-diff__line:nth-child(1) { animation-delay: 0s; }
.nuda-diff__line:nth-child(2) { animation-delay: 0.1s; }
.nuda-diff__line:nth-child(3) { animation-delay: 0.2s; }
.nuda-diff__line:nth-child(4) { animation-delay: 0.3s; }

.nuda-diff__line i {
  display: inline-flex;
  width: 12px;
  color: #63636e;
  font-style: normal;
  font-weight: 700;
  flex-shrink: 0;
  font-size: 0.95rem;
}

.nuda-diff__line.is-add {
  background: rgba(228, 255, 84, 0.08);
  border-left-color: var(--diff-add);
  color: #fafafa;
}
.nuda-diff__line.is-add i { color: var(--diff-add); }

.nuda-diff__line.is-rem {
  background: rgba(255, 99, 99, 0.08);
  border-left-color: var(--diff-rem);
  color: #fafafa;
  text-decoration: line-through;
  text-decoration-color: rgba(255, 99, 99, 0.4);
}
.nuda-diff__line.is-rem i { color: var(--diff-rem); }

@keyframes nuda-diff-in {
  from { opacity: 0; transform: translateX(-4px); }
  to   { opacity: 1; transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .nuda-diff__line { animation: none; }
}

How to use Diff Highlight

Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.

Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.

More code & terminal components

← Browse all NudaUI components