# Fumadocs (Framework Mode, Next.js): Local HTML
URL: /docs/next/integrations/content/local-html
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/integrations/content/local-html.mdx

Content source for local HTML files.

## Introduction [#introduction]

`@fumadocs/local-html` is a content source for local HTML files. It is bundleless by design, so it works fully at runtime.

It is made for pages you receive as HTML instead of author yourself, like exported decks, reports, and the output of other tools. Each file is adapted to your docs theme rather than rendered as it came.

Compared to [Local Markdown](/docs/next/integrations/content/local-md), HTML is treated as data to adapt, not as a document format to write in.

### Limitations [#limitations]

- Scripts are stripped, the interactive behaviour of the original page is not preserved.
- No MDX components in content, but you can map HTML tags to components at render phase.
- Processing is a transform, not sanitization. Nothing that executes survives it, but the remaining markup is rendered as-is, and the resources it references (images above all) are fetched by everyone who opens the page. Keep the content directory to files you trust, like your Markdown content.

## Setup [#setup]

Install the package:

```package-install
@fumadocs/local-html
```

Create a `localHtml` instance and connect it to Fumadocs:

```ts title="lib/source.ts"
import { dynamicLoader } from 'fumadocs-core/source';
import { localHtml } from '@fumadocs/local-html';

const pages = localHtml({
  dir: 'content/pages',
  // options
});

const pagesLoader = dynamicLoader(pages.dynamicSource(), {
  baseUrl: '/docs',
});

export async function getSource() {
  return pagesLoader.get();
}
```

The returned source from `pagesLoader.get()` is a normal [content loader](/docs/headless/source-api) instance.

## Usage [#usage]

`page.data.load()` returns a renderer for the processed content.

Render it in your page:

```tsx tab="app/docs/layout.tsx"
import { getSource } from '@/lib/source';
import { DocsLayout } from 'fumadocs-ui/layouts/docs';

export default async function Layout({ children }: LayoutProps<'/docs'>) {
  const source = await getSource();

  return <DocsLayout tree={source.getPageTree()}>{children}</DocsLayout>;
}
```

```tsx tab="app/docs/[[...slug]]/page.tsx"
import { notFound } from 'next/navigation';
import { DocsBody, DocsDescription, DocsPage, DocsTitle } from 'fumadocs-ui/layouts/docs/page';
import { getSource } from '@/lib/source';

export default async function Page(props: PageProps<'/docs/[[...slug]]'>) {
  const params = await props.params;
  const source = await getSource();
  const page = source.getPage(params.slug);
  if (!page) notFound();

  const renderer = await page.data.load();
  const { body, toc } = await renderer.render();

  return (
    <DocsPage toc={toc}>
      <DocsTitle>{page.data.title}</DocsTitle>
      <DocsDescription>{page.data.description}</DocsDescription>
      <DocsBody>{body}</DocsBody>
    </DocsPage>
  );
}
```

Pass components to `render()` to map HTML tags onto your own, like headings with anchors:

```tsx
import { getMDXComponents } from '@/components/mdx';

const { body, toc } = await renderer.render(getMDXComponents());
```

### Page Metadata [#page-metadata]

The title and description of each page are read from its `<head>`:

- `<title>` becomes the page title.
- `<meta name="description">` becomes the description.

You can override them (and set an icon) without touching the visible content, using `fumadocs:` metas:

```html
<meta name="fumadocs:title" content="My Page" />
<meta name="fumadocs:description" content="A short description." />
<meta name="fumadocs:icon" content="SquareBookmark" />
```

Every `<meta name>`/`content` pair of the document is also available on `page.data.metadata`.

Like other local sources, `meta.json` files customize the page tree, validated with `metaSchema`.

### Content Options [#content-options]

A page keeps only its content element: the only `<main>`, then the only `<article>`, falling back to `<body>` with page chrome like `<header>` and `<nav>` dropped. Its `class` and `style` attributes are removed so your theme's prose styling takes over, and its headings get ids to power the table of contents and search.

Each part of that is configurable:

```ts
import { localHtml } from '@fumadocs/local-html';

const pages = localHtml({
  dir: 'content/pages',
  // keep the original class/style attributes instead of adapting to your theme
  adaptStyles: false,
  // drop additional tags from the content
  exclude: ['aside'],
  // custom logic to pick the element holding the page content
  selectContent: (root) => {
    // return a hast element, or undefined for the default behaviour
  },
});
```

### Syntax Highlighting [#syntax-highlighting]

`<pre><code>` blocks are highlighted with [Shiki](https://shiki.style), using the same options as [Local Markdown](/docs/next/integrations/content/local-md):

```ts
const pages = localHtml({
  dir: 'content/pages',
  rehypeCodeOptions: {
    themes: {
      light: 'github-light',
      dark: 'github-dark',
    },
  },
});
```

The language is read from the `language-*` class of the block, on the `<code>` or its enclosing `<pre>`:

```html
<pre><code class="language-ts">const answer: number = 42;</code></pre>
```

A block without one falls back to plain text. Pass `rehypeCodeOptions: false` to disable syntax highlighting.

### Hot Reload [#hot-reload]

`@fumadocs/local-html` reads files at runtime, so nothing watches them by default.

During development, run the bundled dev server alongside your app. It watches your files in one process and broadcasts changes over a websocket, so it works when Next.js runs several workers.

```json title="package.json"
{
  "scripts": {
    "dev": "local-html dev -- next dev"
  }
}
```

Connect the source to the dev server:

```ts title="lib/source.ts"
import { watchWithDevServer } from '@fumadocs/local-html/dev/ws';

if (process.env.NODE_ENV === 'development') {
  void watchWithDevServer(pages);
}
```

The command publishes its URL through an environment variable, so no configuration is needed. Pass one explicitly if you run the server yourself, and use `-p` to change the port:

```ts
void watchWithDevServer(pages, { url: 'ws://127.0.0.1:8000/_fumadocs_local_md' });
```

This invalidates the source on the server, while Next.js keeps the rendered page in the browser. Render `<DevClient />` in your root layout so the page refreshes too:

```tsx title="app/layout.tsx"
import { DevClient } from '@fumadocs/local-html/dev/react-client';

export function RootLayout({ children }) {
  return (
    <RootProvider>
      {/* [!code ++] */}
      <DevClient />
      {children}
    </RootProvider>
  );
}
```

To wire up your own watcher instead, call `pages.invalidateFile(path)` when a file changes.

### Disable Revalidation [#disable-revalidation]

You can use `staticSource()` when you only need a one-time snapshot without revalidation.

It works with a normal `loader()` instead of only `dynamicLoader()`:

```ts title="lib/source.ts"
import { loader } from 'fumadocs-core/source';
import { localHtml } from '@fumadocs/local-html';

const pages = localHtml({
  dir: 'content/pages',
});

export const source = loader(await pages.staticSource(), {
  baseUrl: '/docs',
});
```