Skip to main content
Renders a single Mermaid diagram definition to SVG. This method provides programmatic control over diagram rendering without requiring elements in the DOM.

Signature

Parameters

string
required
Unique identifier for the SVG element. Used as the id attribute of the generated SVG.
string
required
The Mermaid diagram definition to render.
Element
Optional HTML element where the SVG will be inserted during rendering. If not provided, a temporary element is created in the document body and removed after rendering.

Return value

object
An object containing the rendered diagram information.

Examples

Basic rendering

Dynamic diagram generation

Handling different diagram types

With container element

Error handling

Multiple renders in sequence

Usage notes

  • Multiple calls to render() are automatically queued and executed serially
  • The id must be unique for each diagram
  • Always call bindFunctions() after inserting SVG into DOM if returned
  • The container parameter is used for temporary rendering and measurements
  • Diagram text is preprocessed to handle directives and configuration
  • The method respects configuration set via initialize()
Always call bindFunctions() after inserting the SVG into the DOM to enable interactive features like click handlers and tooltips.

Queue behavior

Render operations are enqueued to prevent race conditions:
  • run() - Render all diagrams in the document
  • parse() - Validate diagram syntax without rendering
  • initialize() - Configure rendering options