# React Syntax Highlighter — card for AI agents

React component for syntax highlighting code with Prism.js or Highlight.js.

Category: Markdown, editors and content · npm package `react-syntax-highlighter` · latest version 16.1.2 (checked 2026-11-01)
Install: `npm install react-syntax-highlighter`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## React Syntax Highlighter
- Take the `style` object from `react-syntax-highlighter/dist/esm/styles/hljs` or `.../styles/prism` to match the import in use, as the README's examples pair them.
- For JSX code, use the `Prism` or `PrismLight` export.
- With `Light` or `PrismLight`, call `SyntaxHighlighter.registerLanguage(name, lang)` for every language and always pass a `style`; the light builds provide no default style.
- Use `PrismAsyncLight` or `LightAsync` only with a bundler that supports dynamic import, and expect unhighlighted code while chunks load.
- Set `wrapLines` to true when using `lineProps`; `showInlineLineNumbers` has no effect unless `showLineNumbers` is on.
- To style with highlight.js CSS files, pass `useInlineStyles={false}` so the component appends classNames instead of style objects.
- In TypeScript projects, add `@types/react-syntax-highlighter` as a dev dependency.

## What it is
- React Syntax Highlighter is a React component that takes a code string and renders it highlighted. The repository describes it as a "syntax highlighting component for react with prismjs or highlightjs ast using inline styles". It was created in 2016 and is MIT licensed. The latest listed release, v16.1.2, fixes ESM imports that were "still missing `.js` with highlight.js".
- It sits on two parsers by wooorm: lowlight for highlight.js languages and refractor for Prism languages. The README says other React highlighters insert markup with `dangerouslySetInnerHTML` or change the DOM by hand. The maintainer writes that this one uses a syntax tree to build the virtual DOM instead. Themes are JavaScript objects passed through the `style` prop, and CSS classes are an opt-in alternative.
- There are several entry points. The default import, a `Prism` import, `Light` and `PrismLight` builds where you register each language yourself, and async versions of the two light builds that load later.

## Caveats
- Default import is heavy; light build is manual: The README warns that the standard import "can have a fairly large footprint". The light builds are the alternative, but you import and register every language yourself and pass a style.
- Async build shows plain code first: `PrismAsyncLight` and `LightAsync` need a bundler that supports dynamic import. While the chunks load, code appears with line numbers but without highlighting.
- Types are a separate install: TypeScript users add `@types/react-syntax-highlighter` as well. The README recommends it to prevent TypeScript or ESLint errors.
- Two answers on a Prism light mode: The Prism section says a light mode "is not yet supported". The same README later documents a `PrismLight` build, so parts of the docs may lag behind the code.

## Numbers (AgentGid data)
- Gid Score: 65.2 (#664 of all tools, 32 of 149 in its category)
- Used in 45 public projects set up for AI coding agents (0.7%)
- Downloads last week: 9,943,750 (as of 2026-11-24), +27.0% over 4 weeks
- GitHub stars: 4,675 (as of 2026-11-24)
- Last push: 2026-10-08

## Often used with
clsx 93.3%, Lucide React 93.3%, Tailwind Merge 93.3%, Class Variance Authority 86.7%, Next.js 80.0%, Radix UI 77.8%

## Checked alternatives (same job)
- Shiki: https://agentgid.com/tools/shiki/agent.md
- highlight.js: https://agentgid.com/tools/highlight-js/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/react-syntax-highlighter/
- Homepage: https://github.com/react-syntax-highlighter/react-syntax-highlighter#readme
- Repository: https://github.com/react-syntax-highlighter/react-syntax-highlighter
- Source: https://github.com/react-syntax-highlighter/react-syntax-highlighter#readme
- Source: https://github.com/react-syntax-highlighter/react-syntax-highlighter
- Source: https://github.com/react-syntax-highlighter/react-syntax-highlighter/releases

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
