Code Syntax Highlighter
Paste code, choose a language, get highlighted HTML for blogs, emails, and documentation.
How to Use the Syntax Highlighter
- Paste your code into the input area or click "Try Example" to load a JavaScript demo.
- Select a language — JavaScript, Python, HTML, CSS, SQL, or Auto-detect.
- Choose output format — Styled HTML (external CSS), Inline Styled (for emails), or CSS Classes only.
- Set theme and line numbers — Dark or Light code theme, optional line numbers.
- Copy the HTML from the output panel and paste it into your blog post, email, or documentation.
Output Format Comparison
- Styled HTML — wraps tokens in
<span class="kw">etc. You must include the CSS classes in your page's stylesheet. Best for CMS blogs and static sites where you control the CSS. - Inline Styled HTML — embeds
style="color:#cba6f7"directly on each span. No external CSS needed. Best for HTML email newsletters (Gmail, Outlook, Mailchimp). - CSS Classes HTML — outputs only the semantic class names (
.kw,.str,.num, etc.) without any colors. Write your own stylesheet for full theme control.
Language Token Reference
- Keywords — language reserved words (
if,function,def,SELECT) - Strings — single-quoted, double-quoted, and template literals
- Numbers — integer and floating-point literals
- Comments — single-line (
//,#,--) and multi-line (/* */,) - Function names — identifiers immediately followed by
( - Operators — arithmetic and logical symbols
- HTML tags and attributes — in HTML mode, tag names and attribute names are coloured separately
Use Cases
- Blog posts — add syntax-highlighted code snippets to WordPress, Ghost, Substack, or any CMS that accepts raw HTML
- Email newsletters — use inline-styled output to send code to subscribers via Mailchimp, ConvertKit, or Beehiiv
- Documentation — embed highlighted examples in Notion, Confluence, or GitBook
- Slide decks — paste inline-styled HTML into Google Slides or PowerPoint's HTML editor for styled code blocks
- Stack Overflow answers — copy the HTML to use in answers that accept formatted code
How the Tokenizer Works
This tool uses a regex-based tokenizer that processes code in a single pass. Tokens are matched in priority order: multi-line comments first, then single-line comments, then string literals, then numbers, then function calls, then keywords, then operators. This order ensures that code inside strings and comments is not re-tokenized. The approach is lighter than a full parser but handles the vast majority of real-world code snippets correctly.
Limitations
Regex-based tokenization has edge cases: very complex templates, nested quotes, or unusual Unicode identifiers may not highlight perfectly. For production documentation where precise highlighting matters, consider integrating a full library like Prism.js or Highlight.js. This tool is optimised for quick one-off formatting rather than being a build-time plugin. For more Markdown and code tools, see our Markdown Preview and Diff Checker.