> This page is for Docs.

> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. For task-scoped instructions for coding agents working in a Fern project, see https://buildwithfern.com/learn/home/fern-instructions.md.

# Files

> Display interactive file tree structures with expandable folders

The `<Files>` component creates visual file tree structures with expandable folders and nested files. Use it to show project structures, directory layouts, or any hierarchical file organization in your documentation.

The component consists of three parts: `<Files>` as the container, `<Folder>` for directories, and `<File>` for individual files.

## Usage

**`Markdown`**

```jsx Markdown maxLines=10
<Files>
  <Folder name="components" defaultOpen>
    <File name="accordion.mdx" />
    <File name="button.mdx" />
    <File name="card.mdx" />
    <File name="tabs.mdx" />
  </Folder>
  <Folder name="assets">
    <File name="styles.css" />
  </Folder>
  <File name="markdown-basics.mdx" href="/learn/docs/writing-content/markdown-basics" />
  <File name="README.md" />
</Files>
```

## Variants

### Nested folders

You can nest folders within folders to create deep directory structures. The component automatically adds visual nesting lines to show the hierarchy.

**`Markdown`**

```jsx Markdown maxLines=10
<Files>
  <Folder name="components" defaultOpen>
    <Folder name="layout" defaultOpen>
      <File name="header.mdx" />
      <File name="footer.mdx" />
      <File name="sidebar.mdx" />
    </Folder>
    <Folder name="ui">
      <File name="button.mdx" />
      <File name="card.mdx" />
      <File name="tabs.mdx" />
    </Folder>
    <File name="accordion.mdx" />
  </Folder>
  <Folder name="assets">
    <File name="styles.css" />
  </Folder>
  <File name="markdown-basics.mdx" href="/learn/docs/writing-content/markdown-basics" />
  <File name="README.md" />
</Files>
```

### Linked files and folders

Add the `href` property to make files or folders clickable. This is useful for linking to documentation pages, GitHub repositories, or other resources. Files and folders with the `href` property are underlined.

**`Markdown`**

```jsx Markdown maxLines=10
<Files>
  <Folder name="components">
    <File name="accordion.mdx" href="/docs/writing-content/components/accordions" />
    <File name="button.mdx" href="/docs/writing-content/components/button" />
    <File name="card.mdx" href="/docs/writing-content/components/cards" />
    <File name="tabs.mdx" href="/docs/writing-content/components/tabs" />
  </Folder>
  <Folder name="assets">
    <File name="styles.css" href="https://github.com/fern-api/docs/blob/main/fern/assets/styles.css" />
  </Folder>
  <File name="markdown-basics.mdx" href="/learn/docs/writing-content/markdown-basics" />
  <File name="README.md" href="https://github.com/fern-api/docs/blob/main/README.md" />
</Files>
```

### Default open folders

Use the `defaultOpen` property to have specific folders expanded when the page loads. This is useful for highlighting important directories or showing the most relevant parts of a file structure.

**`Markdown`**

```jsx Markdown maxLines=10
<Files>
  <Folder name="components" defaultOpen>
    <File name="accordion.mdx" />
    <File name="button.mdx" />
    <File name="card.mdx" />
    <File name="tabs.mdx" />
  </Folder>
  <Folder name="assets">
    <File name="styles.css" />
  </Folder>
  <File name="markdown-basics.mdx" href="/learn/docs/writing-content/markdown-basics" />
  <File name="README.md" />
</Files>
```

### Line highlighting and comments

Use the `highlighted` property to highlight specific files or folders with an accent background color. Use the `comment` property to add explanatory text that appears next to an item. These properties are useful for drawing attention to important files or providing additional context, similar to how code blocks support [line highlighting](/learn/docs/writing-content/components/code-blocks#line-highlighting) and inline comments.

**`Markdown`**

```jsx Markdown maxLines=10
<Files>
  <Folder name="components" defaultOpen highlighted>
    <File name="accordion.mdx" comment="Collapsible content sections"/>
    <File name="button.mdx" />
    <File name="card.mdx" />
    <File name="tabs.mdx" highlighted/>
  </Folder>
  <Folder name="assets">
    <File name="styles.css" comment="Customize theme colors"/>
  </Folder>
  <File name="markdown.mdx" href="/learn/docs/writing-content/markdown"/>
  <File name="README.md" highlighted comment="Contribute to the docs"/>
</Files>
```

## Properties

### `<Files>` properties

**`children`** `JSX` — required

The file tree content. Should contain `<Folder>` and `<File>` components.

---

**`className`** `string`

Optional CSS class name for custom styling.

---

### `<Folder>` properties

**`name`** `string` — required

The folder name to display.

---

**`defaultOpen`** `boolean`

Whether the folder should be expanded when the page loads. If not specified, the folder will be collapsed by default.

---

**`children`** `JSX`

The nested content within the folder. Can include `<File>` and other `<Folder>` components.

---

**`href`** `string`

Optional URL to make the folder name clickable. The name will show an underline when a link is provided.

---

**`highlighted`** `boolean`

Whether the line containing the folder should be visually highlighted with an accent background color. Use this to draw attention to important directories.

---

**`comment`** `string`

Optional comment text that appears next to the folder name. Comments are automatically prefixed with `#` if not already present and styled in a monospace font with muted color.

---

**`className`** `string`

Optional CSS class name for custom styling.

---

### `<File>` properties

**`name`** `string` — required

The file name to display.

---

**`href`** `string`

Optional URL to make the file name clickable. The name will show an underline when a link is provided.

---

**`highlighted`** `boolean`

Whether the line containing the file should be visually highlighted with an accent background color. Use this to draw attention to important files.

---

**`comment`** `string`

Optional comment text that appears next to the file name. Comments are automatically prefixed with `#` if not already present and styled in a monospace font with muted color.

---

**`className`** `string`

Optional CSS class name for custom styling.

---