HUGO
News Docs Themes Community GitHub

Syntax highlighting

Add syntax highlighting to code examples.

Hugo provides several methods to add syntax highlighting to code examples:

Fenced code blocks

In its default configuration, Hugo highlights code examples within fenced code blocks, following this form:

content/example.md
```LANG [OPTIONS]
CODE
```
CODE
The code to highlight.
LANG
The language of the code to highlight. Choose from one of the supported languages. This value is case-insensitive.
OPTIONS
One or more space-separated or comma-separated key-value pairs wrapped in braces. Set default values for each option in your site configuration. The key names are case-insensitive.

For example, with this Markdown:

content/example.md
```go {linenos=inline hl_lines=[3,"6-8"] style=emacs}
package main

import "fmt"

func main() {
    for i := 0; i < 3; i++ {
        fmt.Println("Value of i:", i)
    }
}
```

Hugo renders this:

1package main
2
3import "fmt"
4
5func main() {
6    for i := 0; i < 3; i++ {
7        fmt.Println("Value of i:", i)
8    }
9}

Options

anchorLineNos
(bool) Whether to render each line number as an HTML anchor element, setting the id attribute of the surrounding span element to the line number. Irrelevant if lineNos is false. Default is false.
codeFences
(bool) Whether to highlight fenced code blocks. Default is true.
guessSyntax
(bool) Whether to automatically detect the language if the LANG argument is blank or set to a language for which there is no corresponding lexer. Falls back to a plain text lexer if unable to automatically detect the language. Default is false.

The Chroma syntax highlighter includes lexers for approximately 250 languages, but only 5 of these have implemented automatic language detection.

hl_Lines
(string) A space-delimited list of lines to emphasize within the highlighted code. To emphasize lines 2, 3, 4, and 7, set this value to 2-4 7. This option is independent of the lineNoStart option.
hl_inline
(bool) Whether to render the highlighted code without a wrapping container. Default is false.
lineAnchors
(string) When rendering a line number as an HTML anchor element, prepend this value to the id attribute of the surrounding span element. This provides unique id attributes when a page contains two or more code blocks. Irrelevant if lineNos or anchorLineNos is false.
lineNoStart
(int) The number to display at the beginning of the first line. Irrelevant if lineNos is false. Default is 1.
lineNos
(any) Controls line number display. Default is false.
  • true: Enable line numbers, controlled by lineNumbersInTable.
  • false: Disable line numbers.
  • inline: Enable inline line numbers (sets lineNumbersInTable to false).
  • table: Enable table-based line numbers (sets lineNumbersInTable to true).
lineNumbersInTable
(bool) Whether to render the highlighted code in an HTML table with two cells. The left table cell contains the line numbers, while the right table cell contains the code. Irrelevant if lineNos is false. Default is true.
noClasses
(bool) Whether to use inline CSS styles instead of an external CSS file. Default is true. To use an external CSS file, set this value to false and generate the CSS file from the command line:
hugo gen chromastyles --style=monokai > syntax.css
style
(string) The CSS styles to apply to the highlighted code. Case-sensitive. Default is monokai. See syntax highlighting styles.
tabWidth
(int) Substitute this number of spaces for each tab character in your highlighted code. Irrelevant if noClasses is false. Default is 4.
wrapperClass
New in v0.140.2
(string) The class or classes to use for the outermost element of the highlighted code. Default is highlight.

Escaping

When documenting shortcode usage, escape the tag delimiters:

content/example.md
```text {linenos=inline}
{{</* shortcode-1 */>}}

{{%/* shortcode-2 */%}}
```

Hugo renders this to:

1{{< shortcode-1 >}}
2
3{{% shortcode-2 %}}

Languages

These are the supported languages. Use one of the identifiers, not the language name, when specifying a language for:

Language Identifiers
ABAP abap
ABNF abnf
ActionScript as, actionscript
ActionScript 3 as3, actionscript3
Ada ada, ada95, ada2005
Agda agda
AL al
Alloy alloy
Angular2 ng2
ANTLR antlr
ApacheConf apacheconf, aconf, apache
APL apl
AppleScript applescript
ArangoDB AQL aql
Arduino arduino
ArmAsm armasm
ATL atl
AutoHotkey autohotkey, ahk
AutoIt autoit
Awk awk, gawk, mawk, nawk
Ballerina ballerina
Bash bash, sh, ksh, zsh, shell
Bash Session bash-session, console, shell-session
Batchfile bat, batch, dosbatch, winbatch
Beef beef
BibTeX bib, bibtex
Bicep bicep
BlitzBasic blitzbasic, b3d, bplus
BNF bnf
BQN bqn
Brainfuck brainfuck, bf
C c
C# csharp, c#
C++ cpp, c++
Caddyfile caddyfile, caddy
Caddyfile Directives caddyfile-directives, caddyfile-d, caddy-d
Cap'n Proto capnp
Cassandra CQL cassandra, cql
Ceylon ceylon
CFEngine3 cfengine3, cf3
cfstatement cfs
ChaiScript chai, chaiscript
Chapel chapel, chpl
Cheetah cheetah, spitfire
Clojure clojure, clj, edn
CMake cmake
COBOL cobol
CoffeeScript coffee-script, coffeescript, coffee
Common Lisp common-lisp, cl, lisp
Coq coq
Crystal cr, crystal
CSS css
CSV csv
CUE cue
Cython cython, pyx, pyrex
D d
Dart dart
Dax dax
Desktop file desktop, desktop_entry
Diff diff, udiff
Django/Jinja django, jinja
dns zone, bind
Docker docker, dockerfile
DTD dtd
Dylan dylan
EBNF ebnf
Elixir elixir, ex, exs
Elm elm
EmacsLisp emacs, elisp, emacs-lisp
Erlang erlang
Factor factor
Fennel fennel, fnl
Fish fish, fishshell
Forth forth
Fortran fortran, f90
FortranFixed fortranfixed
FSharp fsharp
GAS gas, asm
GDScript gdscript, gd
GDScript3 gdscript3, gd3
Genshi genshi, kid, xml+genshi, xml+kid
Genshi HTML html+genshi, html+kid
Genshi Text genshitext
Gherkin cucumber, Cucumber, gherkin, Gherkin
Gleam gleam
GLSL glsl
Gnuplot gnuplot
Go go, golang
Go HTML Template go-html-template
Go Template go-template
Go Text Template go-text-template
GraphQL graphql, graphqls, gql
Groff groff, nroff, man
Groovy groovy
Handlebars handlebars, hbs
Hare hare
Haskell haskell, hs
Haxe hx, haxe, hxsl
HCL hcl
Hexdump hexdump
HLB hlb
HLSL hlsl
HolyC holyc
HTML html
HTTP http
Hy hylang
Idris idris, idr
Igor igor, igorpro
INI ini, cfg, dosini
Io io
ISCdhcpd iscdhcpd
J j
Janet janet
Java java
JavaScript js, javascript
JSON json
JSONata jsonata
Jsonnet jsonnet
Julia julia, jl
Jungle jungle
Kotlin kotlin
Lean4 lean4, lean
Lighttpd configuration file lighty, lighttpd
LLVM llvm
Lua lua, luau
Makefile make, makefile, mf, bsdmake
Mako mako
markdown md, mkd
Mason mason
Materialize SQL dialect materialize, mzsql
Mathematica mathematica, mma, nb
Matlab matlab
MCFunction mcfunction, mcf
Meson meson, meson.build
Metal metal
MiniZinc minizinc, MZN, mzn
MLIR mlir
Modula-2 modula2, m2
Mojo mojo, 🔥
MonkeyC monkeyc
MorrowindScript morrowind, mwscript
Myghty myghty
MySQL mysql, mariadb
NASM nasm
Natural natural
NDISASM ndisasm
Newspeak newspeak
Nginx configuration file nginx
Nim nim, nimrod
Nix nixos, nix
NSIS nsis, nsi, nsh
Objective-C objective-c, objectivec, obj-c, objc
ObjectPascal objectpascal
OCaml ocaml
Octave octave
Odin odin
OnesEnterprise ones, onesenterprise, 1S, 1S:Enterprise
OpenEdge ABL openedge, abl, progress, openedgeabl
OpenSCAD openscad
Org Mode org, orgmode
PacmanConf pacmanconf
Perl perl, pl
PHP php, php3, php4, php5
PHTML phtml
Pig pig
PkgConfig pkgconfig
PL/pgSQL plpgsql
plaintext text, plain, no-highlight
Plutus Core plutus-core, plc
Pony pony
PostgreSQL SQL dialect postgresql, postgres
PostScript postscript, postscr
POVRay pov
PowerQuery powerquery, pq
PowerShell powershell, posh, ps1, psm1, psd1, pwsh
Prolog prolog
Promela promela
PromQL promql
properties java-properties
Protocol Buffer protobuf, proto
PRQL prql
PSL psl
Puppet puppet
Python python, py, sage, python3, py3
Python 2 python2, py2
QBasic qbasic, basic
QML qml, qbs
R splus, s, r
Racket racket, rkt
Ragel ragel
Raku perl6, pl6, raku
react jsx, react
ReasonML reason, reasonml
reg registry
Rego rego
reStructuredText rst, rest, restructuredtext
Rexx rexx, arexx
RPGLE SQLRPGLE, RPG IV
RPMSpec spec
Ruby rb, ruby, duby
Rust rust, rs
SAS sas
Sass sass
Scala scala
Scheme scheme, scm
Scilab scilab
SCSS scss
Sed sed, gsed, ssed
Sieve sieve
Smali smali
Smalltalk smalltalk, squeak, st
Smarty smarty
SNBT snbt
Snobol snobol
Solidity sol, solidity
SourcePawn sp
SPARQL sparql
SQL sql
SquidConf squidconf, squid.conf, squid
Standard ML sml
stas
Stylus stylus
Svelte svelte
Swift swift
SYSTEMD systemd
systemverilog systemverilog, sv
TableGen tablegen
Tal tal, uxntal
TASM tasm
Tcl tcl
Tcsh tcsh, csh
Termcap termcap
Terminfo terminfo
Terraform terraform, tf, hcl
TeX tex, latex
Thrift thrift
TOML toml
TradingView tradingview, tv
Transact-SQL tsql, t-sql
Turing turing
Turtle turtle
Twig twig
TypeScript ts, tsx, typescript
TypoScript typoscript
TypoScriptCssData typoscriptcssdata
TypoScriptHtmlData typoscripthtmldata
Typst typst
ucode
V v, vlang
V shell vsh, vshell
Vala vala, vapi
VB.net vb.net, vbnet
verilog verilog, v
VHDL vhdl
VHS vhs, tape, cassette
VimL vim
vue vue, vuejs
WDTE
WebGPU Shading Language wgsl
WebVTT vtt
Whiley whiley
XML xml
Xorg xorg.conf
YAML yaml
YANG yang
Z80 Assembly z80
Zed zed
Zig zig

Last updated: January 1, 0001
Improve this page