Skip to content

Code Block Language Reference

When writing documentation in Markdown or MDX, specifying the correct language identifier for code blocks ensures proper syntax highlighting and improves readability. This reference guide covers common language identifiers and provides examples of how to use them.

In Markdown, you can create a code block by wrapping your code with three backticks (```) at the beginning and end. To specify a language, add its identifier right after the opening backticks:

```javascript
const greeting = 'Hello, world!';
console.log(greeting);
```

The rendered output will have syntax highlighting appropriate for the specified language:

const greeting = 'Hello, world!';
console.log(greeting);

Here’s a comprehensive list of language identifiers you can use in your documentation:

IdentifierLanguage/FormatUse Case
htmlHTMLMarkup for web pages
xmlXMLExtensible Markup Language
svgSVGScalable Vector Graphics
cssCSSStylesheets
scssSCSSSass CSS pre-processor
lessLESSLESS CSS pre-processor
javascript or jsJavaScriptClient-side scripting
jsxJSXReact component syntax
typescript or tsTypeScriptTyped JavaScript
tsxTSXTypeScript with JSX
jsonJSONData interchange format
jsoncJSON with commentsConfiguration files
IdentifierLanguage/FormatUse Case
python or pyPythonGeneral-purpose programming
ruby or rbRubyGeneral-purpose programming
phpPHPServer-side scripting
javaJavaGeneral-purpose programming
csharp or csC#.NET development
go or golangGoSystems programming
rustRustSystems programming
kotlinKotlinAndroid development
swiftSwiftiOS/macOS development
sqlSQLDatabase queries
IdentifierLanguage/FormatUse Case
bash or shellBash/ShellCommand line scripts
powershell or psPowerShellWindows scripting
yaml or ymlYAMLConfiguration files
tomlTOMLConfiguration files
iniINIConfiguration files
dockerfileDockerfileContainer configurations
diffDiffCode changes/patches
ignoreGitignoreGit ignore patterns
IdentifierLanguage/FormatUse Case
markdown or mdMarkdownDocumentation
mdxMDXMarkdown with JSX
tex or latexLaTeXScientific documents
asciidoc or adocAsciiDocDocumentation

Use these identifiers for command-line instructions:

```sh
# Install dependencies
npm install
# Start development server
npm run dev
```

Result:

Terminal window
# Install dependencies
npm install
# Start development server
npm run dev

Perfect for showing changes between code versions:

```diff
- const oldFunction = () => {
- return "old implementation";
- }
+ const newFunction = () => {
+ return "new and improved implementation";
+ }
```

Result:

const oldFunction = () => {
return "old implementation";
}
const newFunction = () => {
return "new and improved implementation";
}

For .gitignore, .dockerignore, etc.:

# Dependencies
node_modules/
.pnp
.pnp.js
# Testing
coverage/
# Production
build/
dist/

Result:

# Dependencies
node_modules/
.pnp
.pnp.js
# Testing
coverage/
# Production
build/
dist/

GitHub and some other platforms support additional languages:

  • mermaid - For diagrams
  • graphql - For GraphQL queries
  • plantuml - For UML diagrams

Example of Mermaid diagram:

```mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```

If you don’t specify a language, the code block will be displayed without syntax highlighting:

```text
This is a plain text code block with no language specified.
It will not have any specific syntax highlighting.
```

Result:

This is a plain text code block with no language specified.
It will not have any specific syntax highlighting.

Many languages have multiple identifiers that can be used:

  • JavaScript: javascript, js
  • TypeScript: typescript, ts
  • Python: python, py
  • Ruby: ruby, rb
  • Shell: bash, shell, sh

Use whichever feels most natural for your documentation style.

  1. Be consistent - Choose one identifier per language and use it consistently throughout your documentation.

  2. Use appropriate identifiers - Match the identifier to the actual language for accurate syntax highlighting.

  3. For mixed content - When a code block contains mixed languages (like HTML with embedded JavaScript), choose the predominant language.

  4. For configuration files - Use the exact format identifier when possible (dockerfile, nginx, yaml).

  5. For command output - If showing terminal output that isn’t meant to be executed, you can use text or omit the language identifier.

In the Starlight documentation framework, you can enhance code blocks with additional features:

You can highlight specific lines using curly braces:

```js {3-4}
function example() {
const a = 1;
// These lines will be highlighted
const highlightedLine = true;
return a;
}
```
```js title="example.js"
function greet() {
return 'Hello world!';
}
```

The exact list of supported languages for syntax highlighting depends on the syntax highlighter used in your project. Most documentation sites use either:

  • Prism.js
  • Shiki
  • Highlight.js

Check your project’s configuration to see which highlighter is in use and what languages are supported.