Back to articles

    What Is Syntax Highlighting? How It Works and Popular Themes

    November 14, 2026•7 min read•Guide

    Syntax highlighting colors code by role: keywords, strings, comments. Learn how it works, how popular themes compare and how to keep code images readable.

    Picbolt Screenshot Tool

    Syntax highlighting colors source code by what each piece of it is: keywords in one color, strings in another, comments in a third, and so on. It changes only how the code looks on screen, not what the code does, and it lets you see the structure of a program at a glance.

    Most code editors, documentation sites and code-image tools do it. Two things decide what you see: the rules for the programming language, and the color theme.

    What syntax highlighting is

    Take this short JavaScript function:

    // Greet a user
    function greet(name) {
      const count = 3;
      return `Hello, ${name}`;
    }
    

    A highlighter sorts that text into categories, usually called tokens:

    TextToken type
    // Greet a usercomment
    function, const, returnkeyword
    greetfunction name
    nameparameter / variable
    3number
    `Hello, ${name}`string (with an embedded expression)
    { } ( ) ;punctuation

    Each category gets its own color or style. The code underneath is still plain text. Open the file in a basic text editor and the colors disappear, because they were never part of the file.

    How syntax highlighting works

    A highlighter goes through three steps:

    1. It identifies the language. Usually from the file extension (.py, .js) or a setting you pick. If it guesses wrong, or has no rules for that language, you get plain uncolored text.
    2. It splits the code into tokens. The language rules say what counts as a keyword, where a string starts and ends, what a comment looks like, and so on.
    3. It applies a theme. The theme maps each token type to a color, and sometimes to bold or italic.

    The rules come in a few flavors:

    • Pattern-based grammars match text with regular expressions. TextMate grammars (used by VS Code and Sublime Text) and web libraries such as Prism and highlight.js work this way. They are fast and cover many languages, but they read the code's shape, not its meaning.
    • Parser-based highlighting builds a real syntax tree of the code. Tree-sitter, used by editors such as Neovim and Zed, is the best-known example. It copes better with nested or unusual code.
    • Semantic highlighting adds information from a language server, which understands your whole project. A parameter, a local variable and a class name can then get different colors even where the grammar alone can't tell them apart. VS Code supports this on top of its grammars.

    Highlighting is not error checking. It does give one useful hint: if the rest of your file suddenly turns string-colored or comment-colored, you probably left a quote or a block comment unclosed.

    The same code can look very different depending on the theme. Here is how several well-known themes look in their original editors. Each tool reimplements them slightly differently, so exact shades vary.

    ThemeBackgroundLookWorks well for
    DraculaDark gray-purplePink keywords, yellow strings, green function names, purple numbersDark-mode screens, social posts
    MonokaiVery dark olive-grayBright pink keywords, yellow strings, green function namesColorful, high-contrast snippets
    NordDark blue-grayMuted frosty blues and teals, soft accentsCalm, low-glare reading
    Gruvbox DarkWarm dark brown-grayEarthy reds, oranges, yellows and greensLong sessions, retro feel
    GitHub LightWhiteRed keywords, dark blue strings, purple function namesDocs, print, projectors
    GitHub DarkDark grayGitHub's colors adapted for dark modeMatching GitHub screenshots
    VS Code DarkDark grayBlue keywords, orange-brown strings, yellow function names, green commentsCode most developers recognize
    Xcode Dark / LightDark or whiteApple's Xcode lookSwift and Apple-platform posts
    A simple rule for choosing: use a dark theme if your audience mostly reads in dark mode, and a light theme if the code will sit in white documentation, a printed handout or a slide on a projector.

    What happens to highlighting in a code image

    When you share code as an image (on X, LinkedIn, a slide or a blog), the highlighting is baked in. The colors become pixels, which changes a few things:

    • The reader can't change the theme. Whatever you choose is what everyone sees, on every screen.
    • Readers can't reliably copy or search the code. If people need to run it, also share it as text: a gist, a repo link or a code block in the post.
    • Screen readers can't read it. Write alt text that says what the code does, or paste the key lines next to the image.
    • JPEG compression blurs small colored text. Export as PNG when you can (PNG vs JPG vs WebP explains why).
    • Small text disappears on phones. Keep snippets short, use a bigger font size, and break long lines yourself.

    Our code image generator runs in your browser. To make an image with it:

    1. Open the tool and, in the Edit tab, set LANGUAGE first. Changing the language replaces whatever is in the editor with a sample in that language, so pick it before you paste.
    2. Paste or type your code into the editor on the canvas.
    3. Under THEME & FONT STYLE, pick one of 19 themes and one of 10 monospaced fonts. Xcode Dark and JetBrains Mono are the defaults.
    4. Set Font size (4 to 30, default 15). Optionally add a window frame from FRAMES, plus SHADOW and Padding.
    5. Click Save to download the image, or Copy to put it on your clipboard.

    The 19 themes are Dracula, Monokai, Okaidia, Darcula, Android Studio, Atomone, Github Dark, Github Light, ABCDEF, Aura, Nord, Tomorrow Night Blue, VS Code Dark, Material Dark, Gruvbox Dark, Console Dark, Console Light, Xcode Dark and Xcode Light.

    Limits to know:

    • There are 17 languages: HTML, CSS, JavaScript, Python, Java, C++, Rust, SQL, JSON, Wast, Xml, Markdown, PHP, Yaml, Vue, Svelte and C#. Yaml, Vue and Svelte show as plain text, so 14 are actually highlighted.
    • The language isn't detected automatically. If your code looks uncolored, check the LANGUAGE setting.
    • There are no line numbers, and long lines wrap.
    • On the free plan, exports are PNG or JPEG at 1x, and each Save or Copy counts toward 3 downloads a day per browser. Code images carry no watermark. Higher quality and the other formats need the Lifetime plan (see Free vs Lifetime pricing).

    For platform-specific tips, see how to share code on Twitter and LinkedIn as an image and how to add code to slides and docs readably. If you are choosing a tool, our roundup of code screenshot tools compares the options.

    Keep highlighted code readable: contrast and color blindness

    Colors help only if people can see them. A few rules keep highlighted code readable for everyone:

    • Check contrast against the background. WCAG asks for a contrast ratio of at least 4.5:1 for normal-size text (3:1 for large text). Any free WCAG contrast checker will tell you whether a token color passes.
    • Watch the comments. Many dark themes show comments in a dim gray on purpose, so they fade into the background. That's fine in your editor, but in a shared image the comment may be the line that explains everything. Pick a theme with brighter comments, or delete the comments that don't matter.
    • Don't rely on color alone. Red-green color blindness is common, and a theme that separates keywords from strings mainly by red versus green can turn them into the same color for some readers. Themes that also use bold, italic or clearly different brightness levels hold up better.
    • Size beats style. A larger font in a plain theme is easier to read than a striking theme at a small size, especially on a phone or across a room.
    • Match the setting. Light themes usually hold up better on projectors and in print. Dark themes suit dark-mode feeds and screens in dim rooms.

    If one color in your editor theme is hard to read, many editors (VS Code included) let you override individual token colors in their settings, so you can fix that color without giving up the whole theme.

    FAQ

    Does syntax highlighting change my code? No. It is display only. The file contains plain text, and the editor or website adds the colors each time it shows the code.

    Why is my code showing up in one color? The tool either doesn't know the language or doesn't support it. Set the language manually (in VS Code, click the language name in the status bar) or check that the file has the right extension.

    Is syntax highlighting the same as a linter? No. A linter analyzes code for errors and style problems. Highlighting only colors tokens, though an unexpected color change often points to a typo such as an unclosed string.

    Share this article