Skip to content

Visual Editing

Last updated:

Visual editing turns the live preview from a passive display into an interactive canvas. You select, drag, connect, and inline-edit elements directly in the preview, and every change is written back to the source. Its other half is the Element Style pane, a property inspector that restyles the selected element (colors, presets, and diagram-type-specific controls) and writes the result back as Mermaid styling syntax.

Visual editing with a selected node, add handle, and the Element Style pane

The available actions depend on the active diagram type, and the exact capabilities are not identical across them. Some of those differences are deliberate (an interaction that fits one diagram type may not fit another), and others reflect that visual editing is built out iteratively per diagram type rather than reaching full parity all at once. The table below is generated from the latest plugin release; click a diagram name for the actions and shortcuts specific to that type.

Visual-editing actions by diagram type
DiagramClick NavigationInline EditNode MoveAdd ElementEdge RetargetGroupDeleteStyle Pane
Flowchart✓✓✓✓✓✓✓✓
Swimlane✓✓✓✓✓✓✓✓
Sequence✓✓✓—✓—✓—
Class✓✓————✓✓
State✓—————✓—
Architecture✓———————
Block✓———————
Entity Relationship✓———————
Mindmap✓———————
Requirement✓———————

Visual editing is added selectively, for high-value diagram types: commonly used ones whose syntax is involved enough, or whose element-level styling is rich enough, to justify the UX investment. Support for additional diagram types will be added in future releases.

The Edit Mode toggle (pencil icon) in the editor toolbar flips the preview between preview mode and visual editing. Here is the toolbar on a flowchart:

The editor toolbar with Appearance and Layout, then Edit Mode turned on and Caret Tracking, then Diagram Documentation and the editor layout buttons

From left to right, the toolbar holds:

  1. Appearance — Set the diagram’s theme, look, and font (see Appearance)
  2. Layout — Set the layout algorithm on diagram types that offer more than one (see Layout)
  3. Edit Mode — Toggle edit mode on or off (pencil icon)
  4. Caret Tracking — Sync the editor cursor with preview highlighting
  5. Diagram Documentation — Open the Mermaid.js docs for the current diagram type

A dot grid background appears behind the diagram when edit mode is active.

In edit mode, the preview shows a diagram actions toolbar with the actions that add to the diagram as a whole. On a flowchart, it holds Add Node, which opens the shape picker, and Add Subgraph, which inserts a new container:

The flowchart diagram actions toolbar with the Add Node and Add Subgraph buttons

Each diagram type brings its own actions. Swimlane diagrams add Add Swimlane, and sequence diagrams offer Add Participant and Autonumber. The toolbar sits in the top-right corner by default; move it in Preview settings.

Swimlane diagrams also let you drag a lane in the preview to reorder it, writing the new lane order back to the source, as the clip below shows.

In preview mode (edit mode off), the diagram behaves like a standard Mermaid.js render. Built-in Mermaid.js interactivity such as actor menus and external links works normally, and you can navigate to source by holding Command Control and clicking an element.

In edit mode, clicking an element navigates directly to its source declaration without needing a modifier key. The selection, manipulation, and creation features described on each diagram-type page become available.

The Pan Mode toggle (hand icon) at the end of the zoom controls pauses visual editing so you can move around the diagram.

While pan mode is on, left-click dragging pans the viewport, and the preview stops responding to editing: elements can’t be selected, dragged, or edited, and the diagram actions toolbar is hidden. Turn pan mode off to resume editing.

Middle-click dragging always pans the diagram regardless of whether pan mode is enabled.

The Caret Tracking toggle in the editor toolbar links cursor movement in the editor with element highlighting in the preview.

With caret tracking on, moving the cursor to a diagram element in the source code highlights the corresponding element in the preview and updates the Element Style pane.

Caret tracking is off by default for .mmd files and can be toggled as needed. In Markdown files, caret tracking is always active.

Visual editing provides bidirectional navigation between the source code and the rendered diagram.

  • Preview to source — Click an element in the preview to jump to its declaration in the editor. In preview mode (edit mode off), hold Command Control and click instead. Preview-to-source navigation is available across a subset of diagram types.
  • Hover highlighting — Navigable elements highlight when you hover over them, signalling what you can interact with.

Click an element in the preview to select it. The selected element is highlighted, and its source range is selected in the editor.

Build up a selection of multiple elements using any of these methods:

  • Shift+Click an element to add or remove it from the current selection.
  • Marquee select — Click and drag on an empty area of the canvas to draw a selection rectangle around multiple elements.

Marquee selection around diagram elements

Command + A Control + A selects every element in the diagram.

When multiple elements are selected, the Element Style pane shows only the properties common to all of them.

Two nodes selected with shared style properties in the Element Style pane

Each diagram type adds its own structural selection commands (parent / children / siblings, container traversal, and so on). See the diagram-type pages linked above for the specific shortcuts.

In flowchart and swimlane diagrams, you can wrap a selection in a container and lift it back out again without editing the source by hand.

  • Group — Select one or more elements and press Command + G Control + G to wrap them in a new subgraph. Add Subgraph in the diagram actions toolbar inserts an empty container instead.
  • Ungroup — Select a subgraph and press Command + Shift + G Control + Shift + G to lift its members into the parent scope and remove the container.

In sequence diagrams, the same shortcuts wrap messages in a fragment or participants in a box; see Grouping on the sequence diagram page.

Flowchart subgraphs can also be collapsed and expanded from the preview on Mermaid.js 11.17.0 or later.

The clip below selects a subgraph and ungroups it, reparenting its members to the enclosing scope.

Double-click an element in the preview to edit its label inline. An editable text overlay appears over the element, and the change is written back to the source when you commit it (press Enter Enter or click outside the element). Which elements are editable varies by diagram type, and some elements open a small dialog instead of an inline overlay; see the diagram-type pages linked above.

Press Command + B Control + B to toggle bold or Command + I Control + I to toggle italic on the selected element’s label. When multiple elements are selected, the shortcut applies to all of them at once.

Press Backspace Backspace or Delete Delete to remove the selected element or elements, along with their source. Batch deletion works the same way: select multiple elements, then press Delete to remove them all.

All visual-editing actions integrate with the IDE’s undo system. Press Command + Z Control + Z to revert any change made through the preview.

Renaming a selected element via Refactor > Rename follows through to both the Element Style pane header and the preview highlight automatically. The selection clears only when the element is actually deleted, so a rename keeps your in-progress styling work pinned to the element you just renamed.