Retro desktop window

Draggable retro desktop window in CSS and vanilla JS: drag the title bar or press the arrow keys. Black title bar, pass grid, dotted backdrop.

The window is centered with left and top at 50% and translate(-50%, -50%), plus two custom properties, --rwn-x and --rwn-y, that the script updates to move it. Dragging uses pointer events on the title bar: pointerdown stores the start point and captures the pointer, pointermove sets the offset, and pointerup ends the drag. The window has tabindex=0 and moves 12px per arrow key press. Both input paths clamp the offset so the window can overhang the frame by at most 40px.

Open preview
snippet.html89 lines
<div class="rwn" data-rwn>
  <div class="rwn__bg" aria-hidden="true"></div>
  <article class="rwn__win" tabindex="0" aria-label="Confidence window. Drag the title bar to move it.">
    <div class="rwn__bar" data-rwn-handle>Tessel.Confidence</div>
    <div class="rwn__rail" aria-hidden="true"></div>
    <div class="rwn__pane">
      <p class="rwn__line">Levels and thresholds ..</p>
      <p class="rwn__pass"><span>01 / 40 PASS</span></p>
      <div class="rwn__grid" aria-hidden="true">
        <i class="d"></i><i class="m"></i><i class="d"></i><i></i><i></i><i></i><i></i><i></i>
        <i class="d"></i><i class="m"></i><i></i><i></i><i></i><i></i><i></i><i></i>
        <i class="d"></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
      </div>
      <div class="rwn__scale"><span>NO</span><span>50/50</span><span>YES</span></div>
    </div>
  </article>
</div>

<style>
  .rwn {
    --rwn-bg: #f386a1;
    --rwn-ink: #1e1e1e;
    position: relative;
    box-sizing: border-box;
    width: min(100%, 340px);
    height: 340px;
    background: var(--rwn-bg);
    overflow: hidden;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    color: var(--rwn-ink);
  }
  .rwn *, .rwn *::before, .rwn *::after { box-sizing: border-box; }
  .rwn__bg {
    position: absolute; inset: 0;
    background-image: radial-gradient(rgba(30, 30, 30, 0.3) 1px, transparent 1.2px);
    background-size: 5px 5px;
  }
  .rwn__win {
    position: absolute; left: 50%; top: 50%;
    width: 250px;
    transform: translate(calc(-50% + var(--rwn-x, 0px)), calc(-50% + var(--rwn-y, 0px)));
    background: #fff;
    border: 1px solid var(--rwn-ink);
    outline: 1px solid #fff; outline-offset: 2px;
    box-shadow: 4px 4px 0 rgba(30, 30, 30, 0.35);
  }
  .rwn__win:focus-visible { outline: 2px solid var(--rwn-ink); outline-offset: 3px; }
  .rwn__bar { background: var(--rwn-ink); color: #fff; padding: 2px 6px; font-size: 13px; cursor: grab; user-select: none; touch-action: none; }
  .rwn__bar:active { cursor: grabbing; }
  .rwn__pane { padding: 6px 6px 8px; }
  .rwn__rail { display: none; }
  .rwn__line { margin: 0 0 8px; font-size: 12px; }
  .rwn__pass { margin: 0 0 8px; }
  .rwn__pass span { display: inline-block; background: var(--rwn-ink); color: #fff; font-size: 12px; padding: 0 3px; }
  .rwn__grid { display: grid; grid-template-columns: repeat(8, 1fr); border-top: 1px solid var(--rwn-ink); border-left: 1px solid var(--rwn-ink); }
  .rwn__grid i { aspect-ratio: 1; border-right: 1px solid var(--rwn-ink); border-bottom: 1px solid var(--rwn-ink); position: relative; }
  .rwn__grid i.d::after, .rwn__grid i.m::after { content: ""; position: absolute; inset: 20%; background: #2a2a2a; }
  .rwn__grid i.m::after { background: #6b6b6b; }
  .rwn__scale {
    display: flex; justify-content: space-between; margin-top: 8px; padding: 14px 2px 1px;
    background: linear-gradient(90deg, #f4f4f4, #1e1e1e);
    border: 1px solid var(--rwn-ink); font-size: 10px; color: #fff; mix-blend-mode: normal;
  }
  .rwn__scale span { background: var(--rwn-ink); padding: 0 2px; }
  .rwn__scale span:first-child { background: var(--rwn-ink); }
</style>

<script>
  (function () {
    var root = document.currentScript.previousElementSibling.previousElementSibling;
    if (!root || !root.matches("[data-rwn]")) root = document.querySelector("[data-rwn]");
    var handle = root.querySelector("[data-rwn-handle]");
    var win = root.querySelector(".rwn__win");
    var x = 0, y = 0, sx, sy, ox, oy, drag = false;
    function clamp() {
      var lim = (root.clientWidth - win.offsetWidth) / 2 + 40;
      var limy = (root.clientHeight - win.offsetHeight) / 2 + 40;
      x = Math.max(-lim, Math.min(lim, x)); y = Math.max(-limy, Math.min(limy, y));
      win.style.setProperty("--rwn-x", x + "px"); win.style.setProperty("--rwn-y", y + "px");
    }
    handle.addEventListener("pointerdown", function (e) { drag = true; sx = e.clientX; sy = e.clientY; ox = x; oy = y; handle.setPointerCapture(e.pointerId); });
    handle.addEventListener("pointermove", function (e) { if (!drag) return; x = ox + e.clientX - sx; y = oy + e.clientY - sy; clamp(); });
    handle.addEventListener("pointerup", function () { drag = false; });
    win.addEventListener("keydown", function (e) {
      var d = { ArrowLeft: [-12, 0], ArrowRight: [12, 0], ArrowUp: [0, -12], ArrowDown: [0, 12] }[e.key];
      if (!d) return; e.preventDefault(); x += d[0]; y += d[1]; clamp();
    });
  })();
</script>

Kind
Component
Category
Card
Added
6 Nov 2026
Canvas
Centered
File
snippet.html
Size
89 lines · 4.4 KB
Inspired by
typesafe.ai
  • retro
  • draggable
  • monospace
  • pink

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