0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Let users edit an element's content in place, as rich text or plain text only. Covers the roles and labels you must add, sanitising saved HTML, and VB's markdown-editable enhancement.
Overview
The contenteditableattribute makes an element's content editable in place. The user can click into it, type, delete and paste, and the DOM changes as they do. It is the base of inline editors, note fields and rich-text editors.
An editable element is not a form control. It has no name or value, isn't submitted with a form, has no built-in validation, and gets no textbox role. You add those parts yourself.
Applies to: any HTML element (it is a global attribute).
A labelled plain-text editing region
1234567891011
<h2id="note-label">Meeting note</h2><pcontenteditable="plaintext-only"role="textbox"aria-multiline="true"aria-labelledby="note-label">Agreed to move the launch to 14 November. Priya owns the checklist.</p><p>Characters: <spanid="note-count">0</span></p><scripttype="module">const note = document.querySelector('[contenteditable]');const count = document.getElementById('note-count');constupdate = () => { count.textContent = String(note.textContent.length); }; note.addEventListener('input', update);update();</script>
Values
Value
Meaning
true, or empty (contenteditable / contenteditable="")
Editable, rich text. Pasted HTML keeps its formatting, and some browsers apply formatting shortcuts.
plaintext-only
Editable, text only. Pasted content arrives as plain text and formatting shortcuts do nothing.
false
Not editable, even inside an editable ancestor.
Absent, or an invalid value
Inherit: editable if the parent is.
Editability is inherited: every descendant of an editable element is editable unless it sets contenteditable="false". In script, el.contentEditable reads and sets "true", "false", "plaintext-only" or "inherit", and el.isContentEditable reports the result after inheritance.
Examples
Inline markdown with data-markdown-editable
VB's data-markdown-editable turns an element into an inline markdown field: raw markdown while focused, rendered and sanitised HTML after blur.
data-markdown-editable
12345678
<pdata-markdown-editable>This is **bold**, *italic*, ~~strikethrough~~, and `inline code`.</p><scripttype="module">document.addEventListener('markdown-editable:change', (event) => {const { value, html } = event.detail; // raw markdown and rendered HTMLsaveNote(value); });</script>
Controlling edits with beforeinput
document.execCommand() is deprecated. To control what an edit does, listen for beforeinput: its inputType says what is about to happen (insertText, insertParagraph, formatBold, insertFromPaste…), and preventDefault() cancels most of them.
Read textContent (or innerText, which keeps line breaks) for plain text. Only read innerHTML when you need the formatting, and treat it as untrusted (see Security).
Plain text out, plain text in
12
const text = note.innerText; // what the user typednote.textContent = savedText; // never innerHTML for user text
In Vanilla Breeze
No styling. VB has no [contenteditable] rule, so an editable region looks like the element it is. Give it a visible edge, as the demo's own CSS does. Focus shows the browser's default outline.
data-markdown-editable (src/utils/markdown-editable-init.js, loaded on demand) sets contenteditable="true", role="textbox" and aria-multiline="false" on the element. While focused it shows the raw markdown and sets data-md-editing (monospace text and an outline, from src/utils/markdown-editable.css). On blur it renders the inline markdown, sanitises it, and stores the source in data-markdown-value. It fires markdown-editable:change with { value, html }. On a <textarea> or <input> it adds a preview <output> instead.
Sanitising. Rendered markdown goes through VB's internal sanitiser (src/lib/sanitize-html.js), which inserts nodes rather than re-parsing a string. It isn't a public export; for your own editors see Security.
Inserting at the caret.<emoji-picker for="id"> inserts into a contenteditable target at the caret and fires an input event.
Keyboard shortcuts stay out of the way. VB's shared hotkey binder ignores keys typed into contenteditable regions (and inputs) unless a binding is global, so data-hotkey single-key shortcuts don't fire while someone types.
For whole documents, use <markdown-editor>, which wraps a real <textarea> and so takes part in forms.
Accessibility
No implicit role.contenteditable doesn't change an element's role: an editable <p> is still announced as a paragraph, with an editable state. For a field-like region add role="textbox", plus aria-multiline="true" when Enter adds a line.
Name it. A textbox needs an accessible name: aria-labelledby pointing at a visible heading or label, or aria-label. A <label for> doesn't work, because the element isn't labelable.
Editable regions are focusable and in the tab order. Don't add tabindex.
Add aria-required, aria-invalid and aria-describedby yourself if the region acts as a required or validated field.
Keep the editing controls keyboard-reachable. Formatting shortcuts differ between browsers and platforms, so offer buttons too.
Prefer <textarea> (with data-grow) when you don't need rich text: it brings a role, a label, form submission and validation for free.
Security
Pasted HTML is untrusted. With contenteditable="true" a user can paste markup from anywhere, and innerHTML hands it back to you. Storing it and rendering it to other people is a cross-site scripting risk.
Prefer plaintext-only and textContent / innerText for user text.
When you must keep HTML, sanitise it before you store it and again before you render it. Element.setHTML() parses and sanitises in one step (Chrome 146, Firefox 148; not in Safari as of November 2026); elsewhere use a maintained library such as DOMPurify. Never write user HTML back with innerHTML.
Browser support
contenteditable="true" works in every browser. plaintext-only: Baseline 2025 (Chrome 51, Safari 5, Firefox 136).
Gotchas
Not submitted. Copy the content into a hidden input on submit, or use a form-associated custom element.
Markup varies by browser.Enter in rich mode may create a <div>, a <p> or a <br>, and pasted content brings its own elements and styles. Normalise what you save.
Empty regions collapse. An element with no text has no height. Give it a minimum block size.
Placeholders aren't built in.:empty only matches with no child nodes at all, and browsers often leave a <br> behind after deleting.
Child components stay editable. Mark embedded widgets contenteditable="false" so the user can't type into them.