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

The native build creates ordinary DOM elements.

Configure Vite

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

export default defineConfig({
  plugins: [htmlNext({ entries: ["src/app.html"] })],
});

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.html
<link rel="component" href="./counter.html">

<template component="x-app">
  <main>
    <h1>Workshop check-in</h1>
    <p>Count guests as they arrive. Reset for the next session.</p>
    <x-counter></x-counter>
  </main>
</template>

Attach the app to the page:

src/main.js
import { createXApp } from "virtual:html-next/components";

document.getElementById("app").append(createXApp());
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.js"></script>
  </body>
</html>

Run your project's usual npm run dev command. Click the counter and Reset. Vite builds the HTML definition into JavaScript that creates native DOM elements; a production build does not parse component definitions in the browser.

Typecheck

Run html-next-check to check components without building. It reports invalid declarations, constraints, and component links with their file and line. Pass the same entries as your Vite configuration:

package.json
{
  "scripts": {
    "check": "html-next-check src/app.html"
  }
}

Check controllers and other application code with your project's usual tools, such as tsc --noEmit.

Use a library

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

npm install your-library

Add htmlNext() to your Vite plugins, using the same import shown above. Installed libraries are discovered automatically; you do not need to list their HTML files in entries.

Import the factory named in the library's README:

import { createUiButton } from "your-library";

document.getElementById("app").append(createUiButton());

Here your-library and createUiButton are examples; use the package and component names your library documents.

Use it without a build step

Save the app.html and counter.html files from above beside this page. The module script loads the app and its counter, then renders the <x-app> instance:

index.html — browser runtime
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Workshop check-in</title>
    <script type="module" src="https://cdn.jsdelivr.net/npm/@nextwebwg/html-next/dist/browser.js"></script>
    <link rel="component" href="./app.html">
  </head>
  <body><x-app></x-app></body>
</html>

Serve these files over HTTP. The runtime handles updates and components added to the page later. With a bundler, importing @nextwebwg/html-next/browser starts the same runtime.

Browser support

The live runtime needs native CSS @scope: Chrome 118, Safari 17.4, Firefox 146, or later. Vite output uses attribute-based style scoping for older browsers.

Loading and trust

Same-origin component links work directly. Loading a component root from another origin requires an import-map entry. Controllers are ordinary trusted JavaScript; browser CORS and CSP rules apply. See the proposal's resource loading rules.

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.