Code diff card

Code diff block in HTML and CSS: file path bar, line numbers, and red and green rows with a colored left edge. Scrolls sideways.

The diff is an ordered list inside a figure, with the file path in the figcaption. Each row is a flex line with white-space: pre, so indentation is kept, and a hand-written line number in an i element. Rows marked is-del or is-add get a tinted background and a 2px red or green left border, and the number takes the same color. The list has overflow-x: auto, so long lines scroll inside the card.

Open preview
snippet.html32 lines
<figure class="cdc">
  <figcaption class="cdc__bar"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4 1.5h5l3 3v10H4z" fill="none" stroke="currentColor" stroke-width="1.2"/></svg><code>fleet-app/src/screens/Home.tsx</code></figcaption>
  <ol class="cdc__code">
    <li><i>01</i>import React from 'react'</li>
    <li><i>02</i>import { View, Spinner } from 'ui'</li>
    <li class="is-del"><i>03</i>import { useFleet } from '@hooks/fleet'</li>
    <li class="is-add"><i>03</i>import { useFleet, Sync } from '@hooks/fleet'</li>
    <li><i>04</i></li>
    <li><i>05</i>export const Home = () =&gt; {</li>
    <li class="is-del"><i>06</i>  const { vans, isSynced } = useFleet()</li>
    <li class="is-add"><i>06</i>  const { vans, sync } = useFleet()</li>
    <li><i>07</i>  if (sync === Sync.Cold) return &lt;Spinner /&gt;</li>
  </ol>
</figure>

<style>
  .cdc { --cdc-bg: #0e0f11; --cdc-line: rgba(255,255,255,0.1);
    box-sizing: border-box; margin: 0; width: 100%; max-width: 480px; overflow: hidden; background: var(--cdc-bg);
    border: 1px solid var(--cdc-line); border-radius: 12px; color: #d4d8de; box-shadow: 0 24px 60px rgba(0,0,0,0.5);
    font: 12px/22px ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
  .cdc *, .cdc *::before, .cdc *::after { box-sizing: border-box; }
  .cdc__bar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--cdc-line); color: #8a8f98; }
  .cdc__bar svg { width: 15px; height: 15px; flex: none; }
  .cdc__bar code { font: inherit; letter-spacing: 0.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .cdc__code { list-style: none; margin: 0; padding: 10px 0; overflow-x: auto; }
  .cdc__code li { display: flex; gap: 16px; min-height: 22px; padding: 0 18px; white-space: pre; border-left: 2px solid transparent; }
  .cdc__code i { flex: none; width: 2ch; font-style: normal; color: #565a61; }
  .cdc__code .is-del { background: rgba(229,72,77,0.14); border-left-color: #e5484d; }
  .cdc__code .is-del i { color: #e5484d; }
  .cdc__code .is-add { background: rgba(76,195,138,0.14); border-left-color: #4cc38a; }
  .cdc__code .is-add i { color: #4cc38a; }
</style>

Kind
Component
Category
Card
Added
6 Nov 2026
Canvas
Centered
File
snippet.html
Size
32 lines · 2.1 KB
Inspired by
linear.app
  • dark
  • code
  • diff
  • monospace

One file: HTML, a style block and, when needed, a small script. Paste it anywhere. Nothing to install.