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
idmust be unique for each diagram - Always call
bindFunctions()after inserting SVG into DOM if returned - The
containerparameter is used for temporary rendering and measurements - Diagram text is preprocessed to handle directives and configuration
- The method respects configuration set via
initialize()
Queue behavior
Render operations are enqueued to prevent race conditions:Related methods
- run() - Render all diagrams in the document
- parse() - Validate diagram syntax without rendering
- initialize() - Configure rendering options