Blog › Jekyll

Keeping the Jekyll Chirpy table of contents always expanded

Stop Jekyll Chirpy's right-hand table of contents from collapsing on scroll by overriding tocbot's .is-collapsed rule in assets/css/jekyll-theme-chirpy.scss.

Keeping the Jekyll Chirpy table of contents always expanded

On long technical posts, the right-hand table of contents (TOC) acts as a live outline. By default, Jekyll Chirpy collapses inactive subsections as you scroll, hiding the rest of the structure. Here is why that happens inside tocbot and how to keep the TOC permanently expanded using Chirpy’s official SCSS override entry point.

Verified with jekyll-theme-chirpy v7.x (gem-based starter) and Jekyll 4.x.


The problem: collapsing subsections on scroll

Chirpy scans every <h2> and <h3> heading inside a post and renders a sticky TOC panel on the right side of desktop viewports.

Once I started writing longer troubleshooting and architecture posts, the default behavior got in the way:

  • As you scroll down into a section, tocbot collapses every other <h3> group in the sidebar.
  • To jump back to an earlier subsection or scan the full outline of a post, you have to scroll up or click around just to see what headings exist.
Before (Chirpy default)After (always expanded)
Korean table of contents with inactive subsections collapsedKorean table of contents with all headings expanded
Inactive subsections collapse as you scrollThe full post outline stays visible at all times

Figure 1. The same post on the Korean edition before and after the TOC change.

I wanted the entire heading tree visible at a glance while keeping the active-section highlight as you scroll.


Root cause: how Chirpy and tocbot hide subsections

Inspecting the TOC panel in Chrome DevTools shows that Chirpy delegates TOC rendering and scroll spying to tocbot. The generated DOM looks like this:

1
2
3
4
5
6
<!-- Chirpy right-hand TOC DOM structure -->
<nav id="toc">
  <ul class="toc-list is-collapsible is-collapsed">
    <li class="toc-list-item">...</li>
  </ul>
</nav>

Two mechanisms work together here:

  1. JavaScript scroll spy: Whenever the active heading changes, tocbot removes .is-collapsed from the active branch’s nested <ul class="toc-list"> and adds .is-collapsed to every inactive branch.
  2. Theme stylesheet rule: Chirpy’s compiled CSS defines .is-collapsed with max-height: 0 and overflow: hidden:
1
2
3
4
5
6
/* Default rule shipped by Chirpy / tocbot */
.is-collapsed {
  max-height: 0;
  overflow: hidden;
  transition: all 0.2s ease-in-out;
}

Because the collapse animation is driven purely by CSS (max-height: 0), we do not need to fork Chirpy’s JavaScript bundle or override tocbot.init({ collapseDepth: 6 }). Overriding max-height on .is-collapsed keeps every nested list open while preserving tocbot’s active-link highlighting and smooth scrolling.

When not to force the TOC open

Keeping the TOC permanently expanded works best when posts have 4–7 <h2> sections and a moderate number of <h3> headings (roughly 10–25 total items). If your posts routinely contain 40+ nested headings, an always-open TOC will overflow the viewport height and require its own inner scrollbar—in that case, leaving tocbot’s default auto-collapse enabled is actually easier to scan.


The fix: overriding SCSS the right way

The CSS change itself is three lines, but putting it in the wrong file breaks a gem-based Chirpy site.

flowchart TD
    A["Mistake: editing style.css directly"] -->|"Overwritten on Jekyll build"| B["Theme styles broken or lost"]
    C["Fix: assets/css/jekyll-theme-chirpy.scss"] -->|"Sass pipeline compile"| D["Safe custom override applied"]

What not to do: editing _site/ or creating a separate style.css

My first attempt was editing _site/assets/css/style.css or dropping an ad-hoc assets/css/style.scss file into the repository. Jekyll wipes _site/ on every rebuild, and creating a conflicting stylesheet name can shadow the gem’s compiled bundle and strip out the entire theme layout.

The supported entry point: assets/css/jekyll-theme-chirpy.scss

Chirpy exposes assets/css/jekyll-theme-chirpy.scss as its official extension hook. When this file exists in your repository, Jekyll’s Sass compiler loads the theme’s core @use 'main...' bundle first and appends your custom rules at the bottom of the compiled CSS.

1. Create the override file with Chirpy’s required header

Create assets/css/jekyll-theme-chirpy.scss at the project root and keep the empty Front Matter dashes and @use statement intact:

1
2
3
4
5
6
7
8
9
10
---
---

@use 'main
{%- if jekyll.environment == 'production' -%}
  .bundle
{%- endif -%}
';

/* append your custom style below */

Do not remove the empty --- Front Matter markers or the @use 'main...' block. Without the Front Matter header, Jekyll treats the file as a static asset and never runs Sass on it; without @use, you lose the entire Chirpy stylesheet.

2. Override .is-collapsed

Append the override rule at the bottom of assets/css/jekyll-theme-chirpy.scss:

1
2
3
4
5
// assets/css/jekyll-theme-chirpy.scss
/* Keep the right-hand table of contents always expanded */
#toc .is-collapsed {
  max-height: none !important;
}

Scoping the selector to #toc .is-collapsed (instead of a bare .is-collapsed) avoids accidentally affecting any other collapsible component that might reuse the same utility class later.


Verification on desktop and mobile

Start the local server and test both a production and development build:

1
bundle exec jekyll serve --livereload

Check two viewports in DevTools:

  1. Desktop (>= 1200px): Scroll from the top of a long post all the way to the footer. Every <h2> and <h3> item stays visible in the right sidebar, and the active heading indicator still tracks your scroll position accurately.
  2. Mobile and tablet (390px–1024px): Chirpy hides the right sidebar on narrower screens and shows a floating TOC button (#toc-solo-trigger) that opens a popup modal. Confirm that the modal still opens and closes cleanly with no layout overlap.

You can also inspect the compiled CSS in _site/assets/css/jekyll-theme-chirpy.css after running JEKYLL_ENV=production bundle exec jekyll build to confirm your rule appears at the end of the production bundle.


Caveats and checklist

  • Upgrading Chirpy: Because you only touch assets/css/jekyll-theme-chirpy.scss and import main via @use, future bundle update jekyll-theme-chirpy upgrades keep your override intact unless Chirpy changes its #toc DOM structure.
  • Check heading hygiene: Once every heading stays visible, accidental <h2> tags injected by third-party plugins become immediately obvious in the sidebar (I ran into that exact issue with OpenGraph link preview cards).
  • Avoid !important sprawl: !important is justified here because tocbot toggles inline or late-loaded collapse rules, but keep the selector scoped to #toc .is-collapsed.

Verification checklist

  • assets/css/jekyll-theme-chirpy.scss includes the empty --- Front Matter and @use 'main...' header
  • #toc .is-collapsed { max-height: none !important; } appended at the bottom
  • Verified in both jekyll serve (dev) and JEKYLL_ENV=production bundle exec jekyll build (prod)
  • Checked desktop scroll tracking and mobile TOC popup modal
This post is licensed under CC BY 4.0 by the author.