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

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

Comark supports YAML frontmatter at the beginning of documents. Parsing is provided by the built-in [`frontmatter` plugin](https://comark.dev/plugins/defaults/frontmatter) (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

Frontmatter values can be referenced in component props with the `:prefix` 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

Turn off all default plugins so the `---` block is treated as regular markdown:

```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.
