Skip to main content
All CollectionsAll ProductsProduct Features
Syntax Highlighting in Code Blocks
Syntax Highlighting in Code Blocks

How to set syntax highlighting for code at the tag level.

Joel Bradley avatar
Written by Joel Bradley
Updated over 2 weeks ago

Applies to: All Stack Overflow for Teams

Overview

Stack Overflow for Teams applies syntax highlighting to blocks of code in questions and answers. This is similar to programming editors, which use colors and formatting to make code easier to read and parse. For example: you could set the syntax highlighting to Javascript for the gamma-js-library tag. Stack Overflow for Teams will recognize the tag and highlight any code in that tagged content as Javascript.

Here's a before and after example of code highlighting:

Tag highlighting

Most syntax highlighting happens at the tag level, by assigning a highlighting color scheme to a specific Stack Overflow for Teams tag. Assigning a color scheme is especially useful for tags related to programming languages, libraries, extensions, and frameworks.

To set the highlighting color scheme for a tag, visit the tag's info page by clicking on the tag's name. Then, click Learn more… at the top of the tag page.

NOTE: If a tag doesn't have additional info, you'll see "The [tag] tag has no usage guidance, can you help us create it?" at the top of the tag page. Click help us create it to go to the Editing tag info page, then click Cancel.

At the bottom of the tag's About page, you'll see a dropdown menu with syntax highlighting options.

Select the appropriate language from the Code Language pull-down menu, then click save. This will apply the selected highlighting scheme to code blocks in posts with that tag, unless overridden by the user that created the post (see the "Post-specific highlighting" section below).

The following rules define the behavior of tag-specific syntax highlighting:

  • If a question has no tags with syntax highlighting set, the site will apply no syntax highlighting.

  • If a question has one tag with syntax highlighting set and other tags with no specific setting, the site will apply syntax highlighting based on the one set tag.

  • If a question has two or more tags with syntax highlighting set, the site ignores the settings and instead attempts to detect the language for each block of code.

  • If a question has one or more tags with syntax highlighting set to default and none with a specific setting, the site will attempt to detect the language.

Post-specific highlighting

When composing a post, you can override the default formatting for a tag by using a supported syntax highlighting code (or tag name) in the code block. For example:

If a user specifies a language for a code block in their post, that declaration overrides the syntax highlighting settings for any attached tag. This gives better results for posts that contain code blocks in multiple languages, or posts that have tags that lack syntax highlighting settings.

For help with syntax highlighting and other Markdown features when writing a post, see the "How to Format" sidebar to the right of the editor window. For more help with formatting, click formatting help >> in the sidebar, or the formatting help (?) button in the editor toolbar.


Need help? Submit an issue or question through our support portal.

Did this answer your question?