---
title: "Frontmatter"
description: "Add a leading YAML block to declare document metadata that Comark parses into document.frontmatter."
canonical_url: "https://comark.dev/syntax/frontmatter"
---
# Frontmatter

> Add a leading YAML block to declare document metadata that Comark parses into document.frontmatter.

Comark parses YAML frontmatter at the start of a document using the built-in [`frontmatter` plugin](https://comark.dev/plugins/defaults/frontmatter), which is enabled by default.

## Syntax

```mdc
---
title: My Document Title
author: John Doe
date: 2024-01-15
tags:
  - markdown
  - documentation
depth: 3
searchDepth: 2
custom_field: custom value
---

# Document Content

Your Markdown content here...
```

### Rules

- Must be at the **very beginning** of the document (no leading blank lines)
- Enclosed by `---` delimiters
- Body is parsed as YAML
- Empty frontmatter (`---\n---` with no content) is ignored

## Parse result

The `frontmatter` property is available on the parse result:

~~~ts
import { parseMarkdown } from 'comark'

const content = `---
title: My Article
author: Jane Doe
---

# Hello World
`

const { frontmatter, nodes } = await parseMarkdown(content)
/*
frontmatter -> { title: 'My Article', author: 'Jane Doe' }
nodes       -> [ ['h1', { id: 'hello-world' }, 'Hello World'] ]
*/
~~~

See [Document model](https://comark.dev/getting-started/document-model#frontmatter) for how frontmatter sits on `MarkdownDocument`.

## Data binding

Reference frontmatter values in component props with the `:prop` binding syntax:

```mdc
---
theAnswer: 42
user:
  name: Ada
---

::question{:answer="frontmatter.theAnswer"}
::

Hello, :badge{:label="frontmatter.user.name"}
```

Learn more in [Data binding](https://comark.dev/syntax/components#data-binding).

## Disable

Set `registerDefaultPlugins: false` to disable the default plugins and treat `---` as a standard horizontal rule:

```ts
import { parseMarkdown } from 'comark'

const result = await parseMarkdown(content, {
  registerDefaultPlugins: false,
})
// result.frontmatter -> {}
```

See the [frontmatter plugin](https://comark.dev/plugins/defaults/frontmatter) for registration and options.

---

- [Frontmatter plugin](https://comark.dev/plugins/defaults/frontmatter)
- [Document model](https://comark.dev/getting-started/document-model)


## Sitemap

See the full [sitemap](https://comark.dev/sitemap.md) for all pages.
