How to Add Cover Images To Your Gridsome Posts

August 21, 2020 · Updated January 23, 2021 · 4 min read
A white picture frame in front of a landscape with a beach.
Photo by pine watt on Unsplash

This is part thirteen of a series on building a file-based blog from scratch with Gridsome. Find the full series here.

Your blog posts need images.

At least if you want more social shares and higher search engine rankings.

For Gridsome, there are two ways to add images to your blog posts

Add Cover Images Within Markdown

To add an image within markdown, add it to your blog's Git repository (under content/media). Then add it to the blog post with the markdown image syntax:

![A colorful building against a blue sky background](../media/victor-garcia-R8C2nUoSMfc-unsplash.jpg)
_Photo by [Victor Garcia]( on [Unsplash](

The syntax for adding images to markdown is ![Description](./path/to/image.jpg) I added the creator attribution in italics below.

This creates an image inside your blog post. You can add inline images with this syntax and also use them as cover images for your posts.

But this doesn't allow you to reference the image for e.g. social meta tags or from your blog post overview site.

For this, you need to add the image URL as an image property to the markdown frontmatter like this:

slug: "second-post"
date: "2020-06-12"
title: "Helvetica Coloring"
tags: ["frontend", "design", "hipster"]
summary: "Banh mi tilde swag beard. PBR&B disrupt affogato 8-bit fanny pack. Tacos fam brooklyn jean shorts."
image: ../media/victor-garcia-R8C2nUoSMfc-unsplash.jpg

This allows us to use the image property in the src/mixins/PostSEO.vue mixin we added in the last post.

But now we have the URL for the image doubled inside the blog post markdown file. This is where the second, cleaner approach to cover images enters the stage.

Add Cover Images as Front Matter

When we add the image path and its description to the blog post's front matter, we have all the info we need to add it to the src/templates/BlogPost.vue.

Add the necessary information to the front matter:

slug: "second-post"
date: "2020-06-12"
title: "Helvetica Coloring"
tags: ["frontend", "design", "hipster"]
summary: "Banh mi tilde swag beard. PBR&B disrupt affogato 8-bit fanny pack. Tacos fam brooklyn jean shorts."
  path: ../media/victor-garcia-R8C2nUoSMfc-unsplash.jpg
  alt: "A colorful building against a blue sky background"
  caption: '<span>Photo by <a href=";utm_medium=referral&amp;utm_content=creditCopyText">Victor Garcia</a> on <a href=";utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>'

You can copy the image attribution from Unsplash and paste into your code editor as HTML. Now edit the src/template/BlogPost.vue template and add the image.

    <h1 class="mb-2 text-2xl font-semibold text-strong">
      {{ $ }}
    <p class="mb-4 font-light text-gray-700">
      {{ $ }}
    <div class="flex flex-wrap mb-4 text-sm">
        v-for="tag in $"
        class="px-2 py-1 mb-4 mr-4 rounded-full bg-gray-300 dark:bg-gray-700 text-gray-700 dark:text-gray-300 hover:text-gray-300 hover:bg-gray-700 dark:hover:text-gray-700 dark:hover:bg-gray-300"
        {{ tag.title }}
    <!-- This is the figure element we added: -->
      class="flex flex-col"
        class="self-center image-caption mb-15"
      class="mb-16 markdown"

query Post ($path: String!) {
  post: blogPost (path: $path) {
    date (format: "MMMM D, Y")
    image {
    tags {

import PostSeo from '../mixins/Postseo'

export default {
  mixins: [PostSeo]

<style src="../css/markdown.css" />

Don't forget to load the image info in GraphQL.

Finally, add a new class for the image caption to your src/css/main.css.

.image-caption {
  @apply mb-5 text-soft text-sm;
  & a {
    @apply font-bold;

Next part: Forestry CMS for Gridsome posts

That’s it for this post on how to add cover image to your Gridsome blog posts. In the next part of this series, we integrate Forestry CMS.