Use YAML Front Matter Correctly in Obsidian

Video made by @amyjuanli-work

If you’re an Obsidian user, there is a good chance that you already know something about YAML. It is simply a human-friendly way of adding metadata to our Obsidian notes. And today’s video is fully dedicated to learning how to use YAML correctly in our Obsidian notes. If you’re curious about the Obsidian Dataview plugin, then you must be inspired to learn YAML as it will help us take full advantage of that powerful Obsidian Plugin.

Before going over YAML, let’s first understand what is metadata.

What Is Metadata?

Metadata is just a set of data that describes and gives information about other data, but not the content of the data. — Wikipedia

Almost every digital file has some sort of metadata. If you take a picture with your phone or camera it will have a bunch of metadata, it’ll have its size, pixel resolution, file type, file name, etc.

Screenshot by Amy Li

Now that’s the metadata that gets automatically created, but we can also create our metadata in Obsidian notes.

Now bring the metadata concepts to Obsidian. Let’s say that you’re typing out a book note here on Obsidian. Some examples of metadata would be the book cover, author, category, highlights from the book, or maybe some tags, etc.

Screenshot by Amy Li

Suppose we have added ‘aliases’ metadata to the above file using the YAML block, then we could search this file using the alias as well as the original file title.

Screenshot by Amy Li

By creating metadata using YAML, we could quickly understand the key properties of a file by only looking at the metadata — such as the associated project, etc.

Screenshot by Amy Li

As you can see the power of adding metadata to our files. Next, let’s jump into the topic of how to create a valid YAML block step by step.

Create a Valid YAML Front Matter

YAML, also known as front matter, is designed to be file-level metadata that is readable by humans and Obsidian. — Obsidian. md — YAML front matter

File-level metadata simply means we cannot use the metadata across files. Have this out of our way, let’s read the doc definition of a valid YAML block.
According to the doc for a valid YAML Front Matter in Obsidian, we need to satisfy these two requirements:

  • A YAML block needs triple dashes at the start and end to be read by Obsidian (and other apps)
  • It also needs to be placed at the very top of the file.

A typical valid YAML block looks like this (key: value pairs)

---
key: value
key2: value2
key3: [one, two, three]
key4:
- four
- five
- six
---

To show the front matter as a code block, let’s toggle on the Show frontmatter from the Editor.

so with that out of the way, let’s close this and let’s do yaml annotation. to add a valid YAML, you need to add three dashes..enter and then another three dashes.. so what’s in between them is gonna be your YAML header .. so for instance, you can type tags colon evergreen_notes. .. remember there is no space allowed in tags.. now if we toggle on preview mode by clicking this icon or press cmd+E, Obsidian knows that we have a valid YAML header. although YAML is easy it is, however, picky with how you type it out. The first thing is YAML must be the first thing on your file page. if typing anything before YAML, it won’t work anymore. it doesn’t recognize it.

Valid YAML block. (left: editor mode, right: preview mode)

Besides the previous two requirements for a valid YAML — triple dashes and placed at the top of the file, there is also another crucial aspect which is the space between the colon and the beginning of your parameters, otherwise Obsidian will alarm you with an Invalid YAML.

Valid YAML block. (left: editor mode, right: preview mode)

Create Multiple Tags/Aliases

If you want to have multiple tags or multiple aliases, you need to add a comma after each one, use square brackets to surround the multiple values, or in the format of a list.

---
type: content, youtube
type: [content, youtube]
type:
- youtube
- content
---

In summary, to create a valid YAML block, we need to meet these three requirements:

  1. A YAML block needs triple dashes at the start and end to be read by Obsidian (and other apps)

2. It also needs to be placed at the very top of the file.

3. Add space between the colon and the beginning of the value for each key-value pair.

We just briefly showcased the metadata for tags and aliases which natively supported by Obsidian:

Source: https://help.obsidian.md/Advanced+topics/YAML+front+matter

But in this article, let’s focus on how to use aliases and tags correctly in YAML and make good use of them in Obsidian.

Use Aliases Correctly in Obsidian

Why do we bother using aliases?

Sometimes, you might want to refer to the same file with multiple names in different contexts. These alternative names are what we call “aliases”. — https://help.obsidian.md/How+to/Add+aliases+to+note

Create Aliases — Add Aliases to Note

You could create one alias

---
aliases: this is another name for this file
---

or multiple aliases:

---
aliases: demo aliases, this is a demo for aliases
aliases: [demo aliases, this is a demo for aliases]
---
aliases:
- demo aliases
- this is a demo for aliases
---

Use Aliases

Once we have set aliases for a file, we can write [[alias]] to link to the original page, or we could search the file by the alias.

Set aliases in YAML, and use them such as linking to the file or search the file with the aliases. GIF by Amy Li

Use Tags Correctly in Obsidian

Create Tags in YAML

you could just create one tag like below:

---
tags: content_video
---

Three ways of creating multiple tags

---
tags: content_video, content_blog
tags: [content_video, content_blog]
tags:
- content_video
- content_blog
- status_ongoing
- category_productivity
- pkm
- obsidian
---

Use the Tags With Autocompletion Feature

We could use tags like how we create them in the above. If the tags are not existing yet, they will be created for the first time.

But there is one problem with the above approaches. For example, I have already created a tag called content_videoo. Now I want to add some tags to my current note. So I have to type out the tag letter by letter which might end up creating some unnecessary new tags like video, or youtubeVideo, or contentVideo simply because I don’t know I have an existent tag named content_video. Well, of course, I could look through the tags on the tag panel to see what tags I could reuse for my new note, but it’s too much work. Imagine that there is an auto-completion list telling us which relevant tags are available. Luckily Obsidian has provided us with such a feature.

To enable the auto-completion for tags: just add  and insert a space before typing a # followed by the tag name as below:

---
tags: [" #content/blog #content/video"]
tags: " #content/blog #content/video"
tags:
- " #content/blog"
- " #content/video"
---
Demo the auto-completion for tags inside YAML block. GIF by Amy Li

The Potential Power of Self-defined Metadata in Obsidian

Although Obsidian only natively supports metadata from tags, aliases, CSS class, and publish, we can define whatever metadata we want in YAML. For example, I could add metadata named project to associate that note to a project I’ve worked on.

GIF by Amy Li

But we also notice that some metadata keys like aliases and tags are shown there under metadata, while the rest doesn’t get a spot in there like status, keywords, project, type, category, under Obsidian preview mode.

Visualize the metadata created by the YAML on the preview mode of Obsidian (Cmd + E). Screenshot by Amy Li

The reason is simply that they are not natively supported by the Obsidian which was mentioned before. But it doesn’t affect the potential power of these self-defined metadata. In particular, they will be very useful when it comes to data annotation by the Obsidian Dataview plugin.

An example of querying files using Dataview:

Demo the data query in Dataview which uses the metadata we defined for our notes. GIF by Amy Li

Wrap Up the Two Huge Benefits of Using YAML in Obsidian

Benefit 1: Make the note looks much cleaner

An example would be using tags in the YAML block or inside a note:

Left: having tags only YAML block. Right: having tags throughout a note. Screenshot by Amy Li

Although we could create metadata like tags anywhere inside our note, I think it’s much easier for us to have the metadata in the YAML block. Given the second requirement of creating a valid YAML that YAML needs to be placed at the top of the file, it makes our life much easier to track the metadata we have created for the note. We could easily make changes to the metadata inside the YAML block.

Benefit 2: We could easily define our metadata for our purpose

Although Obsidian has very limited support for metadata keys, it doesn’t prevent us from defining our metadata. And one of the most popular and powerful Obsidian plugins, Dataview, relies on the metadata we created for our note. It lets us annotate our notes, then we can query our notes based on them.

Visit more FREE tutorials on our website.

Index