Integrate in Astro

Read installation and basic usage first. The example below mounts Univer Docs in an Astro page, inside a container with an explicit height.

Initialize the editor from a plain <script> tag so that it runs in the browser. Run this initialization on first load and again on astro:page-load, and dispose of the editor before astro:before-swap when ClientRouter is used. Keep the editor imports out of Astro frontmatter. The event details are documented in Astro's navigation events.

Integration steps

  1. Initialize Univer in mount() / astro:page-load.
  2. Dispose of it in astro:before-swap.

Preset configuration

UniverDocsCorePreset

  • container
    string | HTMLElementDefault: 'app'
    The element to mount into, or its DOM ID.

Example

Astro
<div id="univer-docs" style="height: 600px"></div><script>  import type { Univer } from '@univerjs/presets'  import { UniverDocsCorePreset } from '@univerjs/preset-docs-core'  import UniverPresetDocsCoreenUS from '@univerjs/preset-docs-core/locales/en-US'  import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'  import '@univerjs/preset-docs-core/lib/index.css'  let univerInstance: Univer | undefined  function mount() {    const container = document.getElementById('univer-docs')    if (!container || univerInstance) return    const { univer, univerAPI } = createUniver({      locale: LocaleType.EN_US,      locales: { [LocaleType.EN_US]: mergeLocales(UniverPresetDocsCoreenUS) },      presets: [UniverDocsCorePreset({ container })],    })    univerAPI.createDocument({})    univerInstance = univer  }  function dispose() {    univerInstance?.dispose()    univerInstance = undefined  }  mount()  document.addEventListener('astro:page-load', mount)  document.addEventListener('astro:before-swap', dispose)</script>

How is this guide?

© 2026 DreamNum Co., Ltd.