# Draggable template format
> Draggable (https://draggable.co.uk) is a free, in-browser diagram and flowchart tool. A diagram is a "template": a small piece of XML (or JSON) listing boxes and the connections between them. This page tells an AI assistant, or any other program, how to write one.
You only need to describe WHAT is in the diagram: the steps, and what connects to what. Leave out positions, sizes and colours, and Draggable lays the diagram out, sizes each box to its text, colours it, and routes the lines. This is called simple mode, and it is the form you should write unless asked otherwise.
## How the person uses what you write
Give the template in one code block. The person then, in Draggable:
1. chooses File → "Paste template / use with AI",
2. pastes your text and presses Import.
They can also paste it straight onto the canvas, or save it as a .txt file and use Import. Text around the template (a greeting, Markdown code fences) is ignored, so no special care is needed. If something is wrong, Draggable lists the problems in plain words; the person can paste that list back to you.
## Simple mode: the form to write
```xml
Employee requests leave
Enough allowance?
Manager reviews the request
Approved?
HR system
Leave booked
Request declined
```
Rules:
- Give every box a short, unique `id` (letters, digits, `-`, `_`). Connections refer to boxes by id. A connection that names an id that does not exist is skipped and reported.
- Put the box's wording between the tags. Keep it short: a few words, at most a sentence. Use `&` `<` `>` for `&` `<` `>` (a bare `&` is repaired for you).
- Do NOT write `x`, `y`, `width`, `height` or colours in simple mode. If any box has no `x`/`y`, every box is positioned automatically and any coordinates you did give are ignored.
- List boxes in the order the flow reads, main path first. Order is used to break ties in the layout.
- For a decision, write the expected ("yes" / happy) branch first. Label each branch with `label`.
- A line back to an earlier step (a retry loop) is fine; it is drawn around the outside.
- Write one `` per arrow. Do not draw the same arrow twice.
### Template attributes
| Attribute | Meaning |
|------------|---------|
| `name` | Name in the template list. Required in practice. An existing template of the same name is never overwritten; the import is numbered instead. |
| `title` | Optional heading drawn above the diagram. |
| `subtitle` | Optional line under the heading. |
| `layout` | `down` (default): the flow runs top to bottom. `right`: left to right. Ignored when lanes are used (lanes always run left to right). |
### Box attributes (simple mode)
| Attribute | Meaning |
|-----------|---------|
| `id` | Unique id, used by connections. |
| `shape` | What kind of step it is. See the list below. Default `process`. |
| `lane` | Name of the swimlane the box belongs to. See Swimlanes. |
| `color` | Optional fill, any CSS colour (`#fde68a`, `rgb(…)`). Leave out for the standard colours. |
| `textColor`, `bold="true"`, `fontSize` | Optional text styling. |
| `borderColor`, `borderWidth`, `borderDash="true"` | Optional outline. |
| `width`, `height` | Optional size in pixels. Leave out and the box fits its text. |
### Shapes
Use the name on the left; the alternatives in brackets are accepted too.
| `shape` | Use for |
|------------|---------|
| `process` | A step or action (also: `rect`, `step`, `task`) |
| `start` | Where the flow begins (also: `terminator`, `pill`) |
| `end` | Where the flow finishes; drawn green (also: `stop`) |
| `decision` | A yes/no question or branch (also: `diamond`, `condition`) |
| `input` | Data going in or out (also: `output`, `io`, `para`) |
| `database` | A data store (also: `db`, `cylinder`, `cyl`) |
| `document` | A document, email or report (also: `doc`, `file`) |
| `subprocess` | A step that is itself a whole process (also: `sub`) |
| `preparation` | A set-up step (also: `hexagon`, `hex`) |
| `manual` | Something typed in by a person |
| `trap` | A manual operation |
| `delay` | A wait (also: `wait`, `timer`) |
| `offpage` | A link to another diagram |
| `note` | A comment (also: `comment`, `annotation`) |
| `cloud` | An external system or service (also: `external`, `api`) |
| `ellipse` | A state, or a connector point (also: `circle`) |
| `triangle`, `arrow` | Plain shapes |
| `text` | Words with no box (also: `label`) |
An unknown shape is drawn as `process` and reported.
### Connection attributes
| Attribute | Meaning |
|-----------|---------|
| `from`, `to` | Ids of the two boxes. The arrow points at `to`. Required. |
| `label` | Text on the line, e.g. `Yes`, `No`, `timeout`. Up to 80 characters; keep it to a few words. |
| `dash="true"` | Dashed line. Use for data, messages, or anything that is not the main flow. |
| `color` | Line colour, any CSS colour. A common convention: `#dc2626` (red) for failure paths. |
| `arrow="false"` | No arrowhead (a plain association). |
| `arrowStart="true"` | Arrowhead at the start as well (two-way). |
| `style` | `elbow` (right angles, the simple-mode default), `straight`, or `curve`. |
| `fromSide`, `toSide` | Pin an end to a side of its box: `T`, `R`, `B` or `L`. Leave out unless you need to; the automatic choice is usually right. |
| `width` | Thickness in pixels, 1–8. Default 2. |
| `labelAt` | Where the label sits along the line, 0.05 (start) to 0.95 (end). Default 0.5. |
### Swimlanes
To show who does each step, give boxes a `lane`. Draggable draws one horizontal lane per name, with a coloured heading, and the flow runs left to right across them.
```xml
Raises a ticket
Triage and reproduce
Known issue?
Send help article
Investigate and fix
Reply to the customer
Ticket closed
```
- `` elements are optional. They set the order of the lanes (top to bottom) and, with `color="#…"`, a lane's colour. Without them, lanes appear in the order they are first used.
- If you use lanes, give every box a lane. A box without one is put in the first lane and reported.
- Do not create boxes for the lanes themselves; they are drawn for you.
### Writing a good diagram
- 5 to 25 boxes reads well. Split anything bigger into several templates.
- One `start`. Every path should reach an `end`.
- Every `decision` needs at least two labelled connections leaving it.
- Prefer verbs for steps ("Check stock") and questions for decisions ("In stock?").
- Do not add a legend, title box or lane boxes by hand; use `title`, `subtitle` and `lane`.
## The same thing as JSON
If JSON is easier to produce, this is equivalent. Field names match the XML attributes; `text` holds a box's wording.
```json
{
"name": "Leave request",
"title": "Leave request",
"layout": "down",
"lanes": ["Employee", "Manager"],
"boxes": [
{ "id": "start", "shape": "start", "lane": "Employee", "text": "Requests leave" },
{ "id": "review", "lane": "Manager", "text": "Reviews the request" },
{ "id": "ok", "shape": "decision", "lane": "Manager", "text": "Approved?" },
{ "id": "done", "shape": "end", "lane": "Employee", "text": "Leave booked" }
],
"connections": [
{ "from": "start", "to": "review" },
{ "from": "review", "to": "ok" },
{ "from": "ok", "to": "done", "label": "Yes" },
{ "from": "ok", "to": "start", "label": "No" }
]
}
```
`lanes` and `connections` are optional; `boxes` is required. A JSON Schema is at https://draggable.co.uk/template.schema.json.
## Exact mode: full control
When EVERY box has `x` and `y` (and the template has no `layout` attribute), nothing is rearranged or restyled: the diagram is drawn exactly as written. This is what Draggable's own Export produces, and what "Copy this diagram as text" gives you when a person asks you to change an existing diagram. Edit that text and return all of it.
```xml
Step one
OK?
```
Extra box attributes in exact mode:
| Attribute | Meaning |
|-----------|---------|
| `x`, `y` | Top-left corner in pixels. Negative values are fine. x grows right, y grows down. |
| `width`, `height` | Size in pixels. Default 200 × 200 if left out. |
| `zIndex` | Stacking order; higher is in front. |
| `alignH` (`left`/`center`/`right`), `alignV` (`top`/`middle`/`bottom`) | Text position in the box. |
| `locked="true"` | Background box: cannot be clicked or dragged, and lines pass over it. Used for lanes and frames. |
| `background="true"` | A background box the person has unlocked to edit. Draggable offers to re-lock it. Treat it like `locked` when reading; write `locked="true"` instead when creating. |
| `container="true"` | A frame that carries the boxes inside it when dragged. |
| `shape` | Use the short keys here: `rect`, `pill`, `diamond`, `para`, `hex`, `ellipse`, `cyl`, `doc`, `sub`, `manual`, `trap`, `delay`, `offpage`, `note`, `cloud`, `triangle`, `arrow`, `text`. The friendly names also work. |
A connection may carry `z="1"` (or `-1`, `2`, …) to draw it above (or below) the other lines; by default lines with a label are drawn above lines without one. A connection in exact mode may also carry `bends="x1,y1 x2,y2 …"`: the corners of a line routed by hand (elbow lines only), starting and ending with a short stub out of each box. Leave it out to let Draggable route the line.
A template in exact mode may also end with one or more `` elements: recorded walkthroughs played while presenting, one per scenario (for example "Happy path", "Payment declined"). Each frame is a captured view: the time in seconds from the start, then the centre (cx, cy) and size (w, h) of the area of the diagram in view, in canvas units. Playback glides in a straight line from each view to the next, arriving at its time; it eases out of the first view and into the last, flows through views in between, and two frames with the same view make a pause. Times must not go backwards. Add `pace="even"` (JSON: `"pace": "even"`) to ignore the times and play every glide at one steady speed, timed by the distance it covers; pauses keep their length. Add `path="lines"` (JSON: `"path": "lines"`) to travel along the connector lines between the shapes at consecutive views instead of straight across. Add `focus="shape"` (JSON: `"focus": "shape"`) to make the shape in the middle of the view glow during playback. In JSON it is `"tours": [{ "name": "Happy path", "frames": [[0, 600, 300, 1400, 800], [3, 600, 300, 1400, 800], [5, 300, 200, 500, 300]] }]`; a single `"tour": { … }` from older templates is still read. Simple mode ignores tours, because the layout moves the boxes. Keep the tours the person recorded when you edit a template; only write one if asked.
Exact-mode defaults differ from simple mode, for compatibility with older templates: a box with no `color` is light blue with no outline, and a connection with no `style` is `straight`.
Layout advice if you do place boxes yourself: keep to a grid (for example 200 px across, 150 px down), leave at least 50 px between boxes, and centre boxes that are connected. A process box is about 150 × 72, a decision 160 × 108.
## Mermaid is accepted too
If you can only produce Mermaid, a `flowchart` (or `graph`) diagram imports as well: it is laid out the same way as simple mode. Node shapes map across (`[ ]` step, `{ }` decision, `([ ])` start/end, `[( )]` database, `[[ ]]` subprocess, `{{ }}` preparation, `[/ /]` input/output, `(( ))` circle), as do link labels (`-->|Yes|` or `-- Yes -->`), dotted (`-.->`), thick (`==>`) and two-way (`<-->`) links, and `subgraph` blocks, which become swimlanes. Styling lines (`classDef`, `style`, `click`) are ignored. Prefer the template format above when you can: it is richer (colours, notes, cloud and delay shapes, label positions).
## Opening a diagram from a link
If you can run code, you can hand over a link instead of text. Build a JSON object `{"t": ""}`, encode it as UTF-8, then as URL-safe base64 with no padding, and append it:
```
https://draggable.co.uk/#j=
```
Opening the link imports the template. The part after `#` is never sent to a server.
## More
- App: https://draggable.co.uk
- Help for people: https://draggable.co.uk/help.html
- Source: https://github.com/garethmcauley/Draggable