Hugo on Netlify
Hugo is a fast and flexible open source static site generator written in Go.
# Key features
These features provide important benefits for Hugo sites, including ones built and deployed with Netlify.
- Build speed. Hugo boasts near-instant build times of less than one millisecond per page. For large sites with a lot of pages, this can translate into significant time savings during site development and Netlify build and deploy processes.
- Choice of themes. The Hugo ecosystem includes a wide range of premade themes for styling static content.
- Robust templating. Hugo uses Go templates with
text/templatelibraries to control templating.
- Instant previews. The LiveReload tool is integrated into Hugo for a hot reloading experience during development.
- URL management. Hugo has built-in support for URL manipulations and redirects.
- Functions and variables. When building out templates, you can use Go functions, built-in Hugo-specific functions, and a variety of variables.
# Netlify integration
Hugo sites on Netlify can benefit from automatic framework detection and control over Hugo version selection. They also require theme setup considerations.
# Automatic framework detection
When you link a repository for a project, Netlify tries to detect the framework your site is using. If your site is built with Hugo, Netlify provides a suggested build command and publish directory:
public. If you’re using the CLI to run Netlify Dev for a local development environment, Netlify also suggests a dev command and port:
hugo server -w and
1313. You can override suggested values or set them in a configuration file instead, but automatic framework detection may help simplify the process of setting up a site on Netlify.
For manual configuration, check out the typical build settings for Hugo.
# Hugo version
By default we’ll use the Hugo version that is preinstalled in your site’s initial build image. Because the preinstalled version may not match your local version, we recommend setting a
HUGO_VERSION environment variable. You can set the variable to the version string for any released version after 0.19, for example,
First, confirm your local Hugo version with
Then add an environment variable in the Netlify UI or in a Netlify configuration file.
- In the Create a new site page, select Show advanced. This provides access to Environment variables, where you can create the environment variable as you link your site.
- Alternatively, add the following to
netlify.tomlin your site’s base directory, where
YOUR_HUGO_VERSIONis a version string such as
[build] command = "hugo" publish = "public" [build.environment] HUGO_VERSION = "YOUR_HUGO_VERSION"
If you get an error with
exit code: 255 when building a Hugo site on Netlify, remember to set
HUGO_VERSION to the version you are using locally.
# Hugo themes
Hugo themes work by default on Netlify. Like any continuous integration system, however, Netlify can’t use a theme installed by the
git clone method. Instead, you should install a Hugo theme for your site as a git submodule. The Hugo docs provide more information.
Here’s an example:
cd YOUR_PROJECT_DIRECTORY git init git submodule add https://github.com/THEME_CREATOR/THEME_NAME
# More resources
Did you find this doc useful?
Your feedback helps us improve our docs.