OSS TanbouSign in with GitHub

highlight source code with more than 180 language definitions and optionally auto-detect the language

About these scores

OSS scale score is an unbounded metric that log-compresses and weights Stars, Watchers, Forks, and Contributors. Discovery score is the current OSS scale score minus the score at discovery. Update pace is commits in the last 30 days, growth momentum is the OSS scale score difference within the recent observation window, and OSS health is a 0–100 rating based on available recency, Community Health, and release data.

Stars
25,005
Primary language
JavaScript
License
BSD-3-Clause
Repository last updated
Sep 6, 2026
On this page

Overview

Highlight.js is a JavaScript syntax-highlighting library that runs in browsers and on servers without depending on a framework. It supports both explicit language selection and automatic language detection from source text.

Features and best fit

Based on official documentation; not hands-on tested · Content checked:

Key features

Highlight pre/code blocks across a page in the browser

Load the stylesheet and library and call hljs.highlightAll() to process code inside <pre><code> elements. Known languages can be declared with classes such as language-html.

Sources: [1]

Choose explicit or automatic language detection in Node.js

Server-side code can call highlight() with a language name or highlightAuto() to infer the language from the input. The generated highlighted HTML is available from the result's value field.

Sources: [1]

Load fewer grammars to reduce the bundle

The top-level package can load all bundled languages, while highlight.js/lib/common provides a smaller common subset. Applications can also register only the grammars they need.

Sources: [1]

Best fit

Fits documentation, code viewers, and article code blocks that need consistent syntax highlighting

It works well for technical documentation, Markdown-generated code blocks, and server-rendered code snippets that should share one highlighting implementation.

Sources: [1]

Before adoption

Prefer an explicit language when the language is already known

Automatic detection infers a language from the source text, so short snippets or similar syntaxes can be ambiguous. A class or the highlight() language option can pin known input.

Sources: [1]

The 11.12.0 npm package requires Node.js 12 or later

Package metadata for 11.12.0 declares Node.js >=12.0.0. Browser usage also needs a theme stylesheet to provide the visible highlighting colors.

Sources: [2][1]

Official sources

  1. [1]Highlight.js 11.12.0 README(2026-10-05)
  2. [2]Highlight.js 11.12.0 package metadata(2026-10-05)
  3. [3]Highlight.js 11.12.0 release(2026-10-05)
  4. [4]Highlight.js BSD-3-Clause license(2026-10-05)
Supplemental curator note

A practical strength is choosing between explicit language selection and automatic detection through the same library. When a page does not need every grammar, lib/common or explicitly registered languages can keep the shipped bundle smaller.

Try it in 3 steps

  1. 1

    Check Node.js and install Highlight.js 11.12.0

    Pin the reviewed stable release in a temporary directory without changing an existing project.

    node -e 'if (Number(process.versions.node.split(".")[0]) < 12) throw new Error("Highlight.js 11.12.0 requires Node.js >= 12")' && demo=$(mktemp -d "${TMPDIR:-/tmp}/highlightjs.XXXXXX") && cd "$demo" && npm init -y >/dev/null && npm install --save-exact highlight.js@11.12.0
  2. 2

    Create a script that highlights XML explicitly

    Follow the README's Node.js pattern while pinning the language to XML instead of relying on auto-detection.

    printf "%s\n" "const hljs = require('highlight.js/lib/common');" "const result = hljs.highlight('<h1>Hello</h1>', { language: 'xml' });" "console.log(result.value);" "if (!result.value.includes('hljs-tag')) throw new Error('highlight output missing');" > demo.cjs
  3. 3

    Run the script and verify highlighted output

    Print the highlighted HTML and let the script verify that the output contains the hljs-tag class.

    node demo.cjs
Check the official README

Growth

Growth trends · Last 30 days

25,005 Stars

Trend data is still being collected.

Development activity

Last 90 days · weekly

Commits (last 30 days)
0
Open PRs
54

Development activity is still being collected.

Built with

Categories and tags

Categories

GitHub data

GitHub dataView detailed GitHub data

GitHub Topics

  • syntax-highlighting
  • language-grammars
  • highlighting
  • syntax-highlighter
  • javascript
Stars
25,005
Forks
3,752
Watchers
296
Open issues
65
Contributors
415
Owner type
Organization
Primary language
JavaScript
Repository last updated
Sep 6, 2026
Write a related article

Share a guide or use case for this OSS in Markdown. Articles are published after administrator approval.

Report incorrect information

Tell us if any listing information is incorrect or outdated.

After reading this page, do you know what to do next?