Debian Codegraph @

docs/content/en/quick-reference/syntax-highlighting-styles.md

raw
1 ---
2 title: Syntax highlighting styles
3 description: Highlight code examples using one of these styles.
4 categories: []
5 keywords: [highlight]
6 ---
7
8 ## Overview
9
10 Hugo provides several methods to add syntax highlighting to code examples:
11
12 - Use the [`transform.Highlight`][] function within your templates
13 - Use the [`highlight`][] shortcode with any [content format](g)
14 - Use [fenced code blocks][] with the Markdown content format
15
16 Regardless of method, use any of the syntax highlighting styles below.
17
18 Set the default syntax highlighting style in your project configuration:
19
20 {{< code-toggle file=hugo >}}
21 [markup.highlight]
22 style = 'monokai'
23 {{< /code-toggle >}}
24
25 See [configure Markup][].
26
27 By default, Hugo applies syntax highlighting using inline CSS styles. To use an external CSS file instead, set [`noClasses`][] to `false` in your configuration, then generate the stylesheet with the [`hugo gen chromastyles`][] command.
28
29 ## Modes
30
31 {{< new-in 0.164.0 />}}
32
33 Syntax highlighting styles are designed for either light mode or dark mode displays. Some light mode styles have a corresponding dark mode counterpart. When using external CSS stylesheets, you can switch between them based on user preference or environment.
34
35 The table below lists the light mode styles that have a dark mode counterpart. Each style name links to its entry in the [Gallery](#gallery) section of this page.
36
37 {{% syntax-highlighting-styles-light-with-counterpart %}}
38
39 ## Gallery
40
41 This gallery demonstrates the application of each syntax highlighting style with code examples written in different programming languages. Each style lists its mode (light or dark). For styles with a counterpart in the opposite mode, the counterpart style is also listed.
42
43 {{% syntax-highlighting-styles %}}
44
45 [`highlight`]: /shortcodes/highlight/
46 [`hugo gen chromastyles`]: /commands/hugo_gen_chromastyles/
47 [`noClasses`]: /configuration/markup/#noclasses
48 [`transform.Highlight`]: /functions/transform/highlight/
49 [configure Markup]: /configuration/markup/#highlight
50 [fenced code blocks]: /content-management/syntax-highlighting/#fenced-code-blocks