Add Line Numbers to a Hugo Code Block

Hugo can add line numbers to one code block without changing every snippet on the site. Add linenos=true to the opening fence.

Here is the same small example without line numbers:

print("Hello, World!")

Now enable them for that block:

print("Hello, World!")

If the numbers do not appear

Hugo’s syntax highlighter produces the line-number markup, while the theme is responsible for making it look right. If nothing changes, check that:

I would not enable line numbers for every one-line example. They are useful when the article refers readers to particular lines; otherwise, plain code blocks are usually easier to scan.