Skip to content

File Trees

The <FileTree> component is used to display folder structures, file hierarchies, and project architectures. It transforms standard indented Markdown lists into visual, IDE-like directory trees, automatically adding the correct file and folder icons based on file extensions.

Display project directory structures clearly using the FileTree component:

  1. Import FileTree: Add import { FileTree } from '@astrojs/starlight/components'; to imports.
  2. Write Nested Lists: Construct standard Markdown bullet lists representing folders and files.
  3. Highlight Key Files: Append comments or keep names explicit to highlight configuration files.

Explore the live specimen, the raw markup required to build it, and instructions for authoring this component inside Sveltia CMS.

Below is an example of a repository structure. Notice how bold text is used to highlight a specific file, and standard Markdown comments provide inline context.


  • Directorypublic/
    • Directoryadmin/
      • config.yml # Sveltia CMS backend configuration
      • index.html
  • Directorysrc/
    • Directorycontent/
      • Directorydocs/
        • index.mdx
        • Directorycomponents/
          • file-trees.mdx
    • Directoryassets/
      • …
  • astro.config.mjs
  • package.json

When documenting project structures in this knowledge base, adhere to the following stylistic rules:

  • Highlight the Target: If a procedure asks a user to edit a specific file within a larger tree, use bold text (**filename.ext**) to draw their eye directly to that file.
  • Prune the Tree: Do not show the entire repository architecture unless absolutely necessary. Omit irrelevant folders (like node_modules/, .git/, or unrelated feature directories) to keep the diagram focused on the task at hand.
  • Use Inline Comments: If a file’s purpose isn’t obvious from its name, add a brief explanation on the same line after a hash symbol (e.g., # This controls routing).
  • Always Include Extensions: Starlight determines which icon to render based on the file extension. Always write out .js, .json, .mdx, etc., rather than just the file name.