Files
hugo/content/en/configuration/introduction.md
T
Bjørn Erik Pedersen c23d97904f Squashed 'docs/' changes from 0755fb534d..1f8ddb8a52
1f8ddb8a52 content: clarify resources front matter key descriptions
e064ab8528 content: Add deprecation badges to module config page
727ca5563a github: Add push trigger to lint workflow
64dd5c9886 content: Fix typo
c5bc6b6515 github: Fix lint workflow
faec0c3a0a github: Combine linting actions into a single workflow
06112aeaf2 theme: Miscellaneous template edits
75d4902270 theme: Format templates with gotmplfmt
fec2e2a67e content: Document that the language code in a file name must be lowercase
9dbd841ba6 content: Document the src attribute in the Page Resources metadata reference
fd3ffef985 content: Fix "build from source" instructions for Windows
af4c9cd4d7 content: Miscellaneous edits
408d8b2f0a content: Miscellaneous edits
e8804afe6e content: Fix typo
d98276be30 content: Updates for v0.161.0
01b1f8fa12 content: Note merge limitation for slice configuration values
d2b18f0c8d content: Document page matcher usage for cascading values
45e5bd9ab3 content: Update Cloudflare Worker host/deploy guide
b83726b89a content: Document fallback rendering for fenced code blocks
8f1eeb42bc content: Update reference for source code shortcode
e8da56303b content: Add gotmplfmt to list of VS Code extensions
950fabbfd6 content: Update FAQ on feature availability error
6411146d24 content: Update quick start guide
38cc39fd51 content: Add Hugo Shortcodes to list of VS Code extensions
72d98b107b content: Misc updates to get validators to pass
9fb0e1ca35 Add a paragraph about sec boundaries
e6abf5644f content: Improve syntax highlighting documentation
c06193bd1a content: Update go-i18n package reference
ce58fef945 Hugo 0.161.1
c7e0f63385 content: Fix package references
7f15fb3bf9 data: Regen docshelper
7483d53b55 Update HUGO_VERSION to 0.161.0
c4abcdb45f security: Add a bullet point about "pragmatic defaults"
3cd7492862 content: Improve explanation of mount removal in module configurations
4099f07bb9 content: Update GitHub Pages workflow example
a6c9853a58 content: Fix typo
e6f79a938b Update netlify.toml
abda3d6659 content: Update Action versions in GitHub Pages workflow example
55dd288fa9 content: Add GitCMS to front-ends tools list
21081f6d49 content: Remove outdated new-in badges
b2ec263884 content: Update version references
825e0b8ea9 One more CSS var adjustment
85f95a899b Adjust css.Build var docs a little
df48288002 content: Updates for v0.160.0
a82a9b9797 Update HUGO_VERSION to 0.160.0
1155747dc4 content: Improve CSS processing feature description
f6ce893974 content: Add css.Build to features
67b8ed1198 content: Fix typos
0f62a67863 content: Fix typo
dbb42aed4a content: Document the deploy edition
549f30f933 content: De-emphasize references to the extended edition
8f5c9782d4 content: Add Pages CMS to front-ends documentation
b2bfc3af48 Update HUGO_VERSION to 0.159.2
3793156fc5 content: Fix typos
bacd4824ef content: Specify function namespace in example
7f2dc0d40a Regen docs.yml
65a851f731 Update HUGO_VERSION to 0.159.1
ce05fe3fc0 content: Adjust variable references in build script examples
8a04f9fe64 content: Improve hosting build script examples
67962ce05c content: Link to Codeberg Pages 404 handling
fd248f57ed content: Identify esbuild as the foundation for build functions
62f02879fd content: Remove outdated content
553c407f9e content: Miscellaneous corrections
77e2cad088 content: Add new-in badge for usePackageJSON
0746e1e621 Add a page on using npm dependencies in Hugo Modules
8824850f5c Update HUGO_VERSION to 0.159.0

git-subtree-dir: docs
git-subtree-split: 1f8ddb8a5230518f07c50b4b03cba3cae21081c4
2026-05-21 12:22:48 +02:00

9.9 KiB

title, description, categories, keywords, weight
title description categories keywords weight
Introduction Configure your site using files, directories, and environment variables.
10

Sensible defaults

Hugo offers many configuration options, but its defaults are often sufficient. A new project requires only these settings:

{{< code-toggle file=hugo >}} baseURL = 'https://example.org/' locale = 'en-us' title = 'My New Hugo Site' {{< /code-toggle >}}

Only define settings that deviate from the defaults. A smaller configuration file is easier to read, understand, and debug. Keep your configuration concise.

Note

The best configuration file is a short configuration file.

Configuration file

Create a project configuration file in the root of your project directory, naming it hugo.toml, hugo.yaml, or hugo.json, with that order of precedence.

my-project/
└── hugo.toml

Note

For versions v0.109.0 and earlier, the project configuration file was named config. While you can still use this name, it's recommended to switch to the newer naming convention, hugo.

A simple example:

{{< code-toggle file=hugo >}} baseURL = 'https://example.org/' locale = 'en-us' title = 'ABC Widgets, Inc.' [params] subtitle = 'The Best Widgets on Earth' [params.contact] email = 'info@example.org' phone = '+1 202-555-1212' {{< /code-toggle >}}

To use a different configuration file when building your project, use the --config flag:

hugo build --config other.toml

Combine two or more configuration files, with left-to-right precedence:

hugo build --config a.toml,b.yaml,c.json

Note

See the specifications for each file format: TOML, YAML, and JSON.

Configuration directory

Instead of a single project configuration file, split your configuration by environment, root configuration key, and language. For example:

my-project/
└── config/
    ├── _default/
    │   ├── hugo.toml
    │   ├── menus.en.toml
    │   ├── menus.de.toml
    │   └── params.toml
    └── production/
        └── params.toml

The root configuration keys are {{< root-configuration-keys >}}.

Note

You must define cascade tables in the root configuration file. You cannot define cascade tables in a dedicated file. See issue #12899 for details.

Omit the root key

When splitting the configuration by root key, omit the root key in the component file. For example, these are equivalent:

{{< code-toggle file=config/_default/hugo >}} [params] foo = 'bar' {{< /code-toggle >}}

{{< code-toggle file=config/_default/params >}} foo = 'bar' {{< /code-toggle >}}

Recursive parsing

Hugo parses the config directory recursively, allowing you to organize the files into subdirectories. For example:

my-project/
└── config/
    └── _default/
        ├── navigation/
        │   ├── menus.de.toml
        │   └── menus.en.toml
        └── hugo.toml

Example

my-project/
└── config/
    ├── _default/
    │   ├── hugo.toml
    │   ├── menus.en.toml
    │   ├── menus.de.toml
    │   └── params.toml
    ├── production/
    │   ├── hugo.toml
    │   └── params.toml
    └── staging/
        ├── hugo.toml
        └── params.toml

Considering the structure above, when running hugo build --environment staging, Hugo will use every setting from config/_default and merge staging's on top of those.

Let's take an example to understand this better. Let's say you are using Google Analytics for your website. This requires you to specify a Google tag ID in your project configuration:

{{< code-toggle file=hugo >}} [services.googleAnalytics] ID = 'G-XXXXXXXXX' {{< /code-toggle >}}

Now consider the following scenario:

  1. You don't want to load the analytics code when running hugo server.
  2. You want to use different Google tag IDs for your production and staging environments. For example:
    • G-PPPPPPPPP for production
    • G-SSSSSSSSS for staging

To satisfy these requirements, configure your site as follows:

  1. config/_default/hugo.toml

    • Exclude the services.googleAnalytics section. This will prevent loading of the analytics code when you run hugo server.
    • By default, Hugo sets its environment to development when running hugo server. In the absence of a config/development directory, Hugo uses the config/_default directory.
  2. config/production/hugo.toml

    • Include this section only:

      {{< code-toggle file=hugo >}} [services.googleAnalytics] ID = 'G-PPPPPPPPP' {{< /code-toggle >}}

    • You do not need to include other parameters in this file. Include only those parameters that are specific to your production environment. Hugo will merge these parameters with the default configuration.

    • By default, Hugo sets its environment to production when running hugo build. The analytics code will use the G-PPPPPPPPP tag ID.

  3. config/staging/hugo.toml

    • Include this section only:

      {{< code-toggle file=hugo >}} [services.googleAnalytics] ID = 'G-SSSSSSSSS' {{< /code-toggle >}}

    • You do not need to include other parameters in this file. Include only those parameters that are specific to your staging environment. Hugo will merge these parameters with the default configuration.

    • To build your staging site, run hugo build --environment staging. The analytics code will use the G-SSSSSSSSS tag ID.

Merge configuration settings

Hugo merges configuration settings from themes and modules, prioritizing the project's own settings. Given this simplified project structure with two themes:

project/
├── themes/
│   ├── theme-a/
│   │   └── hugo.toml
│   └── theme-b/
│       └── hugo.toml
└── hugo.toml

and this project-level configuration:

{{< code-toggle file=hugo >}} baseURL = 'https://example.org/' locale = 'en-us' title = 'My New Hugo Site' theme = ['theme-a','theme-b'] {{< /code-toggle >}}

Hugo merges settings in this order:

  1. Project configuration (hugo.toml in the project root)
  2. theme-a configuration
  3. theme-b configuration

The _merge setting within each top-level configuration key controls which settings are merged and how they are merged.

The value for _merge can be one of:

none
No merge.
shallow
Only add values for new keys.
deep
Add values for new keys, merge existing.

Note that you don't need to be so verbose as in the default setup below; a _merge value higher up will be inherited if not set.

{{< code-toggle file=hugo dataKey="config_helpers.mergeStrategy" skipHeader=true />}}

Note

Hugo can merge map configuration values from modules and themes into the project configuration, but cannot merge slice values. This applies to top-level slice keys such as menus, as well as to map keys whose values are slices, such as the per-kind format lists in outputs.

Environment variables

You can also configure settings using operating system environment variables:

export HUGO_BASEURL=https://example.org/
export HUGO_ENABLEGITINFO=true
export HUGO_ENVIRONMENT=staging
hugo

The above sets the baseURL, enableGitInfo, and environment configuration options and then builds your site.

Note

An environment variable takes precedence over the values set in the configuration file. This means that if you set a configuration value with both an environment variable and in the configuration file, the value in the environment variable will be used.

Environment variables simplify configuration for CI/CD platforms by allowing you to set values directly within their respective configuration and workflow files.

Note

Environment variable names must be prefixed with HUGO_.

To set custom site parameters, prefix the name with HUGO_PARAMS_.

For snake_case variable names, the standard HUGO_ prefix won't work. Hugo infers the delimiter from the first character following HUGO. This allows for variations like HUGOxPARAMSxAPI_KEY=abcdefgh using any permitted delimiter.

In addition to configuring standard settings, environment variables may be used to override default values for certain internal settings:

DART_SASS_BINARY
(string) The absolute path to the Dart Sass executable. By default, Hugo searches for the executable in each of the paths in the PATH environment variable.
HUGO_FILE_LOG_FORMAT
(string) A format string for the file path, line number, and column number displayed when reporting errors, or when calling the Position method from a shortcode or Markdown render hook. Valid tokens are :file, :line, and :col. Default is :file::line::col.
HUGO_MEMORYLIMIT
(int) The maximum amount of system memory, in gigabytes, that Hugo can use while rendering your site. Default is 25% of total system memory. Note that HUGO_MEMORYLIMIT is a "best effort" setting. Don't expect Hugo to build a million pages with only 1 GB of memory. You can get more information about how this behaves during the build by running hugo build --logLevel info and look for the dynacache label.
HUGO_NUMWORKERMULTIPLIER
(int) The number of workers used in parallel processing. Default is the number of logical CPUs.

Current configuration

Display the complete project configuration with:

hugo config

Display a specific configuration setting with:

hugo config | grep [key]

Display the configured file mounts with:

hugo config mounts