HTML Next · Usage

Use HTML Next components

Choose a framework in any section. Every selector on this page follows your choice, so the setup and examples stay together.

Install

Start with a Vite project and use Node 22 or 24. The plugin supports Vite 8.

npm install --save-dev @nextwebwg/html-next-unplugin

Keep your project's usual Svelte plugin. The current target is Svelte 5.57.1. The adapter uses the standard, unpatched framework; see the known keyed-focus limitation.

Configure Vite

vite.config.ts
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import htmlNext from "@nextwebwg/html-next-unplugin/vite";

export default defineConfig({
  plugins: [htmlNext({ target: "svelte" }), svelte()],
});

Use your component

Build a small workshop check-in app: count guests as they arrive, then reset for the next session. Each example uses the same counter inside an App component and shows how to attach that app to the page. In an existing Vue, React, or Svelte project, keep its mounting code and add the counter to its App component.

Save the counter you built as src/counter.html. Use it inside the app:

src/App.svelte
<script lang="ts">
  import { XCounter } from "./counter.html";
</script>

<main>
  <h1>Workshop check-in</h1>
  <p>Count guests as they arrive. Reset for the next session.</p>
  <XCounter />
</main>

Attach App to the page:

src/main.ts
import { mount } from "svelte";
import App from "./App.svelte";

mount(App, { target: document.getElementById("app")! });
index.html
<!doctype html>
<html lang="en">
  <head><meta charset="utf-8"><title>Workshop check-in</title></head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.ts"></script>
  </body>
</html>

Run your project's usual npm run dev command. Click the counter and Reset.

The result uses Svelte and native DOM roots. Generated components import the helpers their features need and have no HTML Next runtime dependency. Editing the HTML definition updates the component in your app.

Typecheck

Enable allowArbitraryExtensions in your TypeScript configuration. The adapter writes adjacent .d.html.ts declarations for local imports. Check components with html-next-check, then generate declarations before a standalone typecheck:

package.json
{
  "scripts": {
    "typecheck": "html-next-check --target svelte src/counter.html && html-next-sync && svelte-check"
  }
}

If a component needs declarations before its first import, add entries: ["src/counter.html"] to htmlNext({ target: "svelte" }).

Use a library

With the Vite plugin configured, install the library named in its README:

npm install your-library
import { UiButton } from "your-library";

Use those exports like other Svelte components. The names come from the library's README. Include the generated src/html-next.d.ts in your TypeScript project to get its component types.

Use it without a build step

For Svelte, use the Vite adapter above. Choose HTML Next in this section for the direct browser-runtime setup.

When you need more

  • Ship a library when other projects need your components.
  • Use the CLI reference to check definitions or build without Vite.
  • See the Vite plugin reference for libraries, externally defined custom elements, and build limits. Compiled component invocations currently need to be empty and statically placed; unsupported features fail with a source-located diagnostic.

HTML Next. MIT-licensed tools for universal HTML components. Implementations of the HTML Next proposals, published from nextwebwg/html-next. Prerelease: the proposals are at Stage 0 and may change.