highlight.js

Zero-dependency JavaScript syntax highlighter with automatic language detection for over 190 languages.

Library
npm
v11.12.0
25,004 stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
85 /100 Excellent
Development Activity 84
Maintenance 72
Community 84
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
84 /100 Excellent
Architecture 85
Code Quality 82
Innovation 80
Learning Curve 88

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 core module for registering only the languages you need, and a Node.js require/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

TypeScript
97%
GPL 3.0

OpenKnowledge

Code Editors · Knowledge Management · Note Taking

4,485

A beautiful, local-first markdown IDE that turns any git repo into a live collaborative workspace for humans and AI coding agents like Claude, Codex, and OpenCode.

View details
79
Repo Health
89
Technical
64
Dependency
Built with
TypeScript 97%
Updated today
Python
37%
Other

Open WebUI

AI Agents · AI Assistants

154,169

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
92
Repo Health
75
Technical
66
Dependency
Built with
Python 37%
Svelte 34%
JavaScript 21%
Updated yesterday
TypeScript
90%
MIT

OpenClaw

AI Agents · AI Assistants

391,553

An open-source AI assistant that runs on your own hardware and meets you in Discord, Slack, WhatsApp, iMessage, Telegram, and 20+ other channels, with native apps for every major platform.

View details
88
Repo Health
88
Technical
67
Dependency
Built with
TypeScript 90%
Updated today
TypeScript
39%
AGPL 3.0

OpenObserve

Analytics · Devops · Monitoring

22,312

Open source observability platform for logs, metrics, traces, and real user monitoring — delivering 140x lower storage costs than Elasticsearch with a single binary you can run in under 2 minutes.

View details
90
Repo Health
9
Technical
71
Dependency
Built with
TypeScript 39%
Rust 30%
Vue 17%
Updated today
JavaScript
92%
Other

OpenSign

Digital Signiture

7,080

Self-host a full-featured DocuSign alternative with unlimited e-signatures, multi-signer workflows, and cryptographic PDF signing.

View details
77
Repo Health
61
Technical
70
Dependency
Built with
JavaScript 92%
Updated 1 months ago
Python
74%
AGPL 3.0

OpenViking

AI Development · AI Memory · Databases

39,552

An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.

View details
85
Repo Health
75
Technical
64
Dependency
Built with
Python 74%
Rust 12%
TypeScript 11%
Updated today
Clojure
73%
MPL 2.0

Penpot

Design Tools

60,867

Open-source design platform with GPU-accelerated canvas, native design tokens, and MCP-powered AI workflows for teams that ship fast.

View details
91
Repo Health
83
Technical
72
Dependency
Built with
Clojure 73%
Updated yesterday
TypeScript
96%
MIT

Pi

AI Agents

113,876

An open-source, self-extensible agent harness and coding agent CLI — a modular runtime (agent core, unified multi-provider LLM API, TUI) with no built-in permission system by default, documented containerization patterns for sandboxing instead.

View details
88
Repo Health
73
Technical
74
Dependency
Built with
TypeScript 96%
Updated yesterday
TypeScript
69%
AGPL 3.0

Plane

Collaboration · Productivity · Project Management

60,619

Open-source project management platform to replace Jira, Linear, and ClickUp — with built-in cycles, real-time collaborative docs, and full self-hosting.

View details
90
Repo Health
82
Technical
77
Dependency
Built with
TypeScript 69%
Python 28%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers