<!--
Sitemap:
- [What is Vocs](/guide/what-is-vocs): Learn what Vocs provides for documentation sites
- [Getting Started](/guide/getting-started): Install Vocs and create your first documentation site
- [Writing Docs with AI](/guide/writing-docs-with-ai): Use an AI agent to create and maintain Vocs documentation
- [Project Structure](/guide/structure): Overview of the structure of a Vocs project
- [Markdown Extensions](/guide/markdown-extensions): Features and syntax of Markdown in Vocs
- [Code & Syntax Highlighting](/guide/syntax-highlighting): Rich markup and annotations for code
- [Code Snippets](/guide/code-snippets): Include and reuse code in Markdown
- [Markdown Snippets](/guide/markdown-snippets): Include other Markdown files in MDX
- [Asset Handling](/guide/asset-handling): Manage images, fonts, icons, and other docs assets
- [Frontmatter](/guide/frontmatter): Configure page metadata, layouts, search, and UI visibility
- [Using React in Markdown](/guide/react): Compose MDX pages with React components
- [Twoslash](/guide/twoslash): Add type-aware annotations to code examples
- [Sidebar & Top Navigation](/guide/navigation): Keep docs navigation synced with routes
- [Theming](/guide/theming): Customize colors, typography, spacing, logos, and code themes
- [Tailwind CSS](/guide/tailwind): Use Tailwind utilities in Vocs pages and components
- [Layouts](/guide/layouts): Choose and customize page shells for your docs
- [Dynamic OG Images](/guide/dynamic-og-images): Generate social preview images from page metadata
- [Feedback](/guide/feedback): Collect page-level feedback from readers
- [Changelog Generation](/guide/changelog-generation): Fetch release notes and render a changelog page
- [MCP Server](/guide/mcp-server): Expose your docs and source code to AI assistants
- [AI Support](/guide/ai-support): Make your documentation easier for AI assistants to read
- [Site Configuration](/reference/site-config): Reference for options accepted by defineConfig
- [Components](/reference/components): Reference for the public React components exported from Vocs
- [Hooks](/reference/hooks): Reference for the React hooks exported from Vocs
- [Changelog](/guide/changelog): Release history for Vocs
-->

# Asset Handling \[Manage images, fonts, icons, and other docs assets]

Vocs uses Vite's asset handling model. There are two main ways to work with assets:

* use `public/` for files you want to serve at a fixed URL
* import assets from source files when they belong to a page or component

## Use `public/` For Fixed URLs

Use `public/` for assets that should be served as-is, such as favicons, logos, social images, and font files.

:::file-tree

* +my-project
  * **+public**
    * **logo.svg**
    * +images
      * **hero.png**
    * +fonts
      * **soehne-buch.woff2**
    * **favicon.ico**
  * +src
    * +pages
      * index.mdx
        :::

Files in `public/` are available at the site root:

```mdx [src/pages/index.mdx]
![Logo](/logo.svg)

<img src="/images/hero.png" alt="Hero" />
```

```ts [vocs.config.ts]
import { defineConfig } from 'vocs/config'

export default defineConfig({
  logoUrl: '/logo.svg',
  iconUrl: '/favicon.ico',
})
```

Do not import files from `public/`. Reference them by URL instead.

## Import Assets From Source Files

If an image belongs to a specific page or component, keep it next to that file and import it. This works well for colocated diagrams, screenshots, and illustrations.

:::file-tree

* +src
  * +pages
    * +guide
      * **asset-handling.mdx**
      * **diagram.png**
        :::

```mdx [src/pages/guide/asset-handling.mdx]
import diagram from './diagram.png'

<img src={diagram} alt="Architecture diagram" />
```

Imported assets go through Vite's asset pipeline, which makes them a better default when the asset is part of your source tree rather than a globally addressed file.

## Choosing Between `public/` And Imports

Use `public/` when you need:

* a stable URL like `/logo.svg` or `/favicon.ico`
* files referenced from config such as `logoUrl` and `iconUrl`
* files referenced from CSS such as font files
* assets that should be shared across many pages without importing them

Import assets from source files when you want:

* page-specific images colocated with the content that uses them
* component-specific assets kept next to the component
* Vite to process the asset as part of the source graph

If you are choosing between the two, prefer imports unless you specifically need a fixed public URL.

## Fonts

Load custom fonts in `src/pages/_root.css`, and place the font files in `public/fonts` or another static asset path.

```css [src/pages/_root.css]
@font-face {
  font-family: 'Soehne';
  src: url('/fonts/soehne-buch.woff2') format('woff2');
  font-display: swap;
}

:root {
  --vocs-font-family: 'Soehne', sans-serif;
}
```

See also: [Theming](/guide/theming)

## Common Asset Patterns

* Put shared brand assets like logos, favicons, and social images in `public/`.
* Put page-local diagrams and screenshots next to the page or component that uses them.
* Reference `public/` assets with URL paths such as `/logo.svg`.
* Do not import from `public/` like `import logo from '../public/logo.svg'`.
