Skip to content

Frontmatter

Frontmatter is a block of structured metadata at the very top of a text file — typically YAML delimited by three hyphens — that describes the document without being part of its content.

Definition

What it is

Frontmatter sits above the content, separated by a fixed delimiter. In Jekyll, Hugo, Eleventy and Astro, the delimiter is three hyphens:

---
title: Writing a slug
date: 2024-03-15
tags: [web, seo]
---

In TOML-based systems (Hugo's +++) or JSON ({...} at the top), the shape differs but the principle is the same: a machine-readable block that describes what follows. The content below is prose; the frontmatter above is a contract.

Why it matters

Without frontmatter, a static site generator must parse the prose to find the title, the date and the tags. Parsing prose is brittle: markdown headings, first paragraphs, and regex all fail on the same edge cases (nested quotes, escaped characters, mixed languages). Frontmatter fixes the shape: the metadata is declared once, in a predictable format, at a predictable position.

YAML vs TOML vs JSON

Aspect

YAML

TOML

JSON

Delimiter

---

+++

{ ... }

Typical tool

Jekyll, Eleventy, Astro

Hugo

Custom

Readability

High

High

Low (quotes, braces)

Indentation

Significant

Not significant

Required

Multi-line strings

`\

/>`

"""

Escape

Best for

Hand-edited config

Config-heavy sites

Machine output

Where frontmatter lives

graph LR
  F[Frontmatter] -->|delimiter| B[Body]
  F --> M[Metadata: title, date, tags]
  B --> R[Rendered HTML]
  M --> I[Indexes, feeds, sitemaps]
  style F fill:#FFF3E0
  style B fill:#E8F5E9

How to write frontmatter well

Frontmatter that stays sane

  1. Three hyphens, on their own lines

    The delimiter is --- at the beginning of a line. Not --- inline. Not ---yaml.

  2. Lowercase keys

    title, date, tags. Not Title or TITLE. Consistency beats cleverness.

  3. ISO 8601 dates

    2024-03-15T10:00:00-05:00. Ambiguous dates break on server timezone changes.

  4. Validate the schema

    A frontmatter with the wrong type (string where array expected) fails at build time, hours after commit. Validate on save.

Common failures

Origin

In book production, front matter is everything before the main text: half-title, title page, copyright, dedication, table of contents, preface, acknowledgements. It is not the body; it describes the body. Static site generators of the 2000s (Jekyll was the first to popularise the pattern, in 2008) borrowed the word: a short block of metadata above the content, describing it.

Jekyll uses a front matter block at the top of files to define variables, like the layout to use, the title, the date.

— Jekyll documentation, *Front Matter*, 2024
2008 · Jekyll populariza frontmatter YAML
2013 · Hugo lanza con soporte YAML, TOML y JSON
2018 · Eleventy adopta el formato de Jekyll
2020 · Astro añade validación de schema via Zod
3 · delimitadores aceptados`---`, `+++`, `{...}`

Evidence

FAQ

Why YAML and not TOML?

YAML is more readable for hand editing and has a wider ecosystem. TOML is stricter but less expressive for nested structures.

Can I mix YAML and TOML?

In Hugo, yes, per file. In most other tools, pick one. Mixing within a project is a configuration trap.

How do I handle a value with a colon?

Quote it: title: "Writing: a slug".

What if I need to put code in frontmatter?

Don't. Frontmatter is for metadata. Code goes in the body, or in a fenced block.

Connections

  • metadata
  • yaml
  • static-site-generator
  • markdown
  • schema

Etymology

Origin: borrowed

  • front (noun): from Latin frons, frontis, "forehead, front"
  • matter (noun): from Latin materia, "material, subject"

Semantic network

Frontmatterstatic-sitcontent-foMetadatayamlstatic-sitmarkdownschema

● broader ● narrower ● related

Broader

  • static-sites
  • content-format

Related

  • Metadata
  • yaml
  • static-site-generator
  • markdown
  • schema

Used in the garden

Sources