When writing technical blog posts with Hugo, displaying line numbers in code blocks can enhance readability and make code examples more reference-friendly. This guide walks you through the process of enabling line numbers for your code blocks.

Standard Markdown Code Block

A typical code block in markdown looks like this:

print("Hello, World!")

Enabling Line Numbers

To add line numbers, modify the code block’s opening syntax by including the linenos=true option:

print("Hello, World!")

Configuration Considerations

Troubleshooting

Adding line numbers to your Hugo code blocks is straightforward. With the {linenos=true} option, you can create more readable and professional-looking technical documentation.