TanStack Highlight is a tiny, synchronous syntax highlighter designed specifically for blogs and documentation.
It occupies the space between minimal JavaScript-only scanners and full grammar engines:
Most syntax highlighters optimize for one of two different products:
TanStack Highlight optimizes for a third product: valid code samples rendered repeatedly in documentation. It gives up automatic language detection, editor state, semantic language-service tokens, and TextMate compatibility in exchange for a small synchronous path that can run on both server and client.
The @tanstack/highlight/core entry contains no shipped languages. Every language is an isolated LanguageDefinition under @tanstack/highlight/languages/*.
There is no WebAssembly, worker, filesystem dependency, or asynchronous initialization. A highlighter created from the same registrations and options returns the same result in Node.js and the browser.
Highlighting emits stable th-* classes instead of token colors. Light and dark themes are CSS variable sets applied to the same markup.
Most languages use small priority patterns. JavaScript templates, JSX, markup embeddings, shell heredocs, and similar cases use focused stateful scanners. The library does not contain a general grammar interpreter.
import { highlight } from '@tanstack/highlight'
const result = highlight(`const answer = 42`, { lang: 'ts' })
result.code
result.lang
result.tokens
result.htmlThe HTML contract is one escaped <pre><code> tree:
<pre class="th-code th-code--ts" data-language="ts">
<code>...</code>
</pre>