# draw.io XML Schema Reference Complete reference for the `.drawio` file format (mxGraph XML). Use this when generating, parsing, or validating diagram files. --- ## Top-Level Structure Every `.drawio` file is XML with this root structure: ```xml ``` ### `` Attributes | Attribute | Required | Default | Description | | ----------- | ---------- | --------- | ------------- | | `host` | No | `"app.diagrams.net"` | Origin editor (`"Electron"` for desktop/VS Code) | | `modified` | No | — | ISO 8601 timestamp | | `agent` | No | — | User agent string | | `version` | No | — | draw.io version | | `type` | No | `"device"` | Storage type | ### `` Attributes | Attribute | Required | Description | | ----------- | ---------- | ------------- | | `id` | Yes | Unique page identifier (any string) | | `name` | Yes | Tab label shown in editor | ### `` Attributes | Attribute | Type | Default | Description | | ----------- | ------ | --------- | ------------- | | `dx` | int | `1422` | Scroll X offset | | `dy` | int | `762` | Scroll Y offset | | `grid` | `0`/`1` | `1` | Show grid | | `gridSize` | int | `10` | Grid snap size in px | | `guides` | `0`/`1` | `1` | Show alignment guides | | `tooltips` | `0`/`1` | `1` | Enable tooltips | | `connect` | `0`/`1` | `1` | Enable connection arrows on hover | | `arrows` | `0`/`1` | `1` | Show directional arrows | | `fold` | `0`/`1` | `1` | Enable group fold/collapse | | `page` | `0`/`1` | `1` | Show page boundary | | `pageScale` | float | `1` | Page zoom scale | | `pageWidth` | int | `1169` | Page width in px (A4 landscape) | | `pageHeight` | int | `827` | Page height in px (A4 landscape) | | `math` | `0`/`1` | `0` | Enable LaTeX math rendering | | `shadow` | `0`/`1` | `0` | Global shadow on shapes | **Common page sizes (px at 96dpi):** | Format | Width | Height | | -------- | ------- | -------- | | A4 landscape | `1169` | `827` | | A4 portrait | `827` | `1169` | | A3 landscape | `1654` | `1169` | | Letter landscape | `1100` | `850` | | Letter portrait | `850` | `1100` | | Screen (16:9) | `1654` | `931` | --- ## Reserved Cells (Always Required) ```xml ``` These two cells MUST be the first entries inside ``. IDs `0` and `1` are reserved and must not be used for any other cell. --- ## Vertex (Shape) Element ```xml ``` ### `` Vertex Attributes | Attribute | Required | Type | Description | | ----------- | ---------- | ------ | ------------- | | `id` | Yes | string | Unique identifier within this diagram | | `value` | Yes | string | Label text (HTML allowed if style has `html=1`) | | `style` | Yes | string | Semicolon-delimited key=value style string | | `vertex` | Yes | `"1"` | Must be `"1"` to declare this as a shape | | `parent` | Yes | string | Parent cell ID (`"1"` for default layer) | ### `` Vertex Attributes | Attribute | Required | Type | Description | | ----------- | ---------- | ------ | ------------- | | `x` | Yes | float | Left edge of shape (px from canvas origin) | | `y` | Yes | float | Top edge of shape (px from canvas origin) | | `width` | Yes | float | Shape width in px | | `height` | Yes | float | Shape height in px | | `as` | Yes | `"geometry"` | Always `"geometry"` | --- ## Edge (Connector) Element ```xml ``` ### `` Edge Attributes | Attribute | Required | Type | Description | | ----------- | ---------- | ------ | ------------- | | `id` | Yes | string | Unique identifier | | `value` | Yes | string | Connector label (empty string for no label) | | `style` | Yes | string | Style string (see Edge Styles) | | `edge` | Yes | `"1"` | Must be `"1"` to declare as connector | | `source` | No | string | ID of source vertex | | `target` | No | string | ID of target vertex | | `parent` | Yes | string | Parent cell ID (usually `"1"`) | ### `` Edge Attributes | Attribute | Required | Type | Description | | ----------- | ---------- | ------ | ------------- | | `relative` | No | `"1"` | Always `"1"` for edges | | `as` | Yes | `"geometry"` | Always `"geometry"` | ### Edge with Label Offset ```xml ``` The `x` on relative geometry moves the label along the edge (-1 to 1). `y` is perpendicular offset in px. ### Edge with Manual Waypoints (Control Points) ```xml ``` --- ## Multi-Page Diagrams ```xml ... ... ``` Each `` is a separate page/tab. Cell IDs are scoped to their own `` — the same ID value can appear in different pages without conflict. --- ## Layer Cells Layers replace the default `id="1"` layer. Cells are assigned to a layer via `parent`: ```xml ``` Toggle layer visibility: ```xml ``` --- ## Swimlane Container ```xml ``` > **Key**: Cells inside a swimlane have `parent` set to the **lane's ID**, not `"1"`. > Coordinates inside lanes are **relative to the lane origin**. --- ## Group Cells ```xml ``` --- ## HTML Labels When `html=1` is in the style, `value` can contain HTML: ```xml ``` HTML must be XML-escaped: - `<` → `<` - `>` → `>` - `&` → `&` - `"` → `"` Common HTML tags supported: ``, ``, ``, `
`, ``, ``, `
` --- ## Tooltip / Metadata ```xml ``` --- ## ID Generation Rules | Rule | Detail | | ------ | -------- | | IDs `0` and `1` | Reserved — always the root and default layer | | All other IDs | Must be unique within their `` | | Safe pattern | Sequential integers starting at `2`, or UUID strings | | Cross-page | IDs do not need to be unique across different `` pages | **Safe sequential ID example:** ```text id="2", id="3", id="4", ... ``` **UUID-style example:** ```text id="a1b2c3d4-e5f6-7890-abcd-ef1234567890" ``` --- ## Coordinate System - Origin `(0, 0)` is **top-left** of the canvas - `x` increases **rightward** - `y` increases **downward** - All units are **pixels** --- ## Recommended Spacing | Context | Value | | --------- | ------- | | Minimum gap between shapes | `40px` | | Comfortable gap | `80px` | | Swimlane inner padding | `20px` | | Page margin from edge | `40px` | | Connector routing clearance | `10px` | --- ## Minimal Valid `.drawio` File ```xml ``` --- ## Validation Rules ### Must Pass - [ ] `id="0"` and `id="1"` cells always present as first two children of `` - [ ] No other cell uses `id="0"` or `id="1"` - [ ] All `id` values are unique within each `` - [ ] Every `` has exactly one `` child - [ ] `` has `as="geometry"` attribute - [ ] Vertex cells have `vertex="1"`, edge cells have `edge="1"` - [ ] Edge `source`/`target` IDs reference existing vertex IDs in the same diagram - [ ] Swimlane children have `parent` set to the swimlane/lane ID, not `"1"` - [ ] HTML in `value` attributes is XML-escaped ### Recommended - [ ] Shapes do not overlap unless intentional (use ≥40px gap) - [ ] Edge labels are short (≤4 words) - [ ] Layer cells have descriptive `value` names - [ ] All shapes fit within `pageWidth` × `pageHeight` bounds