Introduction

REALM is a small runtime for building native web components in HTML. A component is a single <custom-element> tag that holds three things: a <script> with plain JavaScript, a <style>, and markup. REALM turns it into a custom element with a shadow root. There is no compiler, no virtual DOM and no build step.

index.htmlhello-card.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Introduction demo</title>
  <link rel="stylesheet" href="https://realm.js.org/dist/realm.css">
  <script type="module" src="https://realm.js.org/dist/realm.js"></script>
</head>
<body>
  <import-element from="./hello-card.html"></import-element>

  <hello-card name="Ana"></hello-card>
</body>
</html>
<custom-element name="hello-card">
  <script>
    const props = defineProps({ name: prop.string().default("world") });
    const greeting = useState({ count: 0 });

    function wave() {
      greeting.count++;
    }
  </script>

  <style>
    :host {
      display: block;
    }
  </style>

  <p>Hello, <slot name="@name"></slot>!</p>
  <button onclick="wave()">Waved <slot name="#greeting.count"></slot> times</button>
</custom-element>

Hello, !

In this example:

Why REALM

What REALM is not

Frequently asked questions

What is REALM? REALM is an open source framework for writing web components in plain HTML. Each component is one <custom-element> tag with a script, a style and markup, and REALM turns it into a native custom element in the browser. It needs no compiler and no build step: a page loads one script and the components work. Is REALM free? Yes. REALM, the REALM UI component library and the Unicons icon component are free and open source under the MIT licence, including for commercial projects. Does REALM need a build step? No. A page loads REALM with one <script type="module"> tag, and components are written inline or loaded from .html files with <import-element>. A Vite plugin is available for sites that want components assembled at build time, for example to run under a strict Content Security Policy. How big is REALM? The runtime is about 16 KB gzipped. CI fails any change that takes it to 17 KB or more. Which browsers does REALM support? Current Chrome, Edge, Firefox and Safari: Chrome and Edge 125, Firefox 126 and Safari 17.4 or newer, on desktop and iOS. Every test runs in Chromium, Firefox and WebKit. See Browser support. Can I use REALM with React, Vue, Rails or Django? Yes. A REALM component is a standard custom element, so it works anywhere HTML does: in pages rendered by Rails, Django, Laravel or any other server, and inside apps built with React, Vue or other frameworks that support custom elements. Is REALM good for SEO? Content you write inside a component's tags stays in the page's HTML, where search engines can read it. Content a component creates in its shadow root is rendered with JavaScript, so only crawlers that run JavaScript see it. REALM has no server-side rendering yet. See Modern framework problems. How is REALM different from Lit? Lit components are JavaScript classes with templates written in JavaScript. REALM components are written in HTML, with logic in a plain script and no JavaScript definition API. Markup in REALM holds references to values, never expressions.

Where to go next

Updated · Edit this page on GitHub · View as Markdown