| 1 |
--- |
| 2 |
title: Front matter |
| 3 |
description: Use front matter to add metadata to your content. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
aliases: [/content/front-matter/] |
| 7 |
--- |
| 8 |
|
| 9 |
## Overview |
| 10 |
|
| 11 |
The front matter at the top of each content file is metadata that: |
| 12 |
|
| 13 |
- Describes the content |
| 14 |
- Augments the content |
| 15 |
- Establishes relationships with other content |
| 16 |
- Controls the published structure of your site |
| 17 |
- Determines template selection |
| 18 |
|
| 19 |
Provide front matter using a serialization format, one of [JSON][], [TOML][], or [YAML][]. Hugo determines the front matter format by examining the delimiters that separate the front matter from the page content. |
| 20 |
|
| 21 |
See examples of front matter delimiters by toggling between the serialization formats below. |
| 22 |
|
| 23 |
{{< code-toggle file=content/example.md fm=true >}} |
| 24 |
title = 'Example' |
| 25 |
date = 2024-02-02T04:14:54-08:00 |
| 26 |
draft = false |
| 27 |
weight = 10 |
| 28 |
[params] |
| 29 |
author = 'John Smith' |
| 30 |
{{< /code-toggle >}} |
| 31 |
|
| 32 |
Front matter fields may be [boolean](g), [integer](g), [float](g), [string](g), [arrays](g), or [maps](g). Note that the TOML format also supports unquoted date/time values. |
| 33 |
|
| 34 |
## Fields |
| 35 |
|
| 36 |
The most common front matter fields are `date`, `draft`, `title`, and `weight`, but you can specify metadata using any of fields below. |
| 37 |
|
| 38 |
> [!NOTE] |
| 39 |
> The field names below are reserved. For example, you cannot create a custom field named `type`. Create custom fields under the `params` key. See the [parameters](#parameters) section for details. |
| 40 |
|
| 41 |
`aliases` |
| 42 |
: (`[]string`) An array of one or more [page-relative](g) or [site-relative](g) paths that should redirect to the current page. Hugo resolves these to [server-relative](g) URLs during the build process. Access these values from a template using the [`Aliases`][] method on a `Page` object. See the [aliases][] section for details. |
| 43 |
|
| 44 |
`build` |
| 45 |
: (`map`) A map of [build options][]. |
| 46 |
|
| 47 |
`cascade` |
| 48 |
: (`map`) A map (or array of maps) of front matter keys whose values are passed down to the page's descendants unless overwritten by self or a closer ancestor's cascade. See the [cascade](#cascade-1) section for details. |
| 49 |
|
| 50 |
`date` |
| 51 |
: (`string`) The date associated with the page, typically the creation date. Note that the TOML format also supports unquoted date/time values. See the [dates](#dates) section for examples. Access this value from a template using the [`Date`][] method on a `Page` object. |
| 52 |
|
| 53 |
`description` |
| 54 |
: (`string`) Conceptually different than the page `summary`, the description is typically rendered within a `meta` element within the `head` element of the published HTML file. Access this value from a template using the [`Description`][] method on a `Page` object. |
| 55 |
|
| 56 |
`draft` |
| 57 |
: (`bool`) Whether to disable rendering unless you pass the `--buildDrafts` flag to the `hugo` command. Access this value from a template using the [`Draft`][] method on a `Page` object. |
| 58 |
|
| 59 |
`expiryDate` |
| 60 |
: (`string`) The page expiration date. On or after the expiration date, the page will not be rendered unless you pass the `--buildExpired` flag to the `hugo` command. Note that the TOML format also supports unquoted date/time values. See the [dates](#dates) section for examples. Access this value from a template using the [`ExpiryDate`][] method on a `Page` object. |
| 61 |
|
| 62 |
`headless` |
| 63 |
: (`bool`) Applicable to [leaf bundles][], whether to set the `render` and `list` [build options][] to `never`, creating a headless bundle of [page resources][]. |
| 64 |
|
| 65 |
`isCJKLanguage` |
| 66 |
: (`bool`) Whether the content language is in the [CJK](g) family. This value determines how Hugo calculates word count, and affects the values returned by the [`WordCount`][], [`FuzzyWordCount`][], [`ReadingTime`][], and [`Summary`][] methods on a `Page` object. |
| 67 |
|
| 68 |
`keywords` |
| 69 |
: (`[]string`) An array of keywords, typically rendered within a `meta` element within the `head` element of the published HTML file, or used as a [taxonomy](g) to classify content. Access these values from a template using the [`Keywords`][] method on a `Page` object. |
| 70 |
|
| 71 |
`lastmod` |
| 72 |
: (`string`) The date that the page was last modified. Note that the TOML format also supports unquoted date/time values. See the [dates](#dates) section for examples. Access this value from a template using the [`Lastmod`][] method on a `Page` object. |
| 73 |
|
| 74 |
`layout` |
| 75 |
: (`string`) Provide a template name to [target a specific template][], overriding the default [template lookup order][]. Set the value to the base file name of the template, excluding its extension. Access this value from a template using the [`Layout`][] method on a `Page` object. |
| 76 |
|
| 77 |
`linkTitle` |
| 78 |
: (`string`) Typically a shorter version of the `title`. Access this value from a template using the [`LinkTitle`][] method on a `Page` object. |
| 79 |
|
| 80 |
`markup` |
| 81 |
: (`string`) An identifier corresponding to one of the supported [content formats][]. If not provided, Hugo determines the content renderer based on the file extension. |
| 82 |
|
| 83 |
`menus` |
| 84 |
: (`string`, `[]string`, or `map`) If set, Hugo adds the page to the given menu or menus. See the [menus][] page for details. |
| 85 |
|
| 86 |
`modified` |
| 87 |
: Alias to [lastmod](#lastmod). |
| 88 |
|
| 89 |
`outputs` |
| 90 |
: (`[]string`) The [output formats][] to render. See [configure outputs][] for more information. |
| 91 |
|
| 92 |
`params` |
| 93 |
: (`map`) A map of custom [page parameters](#parameters). |
| 94 |
|
| 95 |
`pubdate` |
| 96 |
: Alias to [publishDate](#publishdate). |
| 97 |
|
| 98 |
`publishDate` |
| 99 |
: (`string`) The page publication date. Before the publication date, the page will not be rendered unless you pass the `--buildFuture` flag to the `hugo` command. Note that the TOML format also supports unquoted date/time values. See the [dates](#dates) section for examples. Access this value from a template using the [`PublishDate`][] method on a `Page` object. |
| 100 |
|
| 101 |
`published` |
| 102 |
: Alias to [publishDate](#publishdate). |
| 103 |
|
| 104 |
`resources` |
| 105 |
: (`map array`) An array of maps to provide metadata for [page resources][]. Each element supports the `src`, `name`, `title`, and `params` keys. |
| 106 |
|
| 107 |
`sitemap` |
| 108 |
: (`map`) A map of sitemap options. See the [sitemap templates][] page for details. Access these values from a template using the [`Sitemap`][] method on a `Page` object. |
| 109 |
|
| 110 |
`sites` |
| 111 |
: {{< new-in 0.153.0 />}} |
| 112 |
: (`map`) A map to define [sites matrix](g) and [sites complements](g) for the page. |
| 113 |
|
| 114 |
<!-- markdownlint-disable MD049 --> |
| 115 |
|
| 116 |
{{< code-toggle file=content/_index.md fm=true >}} |
| 117 |
title = 'Home' |
| 118 |
[sites.matrix] |
| 119 |
languages = ["en","fr"] |
| 120 |
versions = ["v1.2.*","v2.*.*"] |
| 121 |
roles = ["**"] |
| 122 |
[sites.complements] |
| 123 |
versions = ["v3.*.*"] |
| 124 |
{{< /code-toggle >}} |
| 125 |
|
| 126 |
<!-- markdownlint-enable MD049 --> |
| 127 |
|
| 128 |
`slug` |
| 129 |
: (`string`) Overrides the last segment of the URL path. Not applicable to `home`, `section`, `taxonomy`, or `term` pages. See the [URL management][] page for details. Access this value from a template using the [`Slug`][] method on a `Page` object. |
| 130 |
|
| 131 |
`summary` |
| 132 |
: (`string`) Conceptually different than the page `description`, the summary either summarizes the content or serves as a teaser to encourage readers to visit the page. Access this value from a template using the [`Summary`][] method on a `Page` object. |
| 133 |
|
| 134 |
`title` |
| 135 |
: (`string`) The page title. Access this value from a template using the [`Title`][] method on a `Page` object. |
| 136 |
|
| 137 |
`translationKey` |
| 138 |
: (`string`) An arbitrary value used to relate two or more translations of the same page, useful when the translated pages do not share a common path. Access this value from a template using the [`TranslationKey`][] method on a `Page` object. |
| 139 |
|
| 140 |
`type` |
| 141 |
: (`string`) The [content type](g), overriding the value derived from the top-level section in which the page resides. Access this value from a template using the [`Type`][] method on a `Page` object. |
| 142 |
|
| 143 |
`unpublishdate` |
| 144 |
: Alias to [expirydate](#expirydate). |
| 145 |
|
| 146 |
`url` |
| 147 |
: (`string`) Overrides the entire URL path. Applicable to regular pages and section pages. See the [URL management][] page for details. |
| 148 |
|
| 149 |
`weight` |
| 150 |
: (`int`) The page [weight](g), used to order the page within a [page collection](g). Access this value from a template using the [`Weight`][] method on a `Page` object. |
| 151 |
|
| 152 |
## Parameters |
| 153 |
|
| 154 |
Specify custom page parameters under the `params` key in front matter: |
| 155 |
|
| 156 |
{{< code-toggle file=content/example.md fm=true >}} |
| 157 |
title = 'Example' |
| 158 |
date = 2024-02-02T04:14:54-08:00 |
| 159 |
draft = false |
| 160 |
weight = 10 |
| 161 |
[params] |
| 162 |
author = 'John Smith' |
| 163 |
{{< /code-toggle >}} |
| 164 |
|
| 165 |
Access these values from a template using the [`Params`][] or [`Param`][] method on a `Page` object. |
| 166 |
|
| 167 |
## Taxonomies |
| 168 |
|
| 169 |
Classify content by adding taxonomy terms to front matter. For example, with this project configuration: |
| 170 |
|
| 171 |
{{< code-toggle file=hugo >}} |
| 172 |
[taxonomies] |
| 173 |
tag = 'tags' |
| 174 |
genre = 'genres' |
| 175 |
{{< /code-toggle >}} |
| 176 |
|
| 177 |
Add taxonomy terms as shown below: |
| 178 |
|
| 179 |
{{< code-toggle file=content/example.md fm=true >}} |
| 180 |
title = 'Example' |
| 181 |
date = 2024-02-02T04:14:54-08:00 |
| 182 |
draft = false |
| 183 |
weight = 10 |
| 184 |
tags = ['red','blue'] |
| 185 |
genres = ['mystery','romance'] |
| 186 |
[params] |
| 187 |
author = 'John Smith' |
| 188 |
{{< /code-toggle >}} |
| 189 |
|
| 190 |
You can add taxonomy terms to the front matter of any these [page kinds](g): |
| 191 |
|
| 192 |
- `home` |
| 193 |
- `page` |
| 194 |
- `section` |
| 195 |
- `taxonomy` |
| 196 |
- `term` |
| 197 |
|
| 198 |
Access taxonomy terms from a template using the [`Params`][] or [`GetTerms`][] method on a `Page` object. For example: |
| 199 |
|
| 200 |
```go-html-template {file="layouts/page.html"} |
| 201 |
{{ with .GetTerms "tags" }} |
| 202 |
<p>Tags</p> |
| 203 |
<ul> |
| 204 |
{{ range . }} |
| 205 |
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li> |
| 206 |
{{ end }} |
| 207 |
</ul> |
| 208 |
{{ end }} |
| 209 |
``` |
| 210 |
|
| 211 |
## Cascade |
| 212 |
|
| 213 |
> [!NOTE] |
| 214 |
> For multilingual projects, defining cascade values in your project configuration is often more efficient. This avoids repeating the same cascade values for each language. See [details][]. |
| 215 |
|
| 216 |
A [branch](g) can cascade front matter values to its descendants. However, this cascading will be prevented if the descendant already defines the field, or if a closer ancestor branch has already cascaded a value for that same field. |
| 217 |
|
| 218 |
For example, to cascade the `color` page parameter from the home page to all its descendants: |
| 219 |
|
| 220 |
{{< code-toggle file=content/_index.md fm=true >}} |
| 221 |
title = 'Home' |
| 222 |
[cascade.params] |
| 223 |
color = 'red' |
| 224 |
{{< /code-toggle >}} |
| 225 |
|
| 226 |
### Target |
| 227 |
|
| 228 |
<!-- TODO |
| 229 |
We deprecated the `_target` front matter key in favor of `target` in v0.156.0 on 2026-02-17. Remove footnote #1 somewhere after v0.171.0, 15 minor releases |
| 230 |
after deprecation. |
| 231 |
--> |
| 232 |
|
| 233 |
The `target` key accepts a [page matcher](g) to limit cascaded values to a subset of pages.[^1] If a target is not specified, values cascade to all descendant pages. |
| 234 |
|
| 235 |
{{% include "/_common/configuration/page-matcher.md" %}} |
| 236 |
|
| 237 |
For example, to cascade the `color` page parameter from the home page to the `articles` section and its descendants: |
| 238 |
|
| 239 |
{{< code-toggle file=hugo >}} |
| 240 |
[cascade.params] |
| 241 |
color = 'red' |
| 242 |
[cascade.target] |
| 243 |
path = '{/articles,/articles/**}' |
| 244 |
{{< /code-toggle >}} |
| 245 |
|
| 246 |
### Array |
| 247 |
|
| 248 |
Define an array of cascade maps to apply different values to different targets. For example: |
| 249 |
|
| 250 |
{{< code-toggle file=content/_index.md fm=true >}} |
| 251 |
title = 'Home' |
| 252 |
[[cascade]] |
| 253 |
[cascade.params] |
| 254 |
color = 'red' |
| 255 |
[cascade.target] |
| 256 |
path = '{/articles,/articles/**}' |
| 257 |
[[cascade]] |
| 258 |
[cascade.params] |
| 259 |
color = 'blue' |
| 260 |
[cascade.target] |
| 261 |
path = '{/tutorials,/tutorials/**}' |
| 262 |
{{< /code-toggle >}} |
| 263 |
|
| 264 |
## Emacs Org Mode |
| 265 |
|
| 266 |
If your [content format][] is [Emacs Org Mode][], you may provide front matter using Org Mode keywords. For example: |
| 267 |
|
| 268 |
```text {file="content/example.org"} |
| 269 |
#+TITLE: Example |
| 270 |
#+DATE: 2024-02-02T04:14:54-08:00 |
| 271 |
#+DRAFT: false |
| 272 |
#+AUTHOR: John Smith |
| 273 |
#+GENRES: mystery |
| 274 |
#+GENRES: romance |
| 275 |
#+TAGS: red |
| 276 |
#+TAGS: blue |
| 277 |
#+WEIGHT: 10 |
| 278 |
``` |
| 279 |
|
| 280 |
Note that you can also specify array elements on a single line: |
| 281 |
|
| 282 |
```text {file="content/example.org"} |
| 283 |
#+TAGS[]: red blue |
| 284 |
``` |
| 285 |
|
| 286 |
## Dates |
| 287 |
|
| 288 |
When populating a date field, whether a [custom page parameter](#parameters) or one of the four predefined fields ([`date`](#date), [`expiryDate`](#expirydate), [`lastmod`](#lastmod), [`publishDate`](#publishdate)), use one of these parsable formats: |
| 289 |
|
| 290 |
{{% include "/_common/parsable-date-time-strings.md" %}} |
| 291 |
|
| 292 |
To override the default time zone, set the [`timeZone`][] in your project configuration. The order of precedence for determining the time zone is: |
| 293 |
|
| 294 |
1. The time zone offset in the date/time string |
| 295 |
1. The time zone specified in your project configuration |
| 296 |
1. The `Etc/UTC` time zone |
| 297 |
|
| 298 |
[^1]: The `_target` alias for `target` is deprecated and will be removed in a future release. |
| 299 |
|
| 300 |
[Emacs Org Mode]: https://orgmode.org/ |
| 301 |
[JSON]: https://www.json.org/ |
| 302 |
[TOML]: https://toml.io/ |
| 303 |
[URL management]: /content-management/urls/#slug |
| 304 |
[YAML]: https://yaml.org/ |
| 305 |
[`Aliases`]: /methods/page/aliases/ |
| 306 |
[`Date`]: /methods/page/date/ |
| 307 |
[`Description`]: /methods/page/description/ |
| 308 |
[`Draft`]: /methods/page/draft/ |
| 309 |
[`ExpiryDate`]: /methods/page/expirydate/ |
| 310 |
[`FuzzyWordCount`]: /methods/page/wordcount/ |
| 311 |
[`GetTerms`]: /methods/page/getterms/ |
| 312 |
[`Keywords`]: /methods/page/keywords/ |
| 313 |
[`Lastmod`]: /methods/page/date/ |
| 314 |
[`Layout`]: /methods/page/layout/ |
| 315 |
[`LinkTitle`]: /methods/page/linktitle/ |
| 316 |
[`Param`]: /methods/page/param/ |
| 317 |
[`Params`]: /methods/page/params/ |
| 318 |
[`PublishDate`]: /methods/page/publishdate/ |
| 319 |
[`ReadingTime`]: /methods/page/readingtime/ |
| 320 |
[`Sitemap`]: /methods/page/sitemap/ |
| 321 |
[`Slug`]: /methods/page/slug/ |
| 322 |
[`Summary`]: /methods/page/summary/ |
| 323 |
[`Title`]: /methods/page/title/ |
| 324 |
[`TranslationKey`]: /methods/page/translationkey/ |
| 325 |
[`Type`]: /methods/page/type/ |
| 326 |
[`Weight`]: /methods/page/weight/ |
| 327 |
[`WordCount`]: /methods/page/wordcount/ |
| 328 |
[`timeZone`]: /configuration/all/#timezone |
| 329 |
[aliases]: /content-management/urls/#aliases |
| 330 |
[build options]: /content-management/build-options/ |
| 331 |
[configure outputs]: /configuration/outputs/#outputs-per-page |
| 332 |
[content format]: /content-management/formats/ |
| 333 |
[content formats]: /content-management/formats/#classification |
| 334 |
[details]: /configuration/cascade/ |
| 335 |
[leaf bundles]: /content-management/page-bundles/#leaf-bundles |
| 336 |
[menus]: /content-management/menus/#define-in-front-matter |
| 337 |
[output formats]: /configuration/output-formats/ |
| 338 |
[page resources]: /content-management/page-resources/#metadata |
| 339 |
[sitemap templates]: /templates/sitemap/ |
| 340 |
[target a specific template]: /templates/lookup-order/#target-a-template |
| 341 |
[template lookup order]: /templates/lookup-order/ |