Skip to main content
L
Loopaloo
Buy Us a Coffee
All ToolsImage ProcessingAudio ProcessingVideo ProcessingDocument & TextPDF ToolsCSV & Data AnalysisConverters & EncodersWeb ToolsMath & ScienceGames
Guides & BlogAboutContact
Buy Us a Coffee
L
Loopaloo

Free online tools for developers, designers, and content creators. Your files are processed in your browser and are never uploaded - no accounts required. A few network utilities (like What's My IP and Currency Converter) call public APIs to do their job and say so on their pages.

support@loopaloo.com

Tool Categories

  • Image Tools
  • Audio Tools
  • Video Tools
  • Document & Text
  • PDF Tools
  • CSV & Data
  • Converters
  • Web Tools
  • Math & Science
  • Games

Company

  • About Us
  • Contact
  • Blog
  • FAQ

Legal

  • Privacy Policy
  • Terms of Service
  • Disclaimer

Support

Buy Us a Coffee

© 2026 Loopaloo. All rights reserved. Built with privacy in mind.

Privacy|Terms|Disclaimer
  1. Home
  2. Document & Text
  3. Code Syntax Highlighter
Add to favorites

Code Syntax Highlighter

Syntax highlighting from a real lexer per language, so a URL inside a string is not read as a comment, with 22 languages, 7 themes, and HTML, PNG and copy-as-markup export

Text processed locallyMore document & textJump to full guide

Related reading

  • Keyboard Shortcuts Every Developer Should Know9 min read
  • Code Minification: Reducing File Sizes for Faster Web Performance10 min read

Initializing in your browser…

You might also like

QR Code Reader & Scanner

Scan QR codes from an image or your camera, in this tab. Reads every code in a picture, rescues a faded or transparent one and says which step worked, and parses WiFi, vCard, calendar, geo and payment payloads by their published grammars.

Image Color Palette Extractor

Extract a palette whose every colour is one the image actually contains, with the share of the picture each one covers. Median cut, k-means in CIE Lab or plain frequency, each named.

Code Minifier & Beautifier

Minify or beautify JavaScript, TypeScript, CSS, HTML, JSON, XML and SQL with a real lexer per language, so a comment inside a string is not deleted and a line break the code depends on is kept, with the byte saving measured

Code Syntax Highlighter: a worked example

A JavaScript line assigns a URL to a variable and has a comment after it. A pattern-based highlighter reads the two slashes of the URL as the start of a comment and greys out the rest of the line.

Snippet

const u = "https://example.com/a"; // real
What Code Syntax Highlighter produces

Result

The URL is coloured as a string and only the trailing // real is a comment.

Every language here is read by a lexer rather than by a chain of patterns, so a comment marker inside a string is string content and a quote inside a comment opens nothing. The tokens are checked to cover every character of your input exactly once, and the page says so. Copy the code, copy the highlighted markup with the colours written into it, or export a standalone HTML file or a PNG.

About the Code Syntax Highlighter

Paste code in any of 22 languages and get it coloured correctly, then copy it, copy the highlighted markup, or export a standalone HTML file or a PNG image. Every language is read by a lexer rather than by a chain of pattern replacements, which is the difference between a highlighter that mostly works and one that gets a URL inside a string wrong.

How Syntax Highlighting Works Here

A highlighter makes one claim: it knows what every character of your code IS. A regular expression cannot make that claim, because it cannot tell a comment marker that starts a comment from the same two characters sitting inside a string. Put a URL in a JavaScript string with a real comment after it and a pattern-based highlighter colours the URL, the closing quote, the semicolon and the comment as one long comment.

So nothing here works that way. Each language is tokenised: the source is walked once, left to right, and every character comes out inside exactly one token that knows what it is. Six languages are read by lexers this project already had for its minifier and its SQL formatter: JavaScript and TypeScript (which includes deciding whether a slash divides or opens a regular expression, and reading the expressions inside a template literal as code), CSS and SCSS (including the unquoted url() form), HTML and XML (where a greater-than sign inside an attribute value does not end the tag, and a close tag inside a script string is not markup), and SQL, which offers all five dialects because they disagree about what ends a string literal. JSON is read by the same tokenizer the JSON formatter uses and YAML by the yaml package's own lexer. Markdown is read as block structure, so a number sign inside a fenced code block is not a heading. The remaining twelve (Python, Java, C++, C#, Go, Rust, Ruby, PHP, Swift, Kotlin, Bash and PowerShell) are read by a scanner driven by a rule table stated per language, and each language's panel names the reference its rules come from and anything they do not cover.

Those rules are not decoration. Rust, Swift and Kotlin nest block comments and C, Java and Go do not. A shell single-quoted word has no escape at all, so a backslash in one is a backslash. PowerShell escapes with a backtick, not a backslash, so a Windows path inside a double-quoted string has no escapes in it. Python treats the r in a raw string as part of the string token, and reads the expressions inside a formatted string as code. Each of those was checked against that language's own tokenizer or against a second statement of its rules written independently.

The result carries a self check: the tokens have to cover every character of your input exactly once and spell it back unchanged, and the page shows whether they did. Seven themes are available, and the colours are real colour values rather than class names, so the HTML you copy or export renders the same colours anywhere you paste it.

How to use

  1. 1Paste your source code into the editor, or upload a file and the language is picked from its extension
  2. 2Choose the language from the dropdown (and the SQL dialect, if the language is SQL)
  3. 3Pick one of the 7 themes, and set line numbers, word wrap and font size
  4. 4Open "How this language is read" to see which lexer reads it and what it does not cover
  5. 5Copy the code, copy the highlighted markup, or export a standalone HTML file or a PNG image

Key features

  • 22 languages, each read by a lexer rather than by pattern matching, with the reference for its rules named on the page
  • A self check on every run: the tokens cover every character exactly once and spell your input back unchanged
  • Five SQL dialects, because they disagree about what ends a string literal and what delimits an identifier
  • 7 themes: Dark, Light, Monokai, GitHub Dark, Dracula, Nord and Solarized Dark
  • Copy the highlighted markup with the colours written into it, so it renders anywhere you paste it
  • Export a standalone HTML file or a PNG image, both drawn from the same tokens as the preview
  • Optional line numbers, word wrap and font size, and a file upload that picks the language from the extension

When to reach for this

  • Blog posts and tutorials

    Generate syntax-highlighted snippets for technical writing, and copy the markup with its colours already in it rather than a set of class names your site may not define.

  • Presentations and slides

    Export a PNG of the snippet at the font size and theme you chose, drawn from the same tokens the preview shows.

  • Documentation and wikis

    Embed correctly coloured examples, including ones holding URLs, regular expressions and quoted text that trip pattern-based highlighters.

  • Checking what a snippet actually says

    Because the colouring comes from a lexer, an unterminated string or a comment that swallows the rest of a file shows up immediately as a whole block in the wrong colour.

Frequently asked questions

Which languages are supported?

Twenty-two: JavaScript, TypeScript, Python, Java, C++, C#, Go, Rust, Ruby, PHP, Swift, Kotlin, HTML, CSS, SCSS, JSON, YAML, XML, SQL, Bash, PowerShell and Markdown.

How accurate is the highlighting?

It is measured. A corpus of snippets, each chosen because a pattern-based highlighter gets it wrong, is scored against an independent decider per language: TypeScript's own scanner for JavaScript and TypeScript, Python's own tokenize module for Python, Python's html.parser for HTML, PyYAML for YAML, and a second statement of the rules for the rest. The current version agrees with those deciders on every character of all 44 snippets, both in the module and through this page.

Why does SQL ask for a dialect?

Because the dialects disagree about what ends a string. Only MySQL treats a backslash inside a literal as an escape, the identifier delimiter differs across all five, and PostgreSQL alone has nested block comments and dollar quoting. Getting that wrong means a highlighter can decide a string ends in the wrong place.

Can I use the highlighted output on my website?

Yes. "Copy HTML" gives you the markup with the colours written into each element, and "Export HTML" gives you a standalone file. Neither depends on a stylesheet you have to add.

What is the green line under the preview?

It is the tool checking itself. The tokens it colours from have to cover every character of your input exactly once and spell your input back unchanged; the line reports whether they did. If it ever turns red, that is a fault worth reporting with the code that caused it.

Is the code I paste sent anywhere?

No. Everything runs in your browser.

Related tools and how they differ

  • Markdown Editor & Preview: Authors and renders full Markdown documents with fenced code blocks and live preview; use it when the code lives inside a written document.
  • Code Minifier & Beautifier: Minifies and beautifies the same languages over the same lexers; use it when you want to change the code rather than colour it.
  • HTML ↔ Markdown Converter: Converts between HTML and Markdown with style options for headings, lists, and code fences; use it for format conversion, not snippet styling.
  • Markdown Table Generator: Creates GFM tables from a visual grid with column alignment and escaped pipes; use it when you need table syntax instead of highlighted code.

Further reading

  • Keyboard Shortcuts Every Developer Should Know9 min read
  • Code Minification: Reducing File Sizes for Faster Web Performance10 min read

Private by design

Your text is processed locally in the browser. Nothing you paste or open is transmitted or logged.