Syntax highlighting that keeps up with live code.
Very fast and lightweight. Each line is highlighted once, and only the line being written gets updated, so it stays fast even when the code is long. No flicker, no dependencies.
Live demo Β· GitHub Β· npm Β· Docs
On any page, no build step:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/codelight.js/build/styles/default.min.css">
<script src="https://cdn.jsdelivr.net/npm/codelight.js/build/codelight.min.js"></script>
<script>codelight.highlightAll();</script>For live code, write each chunk as it arrives:
const view = codelight.mount(codeElement, { lang: "python" });
view.write(chunk);In React: npm install codelight.js, then <CodeLight code={reply} lang="ts" />.
| β‘ Keeps up with live code | Each update costs one short line of work, however long the code already is. |
| π§© Half-finished Markdown | Finds code blocks in Markdown that's still arriving, including unclosed fences. |
| π¦ 8.4 KB, no dependencies | All 19 languages in one file. |
| π Light and dark themes | Every colour is a CSS variable and meets WCAG AA contrast. |
| π Works anywhere | A script tag, any bundler, or React with server rendering. |
| Repo | What it is |
|---|---|
| codelight.js | The library: source, docs, tests and releases |
| codelightjs.github.io | The website and live demo |
MIT licensed. Built by CK Giri.