Note: You need to run Hugo ⩾ 0.81, and Hugo 0.108.0 provides interesting improvements on this topic
Enable Markdown Attributes
In config.toml
[markup.goldmark.parser.attribute]
block = true
title = true
or in config.yml
markup:
goldmark:
parser:
attribute:
block: true
title: true
Usage
Add a single class:

{.custom-css-class}
Add multiples classes:

{.myclass class="custom-css-class1 custom-class2"}
Example
This picture surrounded by a frame is the result of this image together with some CSS and the following markup:

{.frame-browser}
Further reading
- Release notes for Hugo 0.108, introducing improvements on this topic.
- Discussion about this release