Front matter
Overview
The front matter at the top of each content file is metadata that:
- Describes the content
- Augments the content
- Establishes relationships with other content
- Controls the published structure of your site
- Determines template selection
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.
See examples of front matter delimiters by toggling between the serialization formats below.
---
date: 2024-02-02T04:14:54-08:00
draft: false
params:
author: John Smith
title: Example
weight: 10
---
+++
date = 2024-02-02T04:14:54-08:00
draft = false
title = 'Example'
weight = 10
[params]
author = 'John Smith'
+++
{
"date": "2024-02-02T04:14:54-08:00",
"draft": false,
"params": {
"author": "John Smith"
},
"title": "Example",
"weight": 10
}
Front matter fields may be boolean, integer, float, string, arrays, or maps. Note that the TOML format also supports unquoted date/time values.
Fields
The most common front matter fields are date
, draft
, title
, and weight
, but you can specify metadata using any of fields below.
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 section for details.
- aliases
- (
string array
) An array of one or more aliases, where each alias is a relative URL that will redirect the browser to the current location. Access these values from a template using theAliases
method on aPage
object. See the aliases section for details. - build
- (
map
) A map of build options. - cascade
- (
map
) A map 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 section for details. - date
- (
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 section for examples. Access this value from a template using theDate
method on aPage
object. - description
- (
string
) Conceptually different than the pagesummary
, the description is typically rendered within ameta
element within thehead
element of the published HTML file. Access this value from a template using theDescription
method on aPage
object. - draft
- (
bool
) Whether to disable rendering unless you pass the--buildDrafts
flag to thehugo
command. Access this value from a template using theDraft
method on aPage
object. - expiryDate
- (
string
) The page expiration date. On or after the expiration date, the page will not be rendered unless you pass the--buildExpired
flag to thehugo
command. Note that the TOML format also supports unquoted date/time values. See the dates section for examples. Access this value from a template using theExpiryDate
method on aPage
object. - headless
- (
bool
) Applicable to leaf bundles, whether to set therender
andlist
build options tonever
, creating a headless bundle of page resources. - isCJKLanguage
- (
bool
) Whether the content language is in the CJK family. This value determines how Hugo calculates word count, and affects the values returned by theWordCount
,FuzzyWordCount
,ReadingTime
, andSummary
methods on aPage
object. - keywords
- (
string array
) An array of keywords, typically rendered within ameta
element within thehead
element of the published HTML file, or used as a taxonomy to classify content. Access these values from a template using theKeywords
method on aPage
object. - lastmod
- (
string
) The date that the page was last modified. Note that the TOML format also supports unquoted date/time values. See the dates section for examples. Access this value from a template using theLastmod
method on aPage
object. - layout
- (
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 theLayout
method on aPage
object. - linkTitle
- (
string
) Typically a shorter version of thetitle
. Access this value from a template using theLinkTitle
method on aPage
object. - markup
- (
string
) An identifier corresponding to one of the supported content formats. If not provided, Hugo determines the content renderer based on the file extension. - (
string
,string array
, ormap
) If set, Hugo adds the page to the given menu or menus. See the menus page for details. - modified
- Alias to lastmod.
- outputs
- (
string array
) The output formats to render. See configure outputs for more information. - params
- New in v0.123.0
- (
map
) A map of custom page parameters. - pubdate
- Alias to publishDate.
- publishDate
- (
string
) The page publication date. Before the publication date, the page will not be rendered unless you pass the--buildFuture
flag to thehugo
command. Note that the TOML format also supports unquoted date/time values. See the dates section for examples. Access this value from a template using thePublishDate
method on aPage
object. - published
- Alias to publishDate.
- resources
- (
map array
) An array of maps to provide metadata for page resources. - sitemap
- (
map
) A map of sitemap options. See the sitemap templates page for details. Access these values from a template using theSitemap
method on aPage
object. - slug
- (
string
) Overrides the last segment of the URL path. Not applicable to section pages. See the URL management page for details. Access this value from a template using theSlug
method on aPage
object. - summary
- (
string
) Conceptually different than the pagedescription
, 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 theSummary
method on aPage
object. - title
- (
string
) The page title. Access this value from a template using theTitle
method on aPage
object. - translationKey
- (
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 theTranslationKey
method on aPage
object. - type
- (
string
) The content type, overriding the value derived from the top-level section in which the page resides. Access this value from a template using theType
method on aPage
object. - unpublishdate
- Alias to expirydate.
- url
- (
string
) Overrides the entire URL path. Applicable to regular pages and section pages. See the URL management page for details. - weight
- (
int
) The page weight, used to order the page within a page collection. Access this value from a template using theWeight
method on aPage
object.
Parameters
New in v0.123.0Specify custom page parameters under the params
key in front matter:
---
date: 2024-02-02T04:14:54-08:00
draft: false
params:
author: John Smith
title: Example
weight: 10
---
+++
date = 2024-02-02T04:14:54-08:00
draft = false
title = 'Example'
weight = 10
[params]
author = 'John Smith'
+++
{
"date": "2024-02-02T04:14:54-08:00",
"draft": false,
"params": {
"author": "John Smith"
},
"title": "Example",
"weight": 10
}
Access these values from a template using the Params
or Param
method on a Page
object.
Hugo provides embedded templates to optionally insert meta data within the head
element of your rendered pages. These embedded templates expect the following front matter parameters:
Parameter | Data type | Used by these embedded templates |
---|---|---|
audio | []string | opengraph.html |
images | []string | opengraph.html , schema.html , twitter_cards.html |
videos | []string | opengraph.html |
The embedded templates will skip a parameter if not provided in front matter, but will throw an error if the data type is unexpected.
Taxonomies
Classify content by adding taxonomy terms to front matter. For example, with this site configuration:
taxonomies:
genre: genres
tag: tags
[taxonomies]
genre = 'genres'
tag = 'tags'
{
"taxonomies": {
"genre": "genres",
"tag": "tags"
}
}
Add taxonomy terms as shown below:
---
date: 2024-02-02T04:14:54-08:00
draft: false
genres:
- mystery
- romance
params:
author: John Smith
tags:
- red
- blue
title: Example
weight: 10
---
+++
date = 2024-02-02T04:14:54-08:00
draft = false
genres = ['mystery', 'romance']
tags = ['red', 'blue']
title = 'Example'
weight = 10
[params]
author = 'John Smith'
+++
{
"date": "2024-02-02T04:14:54-08:00",
"draft": false,
"genres": [
"mystery",
"romance"
],
"params": {
"author": "John Smith"
},
"tags": [
"red",
"blue"
],
"title": "Example",
"weight": 10
}
You can add taxonomy terms to the front matter of any these page kinds:
home
page
section
taxonomy
term
Access taxonomy terms from a template using the Params
or GetTerms
method on a Page
object. For example:
{{ with .GetTerms "tags" }}
<p>Tags</p>
<ul>
{{ range . }}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
{{ end }}
</ul>
{{ end }}
Cascade
A node 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 node has already cascaded a value for that same field.
For example, to cascade a “color” parameter from the home page to all its descendants:
---
cascade:
params:
color: red
title: Home
---
+++
title = 'Home'
[cascade]
[cascade.params]
color = 'red'
+++
{
"cascade": {
"params": {
"color": "red"
}
},
"title": "Home"
}
Target
The target
1 keyword allows you to target specific pages or environments. For example, to cascade a “color” parameter from the home page only to pages within the “articles” section, including the “articles” section page itself:
---
cascade:
params:
color: red
target:
path: '{/articles,/articles/**}'
title: Home
---
+++
title = 'Home'
[cascade]
[cascade.params]
color = 'red'
[cascade.target]
path = '{/articles,/articles/**}'
+++
{
"cascade": {
"params": {
"color": "red"
},
"target": {
"path": "{/articles,/articles/**}"
}
},
"title": "Home"
}
Use any combination of these keywords to target pages and/or environments:
- environment
- (
string
) A glob pattern matching the build environment. For example:{staging,production}
. - kind
- (
string
) A glob pattern matching the page kind. For example:{taxonomy,term}
. - path
- (
string
) A glob pattern matching the page’s logical path. For example:{/books,/books/**}
.
Array
Define an array of cascade parameters to apply different values to different targets. For example:
---
cascade:
- params:
color: red
target:
kind: page
path: '{/books/**}'
- params:
color: blue
target:
kind: page
path: '{/films/**}'
title: Home
---
+++
title = 'Home'
[[cascade]]
[cascade.params]
color = 'red'
[cascade.target]
kind = 'page'
path = '{/books/**}'
[[cascade]]
[cascade.params]
color = 'blue'
[cascade.target]
kind = 'page'
path = '{/films/**}'
+++
{
"cascade": [
{
"params": {
"color": "red"
},
"target": {
"kind": "page",
"path": "{/books/**}"
}
},
{
"params": {
"color": "blue"
},
"target": {
"kind": "page",
"path": "{/films/**}"
}
}
],
"title": "Home"
}
For multilingual sites, defining cascade values in your site configuration is often more efficient. This avoids repeating the same cascade values on the home, section, taxonomy, or term page for each language. See details.
If you choose to define cascade values in front matter for a multilingual site, you must create a corresponding home, section, taxonomy, or term page for every language.
Emacs Org Mode
If your content format is Emacs Org Mode, you may provide front matter using Org Mode keywords. For example:
#+TITLE: Example
#+DATE: 2024-02-02T04:14:54-08:00
#+DRAFT: false
#+AUTHOR: John Smith
#+GENRES: mystery
#+GENRES: romance
#+TAGS: red
#+TAGS: blue
#+WEIGHT: 10
Note that you can also specify array elements on a single line:
#+TAGS[]: red blue
Dates
When populating a date field, whether a custom page parameter or one of the four predefined fields (date
, expiryDate
, lastmod
, publishDate
), use one of these parsable formats:
Format | Time zone |
---|---|
2023-10-15T13:18:50-07:00 | America/Los_Angeles |
2023-10-15T13:18:50-0700 | America/Los_Angeles |
2023-10-15T13:18:50Z | Etc/UTC |
2023-10-15T13:18:50 | Default is Etc/UTC |
2023-10-15 | Default is Etc/UTC |
15 Oct 2023 | Default is Etc/UTC |
The last three examples are not fully qualified, and default to the Etc/UTC
time zone.
To override the default time zone, set the timeZone
in your site configuration. The order of precedence for determining the time zone is:
- The time zone offset in the date/time string
- The time zone specified in your site configuration
- The
Etc/UTC
time zone
The
_target
alias fortarget
is deprecated and will be removed in a future release. ↩︎