Themes and CSS

fhl writes the code colors as highlight.css (or into <style> with --single-html). The library writes no CSS; use the one from fhl, or your own.

Choose a theme

fhl --theme dark:github docs/       # GitHub, dark colors only
fhl --theme light docs/             # default, light colors only
fhl --theme both:tokyo-night docs/  # Tokyo Night, light and dark
fhl --list-themes
fhl --print-css --theme both:github > highlight.css  # only the CSS, for your own build

Every theme has light and dark colors. --theme MODE:THEME chooses which to write and the theme:

MODE Writes
light the light colors only
dark the dark colors only
both the light colors, switched to the dark ones when the viewer's device prefers dark (prefers-color-scheme)

THEME can be left out for default; without --theme, it is both:default. both follows the viewer's device setting by default.

For a site with its own light and dark switch, --theme-selector MODE:SELECTOR adds the MODE colors (light or dark) under your CSS selector. The device setting stays the starting point, and your selector wins over it. To add selectors for both light and dark, repeat the flag in the same command, once for each selector (the CSS of both comes out of one run):

What decides the colors Flags
The device setting only none
The device setting, then the site's switch (<html data-theme="light"> or "dark") --theme-selector dark:':root[data-theme="dark"]' --theme-selector light:':root[data-theme="light"]'
The site's switch only (<html data-theme="dark"> or nothing) --theme-selector dark:':root[data-theme="dark"]' --theme-selector light:':root:not([data-theme="dark"])'

Tip: to override the device setting completely, give the light colors a selector with :not(…) that matches whenever the dark one does not, as in the last row. Then the device setting never shows, even though its @media (prefers-color-scheme: dark) block is still in the CSS.

--no-frame leaves out the background and text color of pre.highlight, so that your own styles for code blocks apply.

fhl --print-css --theme both:github \
  --theme-selector dark:':root[data-theme="dark"]' \
  --theme-selector light:':root[data-theme="light"]' --no-frame > highlight.css

One selector can still match several things: dark:':root[data-theme="dark"], .dark-mode' puts the dark colors under both, as a comma does in CSS.

The default theme, default, has fhl's own colors and bold keywords. Every color in it has a contrast ratio of at least 6 against its background (above WCAG AA). The other themes copy the colors of the original themes as they are, so some of their colors have a lower contrast.

THEME Name Light Dark
default default fhl's own colors fhl's own colors
github GitHub GitHub Light Default (primer/github-vscode-theme) GitHub Dark Default (primer/github-vscode-theme)
vscode VS Code VS Code Light+ (microsoft/vscode) VS Code Dark+ (microsoft/vscode)
solarized Solarized Solarized Light (as shipped with VS Code) Solarized Dark (as shipped with VS Code)
one One One Light (atom/one-light-syntax) One Dark (atom/one-dark-syntax)
catppuccin Catppuccin Catppuccin Latte (catppuccin/vscode) Catppuccin Mocha (catppuccin/vscode)
tokyo-night Tokyo Night Tokyo Night Light (enkia/tokyo-night-vscode-theme) Tokyo Night (enkia/tokyo-night-vscode-theme)

Samples

The same code in each theme.

default

// Greet says hello to name.
func Greet(name string) string {
	if name == "" {
		return "hello, world\n"
	}
	return fmt.Sprintf("hello, %s (%d)", name, 42)
}

GitHub (github)

// Greet says hello to name.
func Greet(name string) string {
	if name == "" {
		return "hello, world\n"
	}
	return fmt.Sprintf("hello, %s (%d)", name, 42)
}

VS Code (vscode)

// Greet says hello to name.
func Greet(name string) string {
	if name == "" {
		return "hello, world\n"
	}
	return fmt.Sprintf("hello, %s (%d)", name, 42)
}

Solarized (solarized)

// Greet says hello to name.
func Greet(name string) string {
	if name == "" {
		return "hello, world\n"
	}
	return fmt.Sprintf("hello, %s (%d)", name, 42)
}

One (one)

// Greet says hello to name.
func Greet(name string) string {
	if name == "" {
		return "hello, world\n"
	}
	return fmt.Sprintf("hello, %s (%d)", name, 42)
}

Catppuccin (catppuccin)

// Greet says hello to name.
func Greet(name string) string {
	if name == "" {
		return "hello, world\n"
	}
	return fmt.Sprintf("hello, %s (%d)", name, 42)
}

Tokyo Night (tokyo-night)

// Greet says hello to name.
func Greet(name string) string {
	if name == "" {
		return "hello, world\n"
	}
	return fmt.Sprintf("hello, %s (%d)", name, 42)
}

How the CSS is made

:root {
  --highlight-keyword: #a3195b; /* keyword (if, func, etc.) */
  --highlight-string: #17663a; /* string */
  /* … */
}
/* nf: function name (Name.Function) */
pre.highlight .nf { color: var(--highlight-function); }

CSS variables

Variable What it colors
--highlight-background code block background
--highlight-text plain text (names, whitespace, and anything not covered by another role)
--highlight-comment comment
--highlight-keyword keyword (if, func, etc.)
--highlight-type type and class name
--highlight-string string
--highlight-escape escape and interpolation inside a string (\n, ${x}, etc.)
--highlight-number number
--highlight-constant constant (true, nil, constant names, etc.)
--highlight-function function name
--highlight-builtin builtin name (print, len, etc.)
--highlight-variable variable
--highlight-attribute attribute and property
--highlight-tag tag (HTML element names, YAML keys, etc.)
--highlight-operator operator
--highlight-punctuation punctuation (brackets, commas, etc.)
--highlight-preproc preprocessor (#include, etc.)
--highlight-decorator decorator and annotation (those starting with @)
--highlight-inserted added diff line
--highlight-deleted removed diff line
--highlight-heading heading (diff file name lines, etc.)
--highlight-muted muted part (shell prompts and output)
--highlight-error part that could not be tokenized

Token classes

The class names are the short ones used by Pygments, Chroma and Rouge, so CSS written for those mostly works too.

Class Meaning Token type
err part that could not be tokenized Error
x other part Other
k keyword Keyword
kc constant keyword (true, nil, etc.) Keyword.Constant
kd declaration keyword (var, func, etc.) Keyword.Declaration
kn namespace keyword (import, package, etc.) Keyword.Namespace
kp keyword-like word Keyword.Pseudo
kr reserved word Keyword.Reserved
kt type keyword (int, string, etc.) Keyword.Type
n name Name
na attribute name Name.Attribute
nb builtin name Name.Builtin
bp special builtin name (self, this, etc.) Name.Builtin.Pseudo
nc class name Name.Class
no constant name Name.Constant
nd decorator and annotation Name.Decorator
ni character reference (&, etc.) Name.Entity
ne exception name Name.Exception
nf function name Name.Function
fm special function name (init, etc.) Name.Function.Magic
py property name Name.Property
nl label Name.Label
nn namespace and package name Name.Namespace
nx other name Name.Other
nt tag (HTML element names, YAML keys, etc.) Name.Tag
nv variable Name.Variable
vc class variable Name.Variable.Class
vg global variable Name.Variable.Global
vi instance variable Name.Variable.Instance
vm special variable Name.Variable.Magic
l literal (a value written out directly) Literal
ld date Literal.Date
s string Literal.String
sa string prefix (the r in r"…", etc.) Literal.String.Affix
sb backtick string Literal.String.Backtick
sc character Literal.String.Char
dl string delimiter Literal.String.Delimiter
sd documentation string (docstring) Literal.String.Doc
s2 double-quoted string Literal.String.Double
se escape (\n, etc.) Literal.String.Escape
sh heredoc Literal.String.Heredoc
si interpolation inside a string (${x}, etc.) Literal.String.Interpol
sx other string Literal.String.Other
sr regular expression Literal.String.Regex
s1 single-quoted string Literal.String.Single
ss symbol (:name, etc.) Literal.String.Symbol
m number Literal.Number
mb binary number Literal.Number.Bin
mf floating-point number Literal.Number.Float
mh hexadecimal number Literal.Number.Hex
mi integer Literal.Number.Integer
il long integer Literal.Number.Integer.Long
mo octal number Literal.Number.Oct
o operator Operator
ow word operator (and, in, etc.) Operator.Word
or reserved operator Operator.Reserved
p punctuation Punctuation
c comment Comment
ch #! on the first line Comment.Hashbang
cm multi-line comment Comment.Multiline
cp preprocessor (#include, etc.) Comment.Preproc
cpf preprocessor file name Comment.PreprocFile
c1 single-line comment Comment.Single
cs special comment Comment.Special
g other Generic
gd removed diff line Generic.Deleted
ge emphasis Generic.Emph
gr error output Generic.Error
gh heading Generic.Heading
gi added diff line Generic.Inserted
go command output Generic.Output
gp shell prompt Generic.Prompt
gs strong emphasis Generic.Strong
gu subheading Generic.Subheading
gt error traceback Generic.Traceback
gl underline Generic.Underline

Make your own colors

Change the variables. You do not need to touch the class rules:

:root {
  --highlight-background: #fffdf5;
  --highlight-keyword: #b00040;
}

Load your file after highlight.css, or edit the variables in highlight.css itself. To color one class differently from the others that share its variable, add a rule for that class, such as pre.highlight .nb { color: … }.

This site's samples above use the same idea: the variables of each theme are put under a class (.theme-github and so on) instead of :root, so each sample takes its own colors.