--- title: tree-style table of contents layout: post-with-toc.njk image: src: 2026/tree-styling-0.png alt: "screenshot of the table of contents for a blog post (this blog post, in fact). it's been styled so that the output resembles the hierarchical file system output from the shell program 'tree.'" tags: - reference - software --- I have a shiny new Table of Contents (hereafter ToC) section for some of my posts (like this one)! And for fun and profit, it's styled like the output of [`tree`](https://en.wikipedia.org/wiki/Tree_(command)). I want to lay out the CSS I used for this. Fair warning, there's some hyper-specific border widths and positioning that *probably* should be a `calc()` function of some kind. I drew inspiration from this [StackOverflow issue regarding tree styling for lists](https://stackoverflow.com/questions/14423671/best-method-for-displaying-a-tree-list-using-css-only-no-images-or-js-example). ## `tree` Just for reference, here's some sample `tree` output: ```txt . ├── footer.njk ├── head-content.njk ├── header.njk ├── layouts │   ├── base.njk │   ├── page-lists.njk │   ├── page.njk │   ├── post.njk │   ├── post-with-toc.njk │   └── tag-redirect.njk ├── pagination.njk ├── postlist.njk └── webring.njk ``` (You'll note that there are gaps between the verticals of each line. That's due to the line-height on the page, but in a standard terminal those vertical lines would be contiguous.) ## HTML Our ToC uses the following HTML structure: ```html ``` We can ignore the `