Cookies This site keeps only what it needs to work. There is no analytics and no advertising on it today, and nothing here follows you to other sites. Read the privacy policy

Choose what to allow
+92 312 8299940Free Quote
EN – Language: English
Free tool, nothing to install

Syntax Highlighter
Colour A Listing, Copy The Markup

This syntax highlighter breaks up a file into individual elements (strings, comments, keywords, numbers) and applies different colors to each element. The output can be copied in several ways: as an HTML string that has been "escaped", as a block of text for use in a word processor program, or as plain text without any formatting. Any code that is pasted into this tool will remain within the user’s web browser.

  • FreePrice
  • 12Languages
  • 4Outputs
  • NoneUploads

Syntax Highlighter

Colour a listing in twelve languages, then copy escaped HTML, a word processor block, plain text or the stylesheet

The output

If you use a screen reader, the plain text tab is the readable copy: the coloured ones carry a span around every token.

The six classes, and the colour each one names

Ready. Paste a listing, or press one of the sample buttons.

Your browser does all of the work here, in this tab. We upload nothing, store nothing and log nothing.
Add a link to this tool on your own site

Copy the code below and drop it into your page. It places a link to this free tool.

The short version

What This Syntax Highlighter Does

Colour can be seen as a way to say something about the content of a document. This makes a highlighted list easier to view. The user will know how big a document is before opening it.

This is the main purpose of this syntax highlighter. This process will split up the text into tokens, then work out the type of token each token is, and finally assign a color to each token’s classification.

It knows twelve languages, and it treats a string, a comment, a keyword, a number and a name as different things. Because the decision comes from a tokeniser rather than from a pattern match, a keyword inside a comment stays a comment.

Four outputs come out of one run. Escaped HTML to paste into a page, a word processor block, plain text, and a small stylesheet for the colours alone.

All of the highlighting is done within this single tab, so when you have an incomplete listing it will be colored the same as if it had been shipped.

How A Syntax Highlighter Splits Code Into Tokens

It reads through the whole text in one go. It carries both a state and a stack. Each time the reader encounters a character, it must work out if the character is part of a string, a comment, a number, or normal code. When the state changes, the reader will produce a token.

Diagram of four code lines and their tokens: a keyword inside a string or comment takes that colour, not keyword colour
The same word on three lines, coloured three ways, because the state decides.

A keyword list per language supplies the rest. The list is short on purpose, because the useful question is which words the language reserves. That reserved list is what the standard documents publish.

The reader has that state, so a word in a comment is not a keyword. That is the difference between a highlighter and finding and replacing. That is what you should check first if a listing with color does not appear correct.

A language with block comments that are nested needs a depth counter as opposed to a flag. A language that includes a template literal will need a stack. Both of these are used so that an inner delimiter cannot terminate an outer block.

The change to the text that the reader will get does not change the text itself. The copy of the original text you give is the exact same byte for byte as what was output from your terminal.

Why The Output Escapes Before It Colours

Markup is highlighted when it is entered into a text editor, and if you copy and paste markup into your web page, then that markup will run in the browser. So, before anything can happen, the angle brackets in your listing must be converted to entities.

There’s a lot more to code than what meets the eye. When you copy a snippet of code from an issue tracker, you are also copying a script tag. If you then paste that code into a web page without removing the script tag, you will have executed a stranger’s code.

To give the most accurate output, every output is escaped first and then colored second. Since the escaping occurs before the tool writing even one span, no listing may produce an element that was not part of the original listing.

A comment with a quote in it will go inside the span as opposed to being part of an attribute, so, there is no way for the comment to end any earlier than what was intended.

The reason you should copy the HTML output from here, rather than from another editor which uses color for display purposes, is because the colors appear the same and only one can be safely pasted.

The Twelve Languages, And What Each One Needs

All four use the same grammar as their sibling. JavaScript, TypeScript and JSON are so closely tied that a single reader can handle each one. Similarly, CSS and SCSS are handled by a single reader.

Syntax highlighter language picker open with twelve languages, some sharing a reader with a sibling language
There are twelve total languages, and four of these languages have to use a reader instead of having one that is unique to each language.

The C family includes a preprocessor line. When reading the source code, the reader reads the hash line first, then tokenizes the remaining portion of the line. For this reason, #include and #define are displayed in a different color than the surrounding source code.

Python and Ruby need you to be aware of how much indentation you are using. Both triple quoted strings and heredocs will continue past the line they begin on, so you must continue reading that string until it is closed.

The user is going to switch modes when they open the tag since PHP and HTML have different grammars. So, a single pass which ignored the mode change would be able to color the HTML as if it were PHP.

SQL and Bash are the final two of these four languages, and both of them are line-based. The way each language uses a comment character is different, so this is one example of how small details work out if a listed item will display correctly.

The Four Outputs, And When To Use Each

The initial method of encoding is Escaped HTML, which will be applied to the entire page. All tokens are converted into span elements with classes. The escaping of text within these elements converts them into entities; so, no extra processing is required when placing this content into a post.

Syntax highlighter output tabs: HTML with span classes, inline styles for word processors, plain text and a stylesheet
One listing, four shapes, and a byte count for each so the choice is not a guess.

The word processor block is the second. Because a word processor ignores your stylesheet, the colours arrive as inline styles on each span, which survives a paste into a document.

Plain text is the third, and it keeps the indent and the line count without a single colour. Use it when the listing is going into a terminal or a commit message, where markup would be noise.

The stylesheet is the fourth. It carries the twelve colour rules with no markup attached. So a site that already wraps its own spans can adopt the palette without adopting the output.

Video guide

The Syntax Highlighter in Action

This brief video shows each step from start to finish. Choose your language below, and switch on captions if they help.

Step by step

Colouring Your Code With The Syntax Highlighter

It takes four steps, and not one of them asks you to sign up.

  • Pick the language

    So, select one of the twelve. This setting will give you a list of keywords and comment markers. So, selecting the wrong option is typically why your listing appears only partially colored.

  • Paste the listing

    Then paste the code. The indent is kept as pasted, so a file that is already laid out reads the way it does in an editor.

  • Set the gutter and the theme

    In addition, work out if the output should include line numbers and choose either a light or a dark color scheme. Since both of these options will be part of the final markup, select them before copying.

  • Copy the output in the form you need

    Finally, take the HTML, the word processor block, the plain text or the stylesheet and then paste it where you want to put the listing.

Why this page

Reasons To Use This Syntax Highlighter

Here are five reasons, and the second matters most.

  • It escapes before it colours

    Because the text has been initially entity-escaped, no pasted listings can introduce their own elements or attributes. So, the resulting output can be safely used in a web page.

  • It carries state, not patterns

    A keyword inside a comment remains a comment, and a brace inside a string remains text. As such, the colors will reflect the true meaning of the language.

  • Four outputs from one run

    A page, word processor, terminal and stylesheet each need a unique form. One copy will cover whichever is required first.

  • Nothing uploads

    The tokenization and coloring of all of the tabs on your screen are handled within only one tab. So, an unreleased stylesheet will be processed exactly the same way.

  • The color rules are yours

    The stylesheet will output the color palette without any extra tags. So, if you are now using your own tags for styling, you can simply use the color palette from the stylesheet.

Rules of thumb

Habits That Keep A Listing Readable

Six habits that decide whether coloured code actually helps.

  • Show the shortest snippet that proves the point A thirty line listing gets skimmed and a six line one gets read. Because a reader is looking for the shape rather than the whole file, trim before you colour.
  • Keep the indent as the author wrote it Reindenting a snippet alters the appearance of the snippet within its original document. So, maintain the indentation level of the snippet so that readers can compare the snippet with the original.
  • Reach for the gutter only past ten lines Line numbers help when a reader has to cite a line. Under ten lines they are noise beside code that a reader can count.
  • Match the palette to the page A dark area within a light-colored article can distract readers’ eyes from your main point. Both color options are available, so select the color scheme that complements the surrounding content.
  • Copy the HTML rather than the rendered block When you drag a colored block out of your browser, you will lose all the classes that were applied to it and be left with a jumbled mass of inline styles. So, use the copy button to get the markup for the element that you can then read.
  • Keep a plain text copy for the terminal When you use markup in your commit message or within your shell session it will be displayed as text instead of as color. So, you should display the plain version of the output next to the colored version of the output.
Careful here

Six Ways A Highlighted Listing Goes Wrong

Each of these looks fine in the preview and fails where it lands.

  • Dropping raw markup straight into a page

    Watch out here. A listing pasted without escaping is markup the browser runs, and one script tag in a comment is enough. So use the HTML output rather than a copy from another editor.

  • Choosing the wrong language

    A list of keywords from one language will leave the words of another uncolored. The end product still appears to have some thought put into it, so it can easily be shipped as an error.

  • Expecting a template literal to end at a newline

    A backtick keeps a string open across lines. Hence one unclosed template at the top colours the rest of the file as a single string, which reads as a tool bug.

  • Colouring a diff as source

    The plus and/or minus sign at the beginning of each line does not form part of the language being used. Thus, you should paste the left-hand and right-hand portions of the text into two distinct locations, as each line’s first character would otherwise be incorrect.

  • Turning on the gutter for a copied snippet

    A reader that has copied a numbered list will have the numbers along with the code. If they attempt to paste it back into their program, it will fail to execute, so, keep the gutter on pages that are solely being read by readers.

  • Assuming the colours carry meaning

    A single color is not a strong indicator for someone who cannot see that color. Thus the word(s) will be more important than the palette, and a list should still be understandable even if no colors are used.

Questions

Syntax Highlighter Questions

Is this syntax highlighter free?

Yes. You never sign up, never hit a cap and never meet a paywall. So you colour as many listings as you like.

What languages can it highlight?

Twelve: JavaScript, TypeScript, JSON, HTML, CSS, SCSS, PHP, Python, Ruby, Java, SQL, and Bash. Four of these are shared with another.

Can I safely paste the output into a page?

The HTML output will be, since the tool first encodes the text into entities before writing each individual span. This means that when a user pastes a script tag within their snippet, it will appear as text, not as an element.

Where should the angle brackets go?

The entire purpose of having escaped output is because the browsers display these as entities, not interpret them as markup.

Why is a keyword in my comment not coloured?

The reason for doing so is that it’s in a comment, which means the reader will know. A spelling-only based highlighter would be wrong here; but the present one can make decisions based upon its own internal state.

Can I get the result without any markup?

Yes, the plain text output will maintain both the indentation and the number of lines without adding any color. This makes it perfect for use in a commit message or terminal.

Does it work in a word processor?

Yes, through the word processor output. A document disregards a style sheet; so, the colors appear in-line as styles for every span.

Can I use the colours on my own site?

The twelve rules of the stylesheet do not carry any HTML tags, so you will be able to apply the colors from the palette to your own tags.

Is the code I highlight uploaded anywhere?

No. The tokenization and the colorization take place within this browser tab. So, no unreleased files are sent across the network.

Will it alter my code?

No, the exact output will be exactly what was entered into the field. The only difference between the two outputs (plain and colored) is the span tags that surround the text.

Can I highlight a whole file?

Yes. A file that has several hundred lines will quickly fill with color. Your computer is the limiting factor, not the server’s quota.

Will it look for errors in my code?

No. A highlighter answers what a token is, not whether the program is valid. So run the validator for that question.

Can I highlight a diff?

Not exactly as you would expect since the use of "+" or "-" at the beginning of each line does not form part of the language syntax. So, it is best to paste both parts separately.

Can it add line numbers?

Yes, once you enable this option. The gutter will be included in the output, so please make sure to turn off this option before you copy if you are providing a snippet of code that a reader can use.

What is the light and dark option for?

The color scheme will change to match the page environment, but the token positions remain constant. Only the colors will shift.

Does it handle a template literal across lines?

Yes, because the reader leaves the string "open" with a new line, multi-line templates will be colored like single strings, instead of being treated as code.

Can I colour a listing for a slide?

The output of the word processor is what was used. Paste the section of text into the file and the colors remain.

Why does my listing look half coloured?

The usual cause is an unclosed string or comment above it, which swallows the lines after it. So check the top of the paste first.

Does it run on phones too, or only on desktops?

Yes. The panes stack and the tabs wrap into rows. So a short listing is possible away from a desk, though a long file is easier on a keyboard.

Is an account or a browser add-on needed?

No. There is nothing to sign up for, no plugins, nor extensions that will need to be added. Thus, once the listing has been copied to your clipboard, you may then close out of that browser tab.

Keep going

Handy Companion Tools For This Job

Four pages the same job usually leads to.

  • HTML entity encoder

    On its own, the "escape" portion of this process is what matters most. Since a snippet may contain HTML tags, it is best practice to first encode the angle brackets.

  • Code beautifier

    The listing looks more professional after the layout has been finalized. So, before coloring the file, make sure to re-indent the file.

  • JavaScript minifier

    Once the block is placed on a page, the script that accompanies it can reduce in size. As a result, the download time that a user experiences becomes shorter.

  • HTML minifier

    Once the block is on a page, the markup around it can shrink. Since a browser downloads every comment, that is the last step.

Colour The Listing And Copy The Markup

Pick the language, paste the code, choose a palette and take the output shape you need. Nothing uploads, and the tool escapes the text before it colours anything, so the block is safe to put on a page. Most listings are ready before the tea goes cold.

Prefer Denwix on GoogleReview Denwix on Google