React Syntax Highlighter
React component for syntax highlighting code with Prism.js or Highlight.js.
2. Maintained
Latest GitHub release Oct 8, 2026.
github.com/react-syntax-highlighter/react-syntax-highlighter3. Used by agents' projects
Dependency in 45 public GitHub projects set up for AI coding agents that we scanned (0.7%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What React Syntax Highlighter does
React Syntax Highlighter builds React elements from a highlight.js or Prism syntax tree instead of injecting an HTML string, and ships its themes as JavaScript style objects so a page needs no stylesheet tag.
React Syntax Highlighter popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How React Syntax Highlighter is used
- React Syntax Highlighter is a dependency in 45 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (0.9% of the 4,867 JavaScript/TypeScript ones), #18 of 149 in markdown, editors and content.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 292; those are left out of every share on this page.
- The most used alternative in our scan is Shiki (85 projects).
- Projects that use it most often also use clsx (93.3%), Lucide React (93.3%), Tailwind Merge (93.3%).
By coding agent
Often used with
React Syntax Highlighter in practice
Strengths
The maintainer writes that the component builds the virtual DOM from a syntax tree. This allows "updating only the changing DOM instead of completely overwriting it on any change" and the use of pure function components.
Styles are JavaScript objects passed as a prop. The README says all styles supported by highlight.js have been ported. To use highlight.js CSS files instead, set <code>useInlineStyles</code> to <code>false</code> and the component adds classNames.
Importing <code>Prism</code> switches to refractor, which uses Prism.js language definitions. The README says this is beneficial "especially when highlighting jsx, a problem long unsolved by this module."
With <code>wrapLines</code> on, each line gets its own span. <code>lineProps</code> passes props to that span as an object or as a function of the line number. The README links a diff demo to show what <code>wrapLines</code> enables.
Watch out for
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.
<code>PrismAsyncLight</code> and <code>LightAsync</code> need a bundler that supports dynamic import. While the chunks load, code appears with line numbers but without highlighting.
TypeScript users add <code>@types/react-syntax-highlighter</code> as well. The README recommends it to prevent TypeScript or ESLint errors.
Highlight a snippet with a highlight.js theme
import SyntaxHighlighter from 'react-syntax-highlighter';
import { docco } from 'react-syntax-highlighter/dist/esm/styles/hljs';
const Component = () => {
const codeString = '(num) => num + 1';
return (
<SyntaxHighlighter language="javascript" style={docco}>
{codeString}
</SyntaxHighlighter>
);
};More about React Syntax Highlighter
Funding
- GitHub Sponsors: https://github.com/conorhastings
- 1 GitHub sponsors
Packages around it
- tailwind-merge: Tailwind class merging
- clsx: className joining
- class-variance-authority: component variants
- lucide-react: icons
- @radix-ui: UI primitives
- tailwindcss: utility CSS
More in Markdown, editors and content
Alternatives
React Syntax Highlighter This page
Beautiful syntax highlighter powered by TextMate grammars with superior accuracy.
Syntax highlighting library with automatic language detection for code blocks.
Get started
Install it.
npm install react-syntax-highlighterRules for your agent
## 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.