Code Syntax Highlighter
Color code in over 30 languages, with line numbers and a light or dark theme, and copy it as HTML with inline styles for blogs, email and slides.
How to highlight code
Paste your code
Paste or type your code into the box, or press Try an example.
Choose language and theme
Leave language on detect, or pick it; choose light or dark and line numbers.
Copy the HTML
It has inline styles, so it looks right wherever you paste it.
Worked example
This is what Code Syntax Highlighter gives for its own sample values. Open the tool above and change anything to try your own.
Code
import { readFile } from "node:fs/promises";
// Count the words in a file
export async function countWords(path: string): Promise<number> {
const text = await readFile(path, "utf8");
return text.split(/\s+/).filter(Boolean).length;
}
console.log(await countWords("README.md"));- Language
- Detect automatically
- Theme
- Light
- Line numbers
- No
HTML with inline styles (pastes into blogs, email and slides)
<pre style="margin:0;padding:16px;border-radius:8px;overflow:auto;background:#f6f8fa;color:#24292f;font:14px/1.5 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace"><code><span style="color:#cf222e">import</span> { readFile } <span style="color:#cf222e">from</span> <span style="color:#0a3069">"node:fs/promises"</span>;
<span style="color:#6e7781;font-style:italic">// Count the words in a file</span>
<span style="color:#cf222e">export</span> <span style="color:#cf222e">async</span> <span style="color:#cf222e">function</span> <span style="color:#8250df">countWords</span>(<span style="color:#24292f"><span style="color:#0550ae">path</span>: <span
...Result
- Language
- typescript
When to use Code Syntax Highlighter
A blog editor, newsletter tool or slide deck does not highlight code and you want colored snippets anyway.
You are writing documentation in a tool that only accepts HTML and need code to look as it does in an editor.
Tips for a better Code Syntax Highlighter result
Choose the language rather than relying on detection for short snippets, where several languages look alike.
Pick the theme that matches the page the code goes on; dark code on a white page draws the eye, which may or may not be what you want.
Code Syntax Highlighter: limits and what to check
Email clients may change fonts and ignore some styles, so send yourself a test before a newsletter goes out.
Line numbers are part of the HTML, so readers who copy the code also copy the numbers in some apps.
About Code Syntax Highlighter
Get colored code for a blog post, documentation, an email or a slide. Highlighting is done by highlight.js in your browser, and every color is written as an inline style rather than a class, so the result needs no stylesheet and survives email clients and content editors.
FAQs
Which languages are supported?
Over 30 common ones, including JavaScript, TypeScript, Python, Java, C#, Go, Rust, SQL, shell, YAML and JSON.
Why is the wrong language detected?
Short snippets look alike. Pick the language from the list for the best result.
Can I get an image instead?
Use Code to Image Converter for a picture of the code.