Adding DOM Attributes
You can set additional HTML attributes on a number of DOM elements inside the editor. There include:
editor:
The editor itself, excluding menus & toolbars.
block:
The main container element for blocks. Contains both the block's content and its nested blocks.
blockGroup:
The wrapper element for all top-level blocks in the editor and nested blocks.
blockContent:
The wrapper element for a block's content.
inlineContent:
The wrapper element for a block's rich-text content.
In the demo below, we set a custom class on the block
element to add a border to each block:
import "@blocknote/core/fonts/inter.css";
import { BlockNoteView, useCreateBlockNote } from "@blocknote/react";
import "@blocknote/react/style.css";
import "./styles.css";
export default function App() {
// Creates a new editor instance.
const editor = useCreateBlockNote({
// Sets attributes on DOM elements in the editor.
domAttributes: {
// Adds a class to all `blockContainer` elements.
block: {
class: "hello-world-block",
},
},
initialContent: [
{
type: "paragraph",
content: "Welcome to this demo!",
},
{
type: "paragraph",
content: "You can see there's a border around each block",
},
{
type: "paragraph",
content: [
{
type: "text",
text: "This is because there's a CSS rule using the ",
styles: {},
},
{
type: "text",
text: "hello-world-block",
styles: { code: true },
},
{
type: "text",
text: " class we added",
styles: {},
},
],
},
{
type: "paragraph",
},
],
});
// Renders the editor instance using a React component.
return <BlockNoteView editor={editor} />;
}