Styling
The Notion theme, the DOM the editor renders, the stable data attributes to style it with, the overlay layer for chrome, and how to lay out nested blocks.
The core ships almost no visual styles: you style the document with CSS, through stable data attributes on the elements it renders. For a finished look, import the optional Notion theme. This page covers the theme, those attributes, the overlay layer that holds handles and menus, and the rules to follow so styling never fights the editor.
Notion theme
edytor/themes/notion.css styles every bundled kind like Notion’s light theme: the rich text kinds, images, code, equations, tables, columns, the media blocks, page blocks, tables of contents, mentions and page links. Import it once and put the edytor-notion class on an element around <Edytor> (or on the editor itself, with its class prop):
<script lang="ts">
import { Edytor, richTextPlaceholder } from 'edytor';
import 'edytor/themes/notion.css';
</script>
<div class="edytor-notion">
<Edytor plugins={[() => ({ placeholder: richTextPlaceholder })]} />
</div>
What it sets:
- 16px text at a 1.5 line height in Notion’s text color, and blocks as 3px/2px-padded rows 1px apart;
- headings at 1.875em, 1.5em and 1.25em, weight 600, on the heading’s own text only (its nested blocks keep body text), over the page’s own
h1–h3andblockquoterules (a page rule more specific than the theme’s.edytor-notion [data-edytor-type='heading'] > h2still wins). A leading top-level Heading 1 is the page title: 40px, weight 700; - one 24px nesting step: a block nested under a paragraph, heading or quote starts 24px in, and a list item’s or to-do’s marker column is the same step wide;
- a marker column for lists and to-dos: bullets
•◦▪by depth, numbers1.a.i.by depth, with a run of numbered items sharing one counter; - Notion’s blue to-do checkbox, with done text struck through and muted;
- a toggle caret that rotates as the toggle opens (a toggle heading’s centred on its heading), a 3px quote bar, a 10px-rounded callout panel with its icon button and semibold title, the empty body’s muted hint, and a thin divider;
- the code panel, its header placed at the panel’s top, the monospace font and Notion’s light syntax colours (
--edytor-code-background,--edytor-code-color); - equations: the hover and editing shade, the empty equation’s panel, the source in a monospace font, an unreadable one in red;
- tables: the cells’ borders (
--edytor-table-border) and padding, a header cell’s shade (--edytor-table-header-background); columns flush with the layout’s edges and one rounded highlight over a selected layout; - images with rounded corners and a muted caption; the bookmark card (its border, the cover beside the text), the file row and the unplayable embed’s link, each with its hover;
- inline code in red on a light tint, links underlined at 0.7 opacity, mentions and page links in a line, and blue text and block selections;
- Notion’s page row for a page block and muted, indented entries for a table of contents;
- the block colour tokens (below): a callout given a background shows it in place of its panel.
It styles the document only. The empty image and media panels, the block handles, menus, toolbar and panels are your markup, with your styles (see Menus and handles; the demo’s ready-made menus carry their own). Pair it with richTextPlaceholder for Notion’s placeholders.
Adapt it by overriding its custom properties on .edytor-notion:
| Property | Default | Used for |
|---|---|---|
--notion-text |
#2c2c2b |
Text, caret, list markers, the quote bar, the to-do box |
--notion-text-secondary |
#73726e |
Done to-do text, image captions and the empty image panel |
--notion-placeholder |
rgba(44, 44, 43, 0.4) |
Placeholders |
--notion-border |
rgba(28, 19, 1, 0.11) |
The divider |
--notion-hover |
rgba(33, 27, 23, 0.05) |
The checkbox hover |
--notion-panel |
#f9f8f7 |
The callout background |
--notion-code-panel |
#f7f6f3 |
The code block background |
--notion-inline-code |
#cf5148 |
Inline code text |
--notion-blue |
#2783de |
The checked to-do box, the image panel’s buttons |
--notion-text-selection |
rgba(35, 131, 226, 0.28) |
Text selection |
--notion-block-selection |
rgba(35, 131, 226, 0.14) |
Selected blocks |
--notion-font |
Notion’s system sans stack | Body text |
--notion-mono |
'SFMono-Regular', Menlo, … |
Inline code and code blocks |
It also declares the block colour tokens with Notion’s light values, so a theme of yours overrides them in one place (a dark theme, say).
The theme also sets --edytor-drop-indicator-color to Notion’s rgba(35, 131, 226, 0.43), --edytor-drop-backdrop-color to its light nest tint, rgba(35, 131, 226, 0.14), the marquee’s --edytor-marquee-background and --edytor-marquee-border to the same blue, and --edytor-nest-indent to 24px (see Nested blocks). Its rules are scoped under .edytor-notion: to override one, use a more specific selector, or the same selector in a stylesheet loaded after it.
The theme also paints the visual cues the plugins place in the overlay: a block drag’s drop line and nest backdrop, a table’s drop line and column resize guide, a layout gap’s resize guide, an image’s resize pills and other users’ carets, ranges and name pills (each in that user’s colour, --edytor-remote-color). These rules reach the overlay whether edytor-notion is on an element around the editor or on the editor itself.
Without the theme
Every look is the theme’s: a plugin’s own stylesheet keeps only what makes its blocks work. Without the theme the blocks work and are unstyled, as the browser draws their elements:
- a layout’s columns side by side (
--edytor-columns-gap), stacked under 480px, and a table’s grid of its columns’ widths, scrolling sideways in its box; - a code block’s lines keeping their spaces and scrolling sideways, and its header never selected;
- a wide equation scrolling sideways, an embed’s frame at its provider’s aspect ratio or height, a video and an audio player as wide as the block, an image at its width and alignment;
- an empty body’s hint never selected, a mention or page link on one line;
- the overlay’s chrome placed and sized, shown and hidden, and unpainted: the block handles’ hosts, the drop line and the nest backdrop, the image’s resize handles, a column’s and a table column’s resize band and guide, a table row’s or column’s drop line, and other users’ carets, ranges and name pills. Each still takes the pointer where it should and says its state (
data-shown,data-dragging,data-position,data-blocked), but has no colour, radius, shadow or fade.
To paint the cues without the theme, style their elements (they are in the overlay, the root’s sibling):
[data-edytor-overlay] [data-edytor-drop-indicator],
[data-edytor-overlay] [data-edytor-column-resize-guide],
[data-edytor-overlay] [data-edytor-table-drop] {
background: #2eaadc;
}
[data-edytor-overlay] [data-edytor-drop-backdrop] {
background: rgba(46, 170, 220, 0.15);
}
[data-edytor-overlay] [data-edytor-column-resize]::after,
[data-edytor-overlay] [data-edytor-table-resize]::after {
background: rgba(55, 53, 47, 0.16);
}
[data-edytor-overlay] [data-edytor-image-resize]::after {
border-radius: 3px;
background: #37352f;
}
/* Each user's colour is `--edytor-remote-color` on their caret and ranges. */
[data-edytor-overlay] :is([data-edytor-remote-cursor], [data-edytor-remote-cursor-label]) {
background: var(--edytor-remote-color);
}
[data-edytor-overlay] [data-edytor-remote-cursor-label] {
padding: 0 4px;
color: white;
font: 11px sans-serif;
}
[data-edytor-overlay] [data-edytor-remote-selection] {
background: var(--edytor-remote-color);
opacity: 0.2;
}
The controls inside the blocks (a to-do’s checkbox, a callout’s icon, an empty body’s hint, a bookmark’s card, a file’s row, an unplayable embed’s link, a table of contents’ entries, a page block’s link, an equation’s placeholder and error) are the plugins’ markup unless you pass your own snippet to the plugin (see each plugin’s page); the theme styles the default markup.
Long pages
The edytor-long-page class on the editor (or any element around it) gives each top-level block content-visibility: auto and contain-intrinsic-block-size: auto 32px: a block off screen skips its style, layout and paint until it nears the viewport, and counts as a 32px row until it was rendered once, then as its real height. Selection, typing, find-in-page, block handles, drag and drop and remote carets keep working over skipped blocks. It works with any theme; the containment it brings clips what a block paints outside its own box, so check a custom theme’s kinds paint inside theirs.
<div class="edytor-notion edytor-long-page">
<Edytor {document} />
</div>
It is off by default because it trades scrolling for loading, and loading barely gains: it shortens the first layout, but mounting the blocks takes most of the load, and each block that scrolls into view is then styled and laid out on that frame, so scrolling slows down (three times at 5,000 blocks). The keys cost more with it, not less: at 5,000 blocks a character and a move about a third more, Enter and a paste more than half. Turn it on for pages that are mostly read top to bottom, or whose blocks are expensive to lay out (large images, embeds, code).
Measured in Chromium at 1280×900 on /test/large (top-level blocks of mixed kinds, the Notion theme, the shipped plugins and block handles; tests/editor-dom/large-page.profile.spec.ts, the median of three runs), on a laptop shared with other jobs, so the absolute times are high and the ratios are what to read. A key is the time from its keydown to the next frame, in a block in the middle of the page.
| Measure | 1,000 blocks | 2,000 blocks | 5,000 blocks | 5,000, edytor-long-page |
|---|---|---|---|---|
| First paint | 157 ms | 286 ms | 672 ms | 696 ms |
| of which the view’s mount | 91 ms | 161 ms | 426 ms | 343 ms |
| Layout through the load | 6.7 ms | 13 ms | 29 ms | 10 ms |
| Scroll frame (80px a frame), median | 8.3 ms | 8.3 ms | 8.3 ms | 24 ms |
| Typing a character | 5.1 ms | 7.0 ms | 16 ms | 21 ms |
| Enter | 11 ms | 16 ms | 35 ms | 55 ms |
| Moving a block (Mod+Shift+↓) | 7.4 ms | 12 ms | 29 ms | 36 ms |
| Pasting 50 lines | 20 ms | 24 ms | 44 ms | 74 ms |
What grows with the page is the mount (about 0.1 ms a block) and the browser’s share of each key. Keep a document to a couple of thousand top-level blocks for typing within a frame; for longer content, make each page its own document (A page is a document).
- The editor’s share does not grow. What the editor’s own code does for a key (a character, Enter, a move, a caret moving to another block) is the same work at 5,000 blocks as at 1,000: it re-renders the blocks the key changes and those the selection enters and leaves, checks only the nodes added to the page, and measures only the chrome near the screen. Rows in the test suite count that work at both sizes. At 5,000 blocks it is about a millisecond for a character and a few for Enter.
- The browser’s share does. In Chromium, when the caret moves inside an input event after the page changed, the browser recomputes the text of the whole editable root for the input method, a walk of the page (about 0.4 ms at 1,000 blocks, 1 ms at 5,000), and does it again after the frame when a key added or moved a block; laying out, painting and hit-testing a root of thousands of blocks grows too. The rendered markup weighs on these walks: each block carries about ten empty markers of the renderer (comments and empty text nodes), which the browser steps over. It carried about 34, and the walk took 1 ms at 1,000 blocks and 9 ms at 5,000; with fewer markers a key at 5,000 blocks takes about half the time it took (a character 37 → 16 ms, Enter 68 → 35 ms, a move 70 → 29 ms, in one interleaved comparison).
- One switch. The class sets both properties, and without it neither is set: the remembered height alone makes Chromium check every top-level block’s size on each frame (about 2.5 ms at 5,000 blocks).
- No windowing. The editor renders every block, with no windowing: it would break native selection, find-in-page and IME.
The rendered DOM
For a paragraph with bold text and a mention, followed by the overlay:
<div class="my-editor" data-edytor contenteditable="true" role="textbox" aria-multiline="true">
<div data-edytor-block="true" data-edytor-id="b1" data-edytor-type="paragraph">
<p>
<span data-edytor-text="true" data-edytor-id="t:b1:0" data-edytor-text-empty="false">
Hello <strong data-edytor-mark="bold">world</strong>
</span>
<span data-edytor-inline-block="mention" data-edytor-id="i1" contenteditable="false">…</span>
<span data-edytor-text="true" data-edytor-id="t:b1:1" data-edytor-text-empty="true"></span>
</p>
</div>
</div>
<div data-edytor-overlay style="position: absolute; width: 0; height: 0">…</div>
The block element (div here, the default) comes from the kind’s element; the markup inside it (p) from the kind’s snippet. The class prop of <Edytor> goes on the root.
An empty text segment holds a filler that keeps its line’s height: a <br> when it is its block’s whole content (an empty paragraph: <span data-edytor-text="true" … data-edytor-text-empty="true"><br></span>, so a phone’s keyboard capitalizes the first letter typed there), else a zero-width space, as after the mention above, where a <br> would break the line.
Space below the last block
A click in the root below its last block puts the caret in an empty paragraph at the end of the document, created when the last block is not one (as in Notion). The core gives the root a bottom padding to click in, --edytor-trailing-space (2em by default). Its rule has no specificity, so any rule of yours that sets the root’s padding wins. A taller root works too: the whole area below the content counts. With the marquee plugin, a drag from there selects blocks instead; a click still adds the paragraph.
[data-edytor] {
--edytor-trailing-space: 30vh;
}
Attributes
| Attribute | On | Meaning |
|---|---|---|
data-edytor |
the root | The editable root. contenteditable is false when readonly. |
data-edytor-block="true" |
every block element | A block. |
data-edytor-id |
blocks, texts, atoms | The block’s, text segment’s or atom’s id. |
data-edytor-type |
blocks | The block’s kind, such as heading or todo-item. |
data-edytor-void="true" |
void blocks and chrome | Non-editable: a void kind, or an element marked use:block.void. |
data-edytor-selected="true" |
blocks | The block is part of a block selection. |
data-edytor-focused="true" |
blocks | The caret or a text selection is in the block. |
data-edytor-text="true" |
text segments | A run of editable text between inline atoms. |
data-edytor-text-empty |
text segments | "true" when the segment has no characters. |
data-placeholder |
empty text segments | The placeholder text, see Placeholder. |
data-edytor-mark="<name>" |
mark elements | A mark: the mark’s tag, or a span around a snippet mark. |
data-edytor-inline-block="<type>" |
inline atoms | An atom, non-editable. |
data-edytor-todo-checkbox |
the to-do checkbox | The rich text to-do’s input, a direct child of the block. |
data-edytor-callout-icon |
the callout icon | The rich text callout’s icon span. |
data-edytor-color, data-edytor-background |
blocks | The block’s text colour and background by palette name (red), from data.color and data.background. See Block colors. |
data-edytor-children |
a block’s children container | The one element holding a block’s nested blocks, indented by one nesting step. See Nested blocks. |
data-edytor-code-header |
the code block header | The void header holding the language and the Copy button. |
data-edytor-code-language |
the code block language | The language button inside the header (its label in a readonly view). |
data-edytor-image, data-edytor-image-empty |
the image block | The wrapper of the img, or of the empty state; see Image. |
Block attributes are rendered with the element, so they are also present in server-rendered HTML. A kind’s own attributes (from element) sit beside them. The rich text heading renders as <div data-edytor-block … data-edytor-type="heading"><h2>…</h2></div>, its nested blocks after the h2, and a quote puts its text in a blockquote the same way.
Some useful selectors:
/* A kind */
[data-edytor-type='quote'] { border-left: 3px solid currentColor; padding-left: 14px; }
/* A heading level: the tag inside the block */
[data-edytor-type='heading'] > h2 { font-size: 1.6rem; }
/* A mark */
a[data-edytor-mark='link'] { color: #2383e2; }
/* Selected blocks */
[data-edytor-selected] { background: #e8e6df; border-radius: 3px; }
/* The block holding the caret */
[data-edytor-focused] { background: transparent; }
A block selection is exactly its members: a selected parent does not select its children. Nested blocks render inside their parent’s element, so a background on a selected parent paints under its unselected children too. The demo paints them back:
[data-edytor-selected] [data-edytor-block]:not([data-edytor-selected]) {
background: #fff;
}
Block colors
A block’s colour and background (data.color, data.background, set from the block menu) render as data-edytor-color and data-edytor-background on the block element: a name of lowercase letters, digits and hyphens starting with a letter; any other value renders nothing. The core’s stylesheet paints Notion’s nine names, gray, brown, orange, yellow, green, blue, purple, pink and red, from tokens, each with Notion’s light value as its fallback:
| Token | Paints |
|---|---|
--edytor-color-<name> |
The text colour, color on the block (#cf5148 for red) |
--edytor-background-<name> |
The background, background-color on the block (#fce9e7 for red) |
The colour is inherited by the block’s children, as in Notion; a colour mark on text inside wins. Set the tokens for a dark theme, and paint a name of your own with its own rule:
.dark {
--edytor-color-red: #e06c60;
--edytor-background-red: #3b2220;
}
[data-edytor-block][data-edytor-background='teal'] {
background-color: #e0f2f1;
}
Nested blocks
Children render inside the parent’s element, wherever the kind’s snippet renders children(). Every rich text kind renders them in one container, a direct child of the block element marked data-edytor-children, after the block’s own content (a heading’s children follow its h2, a quote’s its blockquote). As in Notion, a block nested under any kind sits one nesting step in: the core’s default style, and the Notion theme, indent that container by --edytor-nest-indent (24px by default):
[data-edytor-children] {
padding-inline-start: var(--edytor-nest-indent, 24px);
}
Change the step on the editor or any ancestor:
[data-edytor] {
--edytor-nest-indent: 32px;
}
A kind of your own does the same: render its children in one <div data-edytor-children> (when children is not null), and nesting under it looks like nesting under every other kind. The drop indicator reads the same variable (in px) to place an inside drop under a block with no visible children.
A kind that indents its children another way, with a marker column, sets that container’s padding to zero so the indent is not doubled. Keep a block’s own content and its children container in separate elements, then lay them out in a grid so a nested block starts on a new row, in the text column:
[data-edytor-type='bulleted-list-item'] {
list-style: none;
display: grid;
grid-template-columns: var(--edytor-nest-indent, 24px) minmax(0, 1fr);
}
[data-edytor-type='bulleted-list-item']::before {
content: '•';
text-align: center;
}
[data-edytor-type='bulleted-list-item'] > div {
grid-column: 2;
min-width: 0;
}
/* The marker column already indents the children. */
[data-edytor-type='bulleted-list-item'] > [data-edytor-children] {
padding-inline-start: 0;
}
The rich text list items, to-dos and callouts render their content and their children container in two direct div children, which this rule puts in column 2. A flex row would instead place a nested block beside its parent’s text. The Notion theme does this for lists, to-dos and callouts (whose children align with the text after the icon), and aligns a toggle’s children with its text.
For numbered items, count with CSS counters on the editor root:
[data-edytor] { counter-reset: numbered; }
[data-edytor-type='numbered-list-item'] { counter-increment: numbered; }
[data-edytor-type='numbered-list-item']::before { content: counter(numbered) '.'; }
The overlay
Chrome never lives inside the editable root. The editor adds a sibling right after it, [data-edytor-overlay], an absolutely positioned, zero-size layer. Your block handles, menus and toolbar, the drop indicator and collaborators’ carets are rendered there and positioned against the blocks once per frame, following scrolls, resizes (the window’s, the editor’s and each block’s, so a font or an equation that draws late moves them too) and edits.
| Element | Selector |
|---|---|
| Block handle host | [data-edytor-block-handle-host], with data-block-id and data-visible |
| Drop indicator | [data-edytor-drop-indicator], with data-position before, after or inside |
| Nest backdrop | [data-edytor-drop-backdrop], with data-shown="true" and the future parent’s data-block-id while a drop nests (hidden otherwise) |
| Another user’s caret, range and name | [data-edytor-remote-cursor] (data-edytor-remote-block beside a block selection), [data-edytor-remote-selection], [data-edytor-remote-cursor-label], each with data-client-id and that user’s colour as --edytor-remote-color |
| Slash menu host | [data-edytor-slash-menu-host] |
| Toolbar host | [data-edytor-toolbar-host] |
| Block menu host | [data-edytor-block-menu-host] |
| Marquee rectangle | [data-edytor-marquee-host] (placed and sized to the rectangle), your box inside |
The layer sits at its natural place right after the root and positions chrome relative to itself, so chrome follows the editor through page and container scrolls. Since it is a sibling of the root, scope overlay styles with the overlay selector, not the root’s.
CSS variables
| Variable | Default | Effect |
|---|---|---|
--edytor-drop-indicator-color |
rgba(35, 131, 226, 0.43) |
The drop indicator’s bar, which the Notion theme paints with: carried from the target block onto [data-edytor-drop-indicator], for a theme’s rule to read. Set it on the root or any ancestor. |
--edytor-nest-indent |
24px |
One nesting step: the [data-edytor-children] container’s indent, and the drop indicator’s inside offset. Set it on the root or any ancestor. |
--edytor-drop-backdrop-color |
rgba(35, 131, 226, 0.14) |
The nest backdrop over the future parent’s row: carried from that block onto [data-edytor-drop-backdrop], for a theme’s rule to read. Set it on the root or any ancestor. Use one plain color, not light-dark(). |
--edytor-drop-reach |
240px |
How far a block drag still drops outside the blocks: past the handle column on the left and past the blocks’ right edge. Read from the root, so set it on the root or any ancestor. |
--edytor-remote-color |
the user’s | Another user’s colour, set inline on their caret and ranges (their name pill inherits it): the Notion theme paints them with it. Read it, do not set it. |
--edytor-marquee-background |
rgba(35, 131, 226, 0.14) |
The marquee’s rectangle fill. The rectangle is in the overlay, the root’s sibling: set it on an element around the editor, not on the root. |
--edytor-marquee-border |
1px solid rgba(35, 131, 226, 0.4) |
The marquee’s rectangle border (a border shorthand); set it around the editor. |
--edytor-marquee-radius |
2px |
The marquee’s rectangle corners; set it around the editor. |
[data-edytor] {
--edytor-drop-indicator-color: #2eaadc;
}
Style with CSS, not by mutating the DOM
The editor compares the DOM it rendered with the document and restores what it owns. If a script changes the editor’s DOM:
- a node added inside a text segment is removed;
- a node added beside the segments, inside a block’s markup, is left alone;
- text added inside a block’s content is read as typed text and becomes part of the document;
- attributes the core does not own, such as an
ida plugin sets on a block element oropenon a toggle, are never reverted.
So style with CSS selectors on the attributes above, add attributes from a plugin’s onBlockAttached if you need them, and render extra markup from a kind’s snippet (marked use:block.void) or in the overlay. Do not insert elements into text or rewrite text nodes to decorate them; use a kind’s transformText or a mark instead.