FormatterHQ

Code Syntax Highlighter

Turn source code into syntax-highlighted HTML with inline styles, so the colors survive when you paste it into a blog, CMS, email or document.

Input JAVASCRIPT
Output HTML
Ready.

How to use the Code Syntax Highlighter

  1. Paste your source code into the editor.
  2. Choose the programming language, a light or dark theme and whether to show line numbers.
  3. Highlight the code and check the preview.
  4. Copy the generated HTML and paste it into your page, CMS or email.

Highlighted code that works anywhere

Most syntax highlighting on the web is done by JavaScript libraries and CSS themes loaded on the page. That is fine for your own site, but it fails where you cannot add scripts or stylesheets: a hosted blog platform, a CMS rich-text field, a newsletter or a slide. This code highlighter produces self-contained HTML: every color is an inline style attribute, so the snippet looks the same wherever you paste it.

Example

A line of JavaScript:

const total = items.reduce((sum, x) => sum + x.price, 0); // cents

becomes a <pre> block where keywords, strings, numbers, comments and function names are wrapped in spans such as:

<span style="color:#cf222e">const</span> total = items.<span style="color:#8250df">reduce</span>((sum, x) =&gt; …

Supported languages

JavaScript, TypeScript, JSON, Python, PHP, Java, C, C++, C#, Go, Rust, Ruby, Kotlin, Swift, SQL, CSS, HTML, XML and shell scripts. The highlighter recognizes each language's keywords, strings, comments, numbers and function calls; for HTML and XML it colors tags, attributes and values.

It is a lightweight, token-based highlighter rather than a full language parser. The result is accurate for typical code, but unusual constructs, such as a regular expression containing quote characters, may occasionally be colored differently than in an IDE.

Options

  • Language – choose the one that matches your code for correct keywords.
  • Theme – a light theme with a GitHub-like palette or a dark theme inspired by One Dark. Pick the one that contrasts with the page where the code will appear.
  • Line numbers – adds a gutter with line numbers, useful for tutorials that refer to specific lines.

Where to use it

  • Blog posts and documentation on platforms that strip scripts or custom CSS.
  • HTML email newsletters, where inline styles are the only reliable styling method.
  • Presentations and word processors – open the preview, copy it and paste as rich text to keep the colors.
  • Static pages where you want highlighted code without loading a highlighting library.

How it compares with highlighting libraries

Libraries such as Prism, highlight.js and Shiki run on your site and style code with CSS classes, which keeps pages small and lets you switch themes globally. They are the better choice when you control the website template. This tool is for the opposite situation: one-off snippets that must look right in places where you control nothing but the HTML itself. The output also has no dependencies, so it will keep rendering correctly years from now, even if the platform changes its themes.

Tips

  • Format the code before highlighting; the highlighter keeps your whitespace exactly. The JavaScript formatter and other formatters on this site can help.
  • Keep snippets short and focused. Long listings are easier to read in a repository link.
  • Inline styles make the HTML larger than class-based output. That is the price of portability and is rarely a problem for snippets.

To simply read a file with highlighting and line numbers, use the source code viewer. For JSON specifically, the JSON syntax highlighter is tuned for that format. Code is processed in your browser and never uploaded.

Frequently asked questions

Why use inline styles instead of CSS classes?
Inline styles travel with the HTML. When you paste the snippet into a blog editor, CMS or email, it keeps its colors even though the destination does not load a highlighting stylesheet.
Which languages are supported?
JavaScript, TypeScript, JSON, Python, PHP, Java, C, C++, C#, Go, Rust, Ruby, Kotlin, Swift, SQL, CSS, HTML, XML and shell scripts.
Can I paste the highlighted code into Word or Google Docs?
Yes. Copy the rendered preview rather than the HTML source, then paste it as rich text; most editors keep the colors and monospace font.
Does it escape special characters?
Yes. Angle brackets, ampersands and other special characters in your code are escaped, so the snippet displays correctly and cannot be interpreted as HTML.

Last updated October 3, 2026

Related tools

Source Code Viewer View source code with syntax highlighting and line numbers. Open any code file or paste it - HTML, PHP, JS, Python and more. HTML Entities List Searchable list of 1,400+ named HTML character entities with decimal and hex codes, code points and CSS escapes. Click to copy. HTML Formatter Beautify or minify HTML online. Fixes indentation of tags, inline CSS and scripts. HTML Link Generator Create an HTML anchor tag with link text, title, target _blank, nofollow or sponsored rel and simple inline styling. HTML Pretty Print Opinionated HTML pretty print with Prettier: closes implied tags, enforces a line width and gives the same output for any input layout. HTML Table Generator Generate HTML table code with any number of rows and columns, header row, caption, border and padding - with live preview. HTML to BBCode Converter Convert HTML into forum-friendly BBCode: bold, links, images, lists, quotes, tables, code blocks and inline colours. HTML to Jade Converter Turn HTML into Jade syntax for legacy .jade views, using only markup that also keeps working after an upgrade to Pug. HTML to JSX Converter Convert HTML markup to valid JSX for React: className, htmlFor, style objects, self-closing tags and comments handled automatically. HTML to PHP Converter Convert HTML into PHP echo statements, a string variable or a heredoc block with every quote and dollar sign safely escaped. HTML to Pug Converter Convert HTML to Pug template syntax: indentation-based tags, #id and .class shortcuts, attributes and text blocks. HTML to Text Converter Extract readable plain text from HTML: keeps paragraphs, headings, lists and tables, drops tags, scripts and styles.