HTML blocks
An HTML block runs a piece of HTML, CSS and JavaScript inside a page. Use it for the parts of a page that Lyra’s other blocks can’t show, like an animated diagram, a small simulation or a custom chart.
When to use one
Section titled “When to use one”Most explainers and review pages don’t need one. Cards, columns, arrows, timelines, numbers, tables and Mermaid diagrams cover most layouts, and people can edit them like any other text. Reach for an HTML block only for the one part that needs its own drawing or script.
| You want | Use |
|---|---|
| Steps, options, a before and after | Cards and columns |
| A flowchart or sequence diagram | A Mermaid diagram |
| A bar, line or pie chart from a few numbers | A chart |
| An animation, a simulation, a diagram you draw yourself | An HTML block |
The page around the block keeps comments, history and editing with others. Only the block itself is HTML.
Add an HTML block
Section titled “Add an HTML block”- Type
/htmland pick HTML block. - Click Add HTML.
- Paste the HTML and click Save, or press ⌘Enter (Ctrl+Enter on Windows).
To change it later, hover over the block and click Edit HTML.
Agents write HTML blocks as a code block whose language is html-block. See Markdown and directives.
Write only what goes in the body, with its <style> and <script> elements. A whole HTML document works too.
<div class="meter"><div class="fill"></div></div><p data-lyra-text="caption">Drag the slider to fill the meter.</p><input type="range" min="0" max="100" value="40"><style> .meter { height: 16px; border-radius: 8px; background: var(--lyra-surface); border: 1px solid var(--lyra-line); } .fill { height: 100%; width: 40%; border-radius: 8px; background: var(--lyra-accent); }</style><script> const fill = document.querySelector('.fill') document.querySelector('input').addEventListener('input', (event) => { fill.style.width = `${event.target.value}%` })</script>How it runs
Section titled “How it runs”Each HTML block runs in a frame of its own, separate from Lyra and from every other block on the page.
Your Lyra tab┌────────────────────────────────────────────────┐│ The page ││ ┌──────────────────────────────────────────┐ ││ │ Lyra's frame (passes messages only) │ ││ │ ┌────────────────────────────────────┐ │ ││ │ │ Your HTML │ │ ││ │ │ - no Lyra cookies or storage │ │ ││ │ │ - no network │ │ ││ │ │ - scripts only from a few CDNs │ │ ││ │ └────────────────────────────────────┘ │ ││ └──────────────────────────────────────────┘ │└────────────────────────────────────────────────┘The HTML runs on an address that matches no website, so its scripts can’t read your Lyra pages, your cookies or anything else of Lyra’s, and can’t call Lyra as you.
What can load
Section titled “What can load”| Kind | Allowed from |
|---|---|
| Scripts | Inline, or from cdnjs.cloudflare.com, cdn.jsdelivr.net or unpkg.com |
| Stylesheets | Inline, from fonts.googleapis.com, or from those CDNs |
| Fonts | data: links, fonts.gstatic.com, or those CDNs |
| Images, video and audio | Only data: and blob: links, or SVG written in the HTML. For a file uploaded to the page, use lyra.fileUrl |
| Workers | blob: links, or those CDNs |
| Anything else | Nothing |
Load scripts at a pinned version, like https://cdn.jsdelivr.net/npm/chart.js@4.4.1, so the block keeps working when the library changes. eval and WebAssembly work.
What doesn’t work
Section titled “What doesn’t work”| Feature | What happens |
|---|---|
fetch, XHR, WebSockets |
They fail. Put every bit of data in the HTML, or load a file uploaded to the page with lyra.file |
localStorage, sessionStorage, IndexedDB, cookies |
They throw an error. Wrap them in try/catch, keep state in memory and save what should last with lyra.set |
alert, confirm, prompt, print |
Nothing happens |
| Downloads and copying to the clipboard | Nothing happens |
| Forms | They never send. Use button clicks and key handlers |
window.open and popups |
Nothing happens |
| Sending the frame to another address | The frame shows an error. That includes embedding a video or document from another site |
Write links as plain <a href="https://...">. When someone clicks an http, https or mailto link, Lyra opens it in a new browser tab, or in your default browser in the desktop app.
javascript:, data:, blob: and relative links are dropped. For actions, use onclick.
Height. Lyra sizes the frame to the height of its content, between 24 and 8,000 pixels. Don’t give html or body a height, and don’t size anything from 100vh or window.innerHeight: it gets cut off at about the height of the reader’s screen. A chart that fills its container, like Chart.js with maintainAspectRatio: false, needs a container with a fixed height, like 280px.
Width. The block is as wide as the page’s text: about 700 pixels on a computer and 340 on a phone. Keep the layout fluid. Anything wider, like a wide table, scrolls sideways.
Spacing. Lyra sets the margins of html and body to 0 and leaves 8 pixels around your content, so shadows and focus rings at the edges show. Don’t add padding or margin to html, body or your outermost element to space the block out.
File size. Keep each block under about 200 KB so the page stays quick to open.
Match Lyra’s theme
Section titled “Match Lyra’s theme”The frame is transparent, so the page’s background shows through it. Lyra sets data-theme="light" or data-theme="dark" on <html> before your code runs, and changes it when the reader switches theme.
Use Lyra’s CSS variables and your block switches with the theme on its own:
| Variable | What it is |
|---|---|
--lyra-bg |
The page’s background |
--lyra-surface |
A slightly tinted box |
--lyra-elevated |
A raised surface |
--lyra-fg |
Text |
--lyra-muted, --lyra-faint |
Secondary and faint text |
--lyra-line, --lyra-line-strong |
Borders |
--lyra-hover |
A hover background |
--lyra-accent, --lyra-accent-soft |
Lyra’s accent color, strong and soft |
--lyra-danger, --lyra-success |
Errors and success |
--lyra-gray, --lyra-blue, --lyra-green, --lyra-yellow, --lyra-orange, --lyra-red, --lyra-purple, --lyra-pink |
Named colors |
The named colors are lighter in the dark theme, so text on top of one of them should use var(--lyra-bg), not white.
Text in the block uses Lyra’s fonts and sizes, and any CSS of yours wins. The text variables are --lyra-font-sans, --lyra-font-mono, --lyra-text-sm, --lyra-text-base, --lyra-text-lg, --lyra-h1, --lyra-h2, --lyra-h3, --lyra-leading, --lyra-leading-tight, --lyra-weight-normal, --lyra-weight-medium and --lyra-weight-bold.
For colors of your own, set the light ones on :root and the dark ones under :root[data-theme="dark"]:
:root { --line-color: #2563eb; }:root[data-theme="dark"] { --line-color: #93c5fd; }Code that draws its own colors, like a canvas or a chart library, has to redraw when the theme changes:
new MutationObserver(redraw).observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'],})Text people can edit
Section titled “Text people can edit”Put data-lyra-text="name" on an element that holds only text. People who can edit the page can click that text in the block and type over it, without opening the HTML.
- The name can use letters, digits,
-and_, up to 64 characters. - Each piece of text can be up to 10,000 characters.
- Don’t set that element’s text from a script, or it will overwrite what people typed.
- Changes show up for everyone on the page without reloading the block.
Save what people pick or type
Section titled “Save what people pick or type”A block’s script can save what each person picks or types, like an answer, a score or where they stopped, through window.lyra. The next time they open the page, the block shows it again, and an agent working for them sees it.
<div id="pick"> <button data-value="yes">Yes</button> <button data-value="no">No</button> <button data-value="unsure">Not sure</button></div><script> const buttons = document.querySelectorAll('#pick button') const show = () => buttons.forEach((button) => button.setAttribute('aria-pressed', String(lyra.get('answer') === button.dataset.value)), ) buttons.forEach((button) => button.addEventListener('click', () => { lyra.set('answer', button.dataset.value) show() }), ) lyra.ready.then(show)</script>| Call | What it does |
|---|---|
await lyra.ready |
Waits until the saved values have loaded |
lyra.get(name) |
The saved value, or null |
lyra.names() |
The names of every saved value |
lyra.set(name, value) |
Saves a value, or removes it when value is null. Answers false when it can’t save |
lyra.canSave |
false where nothing is saved, like an older version in page history |
- Each person has their own values, and nobody else sees them, not even the page’s owner. To collect everyone’s answers in one place, use a database.
- Anyone who can open the page can save values, including people who can only view it.
- Names use letters, digits,
-and_, up to 64 characters. A value is text of up to 10,000 characters. - A block keeps up to 1,000 values and 200,000 characters for each person.
- Call
lyra.setfrom a click, key or input handler. Lyra saves only while the person is using the block, so a script can’t save on its own when the page opens. - An agent reading the page sees the values of the person it works for, at the end of the block’s HTML, as JSON in a
<script type="application/json" data-lyra-values>element. Lyra drops that element when an agent sends the block back, so an agent can’t change values by editing the page.
Show files uploaded to the page
Section titled “Show files uploaded to the page”A block can show images, videos and audio that were uploaded to its page. Upload the file, take the ID from its /api/files/ID link, and ask Lyra for it:
<video controls></video><script> const video = document.querySelector('video') lyra.posterUrl('FILE_ID').then((url) => { video.poster = url }).catch(() => {}) lyra.fileUrl('FILE_ID').then((url) => { video.src = url })</script>| Call | What it gives |
|---|---|
lyra.fileUrl(id) |
A blob: link to put in an <img>, <video> or <audio> |
lyra.posterUrl(id) |
A blob: link to a video’s still frame |
lyra.file(id) |
The file itself, as a Blob |
Lyra loads the file and hands it to the block, so the block still can’t reach the network.
- Only files uploaded to the same page load. Any other file fails.
- Each call answers with a promise. It fails outside Lyra, like in a page an agent exports as HTML, so show something in its place there.
- A block loads up to 200 files each time it opens.
Where HTML blocks show
Section titled “Where HTML blocks show”| Place | What shows |
|---|---|
| The page, in Lyra or the desktop app | The block, running |
| An older version in page history | The block as it was then, running |
| A public link | Only the block’s visible text. Its HTML and scripts never run there |
| Export as Markdown | An html-block code block with the text people changed put in |
| An agent reading the page | The same, and the values its person saved with lyra.set |
| A page an agent exports as HTML | The block, running in a sandboxed frame, without saved values or page files |