Skip to the content.

GitHub Pages Doesn’t Render Mermaid (But Can Be Fixed)

The Problem

GitHub.com shows mermaid diagrams beautifully when viewing markdown files. GitHub Pages (Jekyll) does not. Your diagrams appear as code blocks.

Why

The Fix

Create _layouts/default.html that:

  1. Extends your theme’s default layout
  2. Includes mermaid.js from CDN
  3. Initializes it with startOnLoad: true

Key lines:

<script type="module">
  import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
  mermaid.initialize({
    startOnLoad: true,
    theme: 'default'
  });
</script>

What Doesn’t Work

The Lesson

GitHub’s markdown rendering and GitHub Pages markdown rendering are different systems. What works in repo preview may not work on Pages. Always test the actual Pages site.

Applied In