Symbiote.js is a lightweight, standards-first UI library built on Web Components. It extends Custom Elements with reactive data bindings, portable HTML templates, app-wide state, routing, and SSR. It works directly with browser APIs and updates bound DOM properties without virtual DOM reconciliation or excess repainting. The library has zero runtime dependencies and needs neither a compiler nor a build step. A bundler remains optional, though it is recommended for production performance.
Runtime Agnostic Templates (RAT) are the main reason. A Symbiote.js template is an HTML string that describes markup and named bindings. It is independent of a component instance, render function, runtime, and templating tool. You can define, customize, compose, render, and reuse it at any point in the application lifecycle, on the client or the server.
RAT keeps UI structure, data bindings, and actions declarative across client rendering, SSR, SSG, and hybrid rendering. Because the template remains a plain HTML string, a component can work beside other UI frameworks without converting its template to framework-specific syntax.
Three design choices define the library:
- Runtime Agnostic Templates keep representation separate from component logic and make templates portable across runtimes and rendering strategies.
- Direct DOM extension keeps components as real Custom Elements that standard browser APIs can inspect and control.
- App-wide state connects components without prop drilling. Named contexts provide the data sources, while namespace bindings such as
APP/usergive templates and components explicit access to them.
- WebMCP support exposes live Symbiote UI actions as browser-native tools for agents, with public discovery and invocation APIs for application adapters. See the WebMCP docs.
- Server-side rendering uses
SSR.processHtml()for complete HTML orSSR.renderToStream()for streamed chunks. On the client,ssrModeattaches bindings to existing DOM without rendering it again. - The
isoModeflag lets one component work in SSR and client-only scenarios without environment-specific component logic. It hydrates server-rendered content when present and otherwise renders the template from scratch. - Computed properties provide reactive derived state with microtask batching.
- The optional
AppRoutermodule supports path parameters, route guards, and lazy loading. - The
animateOut(el)helper provides CSS-driven exit transitions and integrates with the Itemize API. Symbiote.devModeenables verbose warnings. ImportdevMessages.jsfor full, human-readable messages.ssrModehydrates both Light DOM and Declarative Shadow DOM.- Binding keys absent from
init$fall back to the component's own class properties and methods. - The
lazyModeflag defers component initialization and rendering until it enters the viewport. Thelazyattribute provides the same behavior foritemizecontainers with large data sets.
Run this example directly in a browser without installing the package:
<script type="module">
import Symbiote, { html } from 'https://esm.run/@symbiotejs/symbiote';
class MyCounter extends Symbiote {
count = 0;
increment() {
this.$.count++;
}
}
MyCounter.template = html`
<h2>{{count}}</h2>
<button ${{onclick: 'increment'}}>Click me!</button>
`;
MyCounter.reg('my-counter');
</script>
<my-counter></my-counter>For npm-based projects:
npm i @symbiotejs/symbioteimport Symbiote, { html, css } from '@symbiotejs/symbiote';Install the Symbiote.js skill from your project directory:
npx skills add symbiotejs/symbiote.js --skill symbioteThe skills CLI lets you choose your coding agent. Add --global to install across projects. The skill covers templates, state bindings, contexts, SSR, WebMCP, and security boundaries, with links to the detailed documentation.
Build a working app in HTML, without writing application JavaScript. The HTML-app foundation lets a form create records, checkboxes update them, and filtered lists react immediately. Navigation, reusable views and browser saving can live in the markup too. You can also define your own custom elements entirely in HTML, including their data, templates and declarative actions.
Compose applications from portable HTML chunks, combining imported sections, reusable templates and custom elements in the layout you need. Bind the same chunk to different data contexts and reuse it across views.
Mix those chunks with Markdown in a host that preserves embedded HTML, keeping explanations and interactive controls in one document. Reusing declarative actions instead of generating event handlers and state-management boilerplate can reduce AI output token consumption.
Load one module, declare your data as JSON, and connect your controls with Symbiote bindings. You can build an interactive tool on a static server, then connect JSON endpoints when it needs shared data. HTML-app is an optional entry that works alongside ordinary Symbiote components; the library core stays independent.
Start with the compact Todo, explore the feature guide, or see how HTML-app compares with htmx.
A template is a plain HTML string that describes markup and named bindings. It does not run inside a component instance or close over this; Symbiote.js resolves the component and data context when the template is rendered or hydrated. Templates can be tested, moved between files, and reused across browser and server environments.
// Separate file: my-component.template.js
import { html } from '@symbiotejs/symbiote';
export default html`
<h1>{{title}}</h1>
<button ${{onclick: 'doSomething'}}>Go</button>
`;The html function supports two interpolation modes:
- An object creates a reactive binding:
${{onclick: 'handler'}} - A string or number uses native concatenation:
${pageTitle}
class TodoItem extends Symbiote {
text = '';
done = false;
toggle() {
this.$.done = !this.$.done;
}
}
TodoItem.template = html`
<span ${{onclick: 'toggle'}}>{{text}}</span>
`;State changes update bound DOM properties synchronously, without a virtual DOM or scheduler. Because components are real DOM elements, their state is also accessible through standard APIs:
document.querySelector('my-counter').$.count = 42;Any host application can control a Symbiote.js widget or microfrontend through the DOM API. It does not need a framework adapter.
Bind a parent state object to a child's $ property to pass several values together:
class ProfileCard extends Symbiote {
init$ = { name: '', role: 'Reader' };
}
ProfileCard.template = html`
<strong ${{textContent: 'name'}}></strong>
<span ${{textContent: 'role'}}></span>
`;
ProfileCard.reg('profile-card');
class ProfilePanel extends Symbiote {
init$ = { profile: { name: 'Alex' } };
}
ProfilePanel.template = html`
<profile-card ${{$: 'profile'}}></profile-card>
`;
ProfilePanel.reg('profile-panel');
const panel = document.createElement('profile-panel');
document.body.append(panel); // Child displays Alex / Reader.
panel.$.profile = { role: 'Editor' }; // Child now displays Alex / Editor.The $ setter merges supplied keys, registers new ones, and keeps omitted values and the existing state proxy. You can also assign card.$ = { name: 'Sam' } directly. This is a shallow merge with notifications for every supplied key, including unchanged primitives. Child edits do not publish back to the parent. See state merging for details.
Render lists from data arrays or objects with efficient updates:
class TaskList extends Symbiote {
tasks = [
{ name: 'Buy groceries' },
{ name: 'Write docs' },
];
}
TaskList.template = html`
<ul itemize="tasks">
<template>
<li>{{name}}</li>
</template>
</ul>
`;In a nested component template, the ^ prefix walks up the DOM tree and finds the nearest ancestor with the requested property in its data context (init$ or add$()):
<!-- Text binding to parent property: -->
<div>{{^parentTitle}}</div>
<!-- Handler binding to parent method: -->
<button ${{onclick: '^parentHandler'}}>Click</button>A named context is an app-wide data source. A namespace binding such as APP/user gives components and templates explicit access to that source without prop drilling:
import { PubSub, html } from '@symbiotejs/symbiote';
PubSub.registerCtx({
user: 'Alex',
theme: 'dark',
}, 'APP');
// Any component can read/write:
this.$['APP/user'] = 'New name';
// Any template can use property directly:
let template = html`<h2>{{APP/user}}</h2>`;Shared contexts follow the same idea as the native HTML name attribute used to group radio buttons. The ctx attribute assigns components to a shared data context, and components with the same value can use the same *-prefixed properties:
<upload-btn ctx="gallery"></upload-btn>
<file-list ctx="gallery"></file-list>
<status-bar ctx="gallery"></status-bar>class UploadBtn extends Symbiote {
init$ = { '*files': [] }
onUpload() {
this.$['*files'] = [...this.$['*files'], newFile];
}
}
class FileList extends Symbiote {
init$ = { '*files': [] }
}
class StatusBar extends Symbiote {
init$ = { '*files': [] }
}All three components access the same *files state. Setting ctx="gallery" in HTML and using *-prefixed properties removes the need for a parent coordinator, prop drilling, or global store boilerplate. This allows markup to describe complex relationships between reusable components that do not need direct knowledge of one another.
// Import optional module:
import { AppRouter } from '@symbiotejs/symbiote/core/AppRouter.js';
AppRouter.initRoutingCtx('R', {
home: { pattern: '/' },
profile: { pattern: '/user/:id' },
about: { pattern: '/about', lazyComponent: () => import('./about.js') },
});Shadow DOM is optional in Symbiote.js. Use it when a component needs isolation; otherwise, let the component participate in the page's regular styling.
Light DOM components use regular CSS:
MyComponent.rootStyles = css`
my-component {
display: flex;
gap: 1rem;
& button { color: var(--accent); }
}
`;Symbiote.js applies this style to the nearest containing shadow root, when one exists, or to the document.
Use Shadow DOM for opt-in isolation:
class Isolated extends Symbiote {}
Isolated.shadowStyles = css`
:host { display: block; }
::slotted(*) { margin: 0; }
`;Native CSS features remain available. CSS variables cross shadow boundaries, ::part() exposes selected internals, and modern nesting, @layer, and @container work without framework abstractions. Light DOM and Shadow DOM components can coexist in the same application.
Components can read CSS custom property values to initiate reactive state:
my-widget {
--label: 'Click me';
}class MyWidget extends Symbiote {...}
MyWidget.template = html`
<span>{{--label}}</span>
`;- Complex widgets embedded in any host application
- Low-code, HTML-based interfaces with declarative bindings for UI, data, and actions
- Microfrontends built from standard Custom Elements without framework coupling
- Reusable component libraries for React, Vue, Angular, or plain HTML
- SSR applications that need lightweight server rendering without framework lock-in
- Framework-agnostic solutions that reuse one codebase across contexts
- Agent-facing web applications that expose state and actions through WebMCP
- Documentation
- Live examples: interactive code playground
- JSDA-Kit: companion tooling for the server, SSG, bundling, import maps, and native Symbiote.js SSR integration
- Agent skill: focused implementation guidance for coding agents
- Symbiote.js: superpowers for Web Components
- Symbiote.js: v3 highlights
- Symbiote.js vs Lit
- JSDA Stack - A Revolutionary Simple Approach to Build Modern Web
Questions and proposals are welcome in Symbiote Discussions.
© rnd-pro.com, MIT License