highlight.js
Zero-dependency JavaScript syntax highlighter with automatic language detection for over 190 languages.
Repository Health
Technical Analysis
Highlight.js is a JavaScript library that adds syntax highlighting to code blocks in the browser or on the server, with no runtime dependencies and no required build step. Drop in a script tag and a stylesheet, call hljs.highlightAll(), and it scans the page for <pre><code> blocks, automatically detects the language of each one, and wraps tokens in CSS classes that any of its ~100 bundled themes can style.
Beyond the drop-in browser build, highlight.js ships a core entry point for tree-shaken bundles that only register the languages an app actually needs, a full Node.js API for highlighting code server-side (used heavily in static-site generators and Markdown renderers), and a plugin system for extending behavior such as line numbers or copy buttons. The library has been a fixture of the JS ecosystem since 2011 and remains actively maintained, with over 190 language grammars covering everything from mainstream languages to esoteric DSLs.
What You Get
- A syntax-highlighting engine with automatic language detection across 190+ bundled language grammars
- Multiple import strategies: a monolithic browser build, a
coremodule for registering only the languages you need, and a Node.jsrequire/import-friendly package - Around 100 CSS themes covering popular editor color schemes (GitHub, Monokai, Atom One, etc.)
- A plugin API for extending highlighting behavior (line numbers, copy-to-clipboard, custom renderers)
- First-class TypeScript type definitions (
types/index.d.ts) shipped in the package - A documented language-grammar authoring format (
mode-reference.rst,language-guide.rst) for adding or customizing language definitions
Common Use Cases
- Highlighting code blocks rendered from Markdown in blogs, documentation sites, and static-site generators
- Adding syntax highlighting to a CMS, wiki, or forum’s rich-text code snippets
- Server-side rendering of highlighted code (e.g. in a Node.js SSG build step) so pages ship pre-highlighted HTML with no client-side JS cost
- Embedding a lightweight, dependency-free highlighter in browser extensions or Electron apps where bundle size matters
Under The Hood
Architecture - Highlighting flows through three stages: src/highlight.js (the HLJS factory) owns the public API and orchestrates a call into lib/mode_compiler.js, which compiles a declarative language grammar (a tree of Mode objects with begin/end/contains regex rules) into a CompiledLanguage with an internal MultiRegex matcher that combines many small regexes into one big alternation for fast single-pass scanning. As the compiled matcher walks the input, lib/token_tree.js’s TokenTreeEmitter builds a tree of matched tokens, which lib/html_renderer.js walks to emit the final <span class="hljs-*"> HTML. Automatic language detection (highlightAuto) simply runs this pipeline against every registered language and picks the highest-scoring result, capped by MAX_KEYWORD_HITS heuristics in highlight.js.
Tech Stack - The library itself is plain ES modules with zero runtime dependencies (confirmed in package.json’s empty dependencies), targeting Node >=12 and browsers directly via a <script> tag. Build tooling uses Rollup (@rollup/plugin-commonjs, @rollup/plugin-node-resolve) plus Terser for minification, ESLint (eslint-config-standard) for linting, and TypeScript purely for authoring the shipped .d.ts type definitions (types/index.d.ts) rather than for the implementation, which stays plain JavaScript.
Code Quality - The test/ directory holds 46 files split into api/, detect/, markup/, parser/, and regex/ suites run via Mocha (npm test), covering the public API surface, auto-detection accuracy, and low-level regex/parser internals. Internal modules are small and single-purpose (regex.js at 156 lines, utils.js at 36 lines, mode_compiler.js at 432 lines), consistently documented with JSDoc @typedef blocks referencing the shared highlight.js type definitions, which gives editor-level type checking without a TypeScript build step.
API Design - The public surface is deliberately small: highlightAll() for zero-config browser use, highlightElement()/configure() for finer control, and highlight(code, {language}) / highlightAuto(code) for the underlying Node/programmatic API, with registerLanguage() to opt into a la carte grammars via the core entry point. This layered design — one line to get started, explicit imports to shrink bundle size — plus the shipped TypeScript types keeps the getting-started cost low while still supporting advanced use (custom languages, plugins) without extra ceremony.
Used by 73 apps in this directory
PostHog
Ab Testing Experimentation · Analytics · Developer Tools
The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.
Puter
Developer Tools · File Storage
A self-hostable, web-based internet OS with desktop GUI, cloud storage, AI drivers, and a developer SDK — all running in your browser.
Refly
AI Development · Automation · No Code Platforms
Build deterministic, versioned agent skills from natural language—run them anywhere from Claude Code to Slack.
Rocket.Chat
Team Chat
The secure, self-hosted team communications platform for organizations that cannot compromise on data sovereignty.
Scalar
Developer Tools
Beautiful, interactive OpenAPI documentation with a built-in offline-first API client and multi-language code generation — all in one open-source platform.
sigle
Blogging
A decentralized, open-source writing platform that permanently stores your stories on the Stacks blockchain and Arweave — where Web3 content creators own their words forever.
SillyTavern
AI Assistants
The power-user LLM frontend that unifies dozens of AI backends with a rich scripting engine, immersive Visual Novel mode, and a thriving extension ecosystem.
strapi
CMS
Open-source headless CMS that auto-generates REST and GraphQL APIs from your content models, with a fully customizable admin panel you control.
superset
AI Code Assistants · AI Development
Orchestrate an army of AI coding agents—Claude Code, Codex, Gemini CLI, and more—running simultaneously in isolated git worktrees from a single Electron desktop app.