Code Highlighter
WM-132Paste code, choose its language and get syntax-highlighted HTML. Copy HTML gives a <pre> block with the colors written inline, so it keeps its look wherever you paste it.
Runs in your browser. Nothing is uploaded.
Code
Highlighted
How to use it
- Paste your code into the input box, or open a source file.
- Pick the language from the Language list. Nothing guesses it for you.
- Choose the Light or Dark theme and turn on line numbers if you want them.
- Press Copy HTML, or Download to save the highlighted block as an .html file.
Languages and what gets colored
The tool has small built-in tokenizers for JavaScript, TypeScript, Python, Java, C and C++, C#, Go, Rust, PHP, Ruby, SQL, Bash, CSS, HTML, XML, JSON and YAML. Comments, strings, keywords, numbers, literals such as true and null, type names, function calls, variables, tags and attributes each get their own color. In HTML, the code inside script and style elements is colored as JavaScript and CSS.
What it does not do
It colors tokens; it does not parse or run the code. So it never reports a syntax error, and an unusual construct can come out a little off, for example a regex that looks like division. It does not format or re-indent the code, and it does not detect the language. Tabs are kept as tabs and Windows line endings become plain line feeds.
Pasting into a page, a CMS or an email
The copied HTML is one <pre><code> block where every colored token is a span with a style attribute. It needs no stylesheet and no script, so it works in a blog editor that accepts HTML, in many email clients and in slide tools that take HTML. Line numbers are part of the block when you turn them on.
Questions people ask
Which languages does the code highlighter support?
Seventeen: JavaScript, TypeScript, Python, Java, C and C++, C#, Go, Rust, PHP, Ruby, SQL, Bash and shell, CSS, HTML, XML, JSON and YAML. Pick one from the Language list. C and C++ share one setting, and HTML also colors the JavaScript and CSS inside script and style tags.
Will the colors survive when I paste the HTML elsewhere?
Yes, in most places that accept HTML. Copy HTML writes each color as an inline style on a span, so the block does not depend on this site's stylesheet. Some email clients and editors strip styles or pre tags, so check the result where you paste it.
Does it check my code for errors?
No. The highlighter splits the text into tokens such as strings, comments and keywords and colors them. It does not parse the program, so broken code is colored as far as the tokens go and no error is shown. Use a compiler or linter for that.
Is my code uploaded anywhere?
No. The tokenizer runs in your browser tab. The code you paste, the highlighted output and the file you download stay on your device, and the page makes no request with your code in it.
Why is part of my code colored wrongly?
The tokenizers are small and rule-based, not full parsers. Rare constructs, such as nested template strings, heredocs or a language feature newer than the rules, can be split in a slightly different place. Picking the language the code is actually written in gives the cleanest result.
About this tool
Highlights these languages with small built-in tokenizers: JavaScript, TypeScript, Python, Java, C and C++, C#, Go, Rust, PHP, Ruby, SQL, Bash, CSS, HTML, XML, JSON and YAML. It colors comments, strings, keywords, numbers, literals, types, function calls, variables, tags and attributes; it does not parse the code, so it never reports syntax errors and an unusual construct can be colored a little off. You pick the language; nothing guesses it. Copy HTML and Download give a <pre> block with inline colors, so it keeps its look when pasted into a page, a CMS or an email. Tabs are kept and Windows line endings become plain line feeds.