Menu

Element Types and Creation

Relevant source files

This document describes the element type system in Excalidraw and the mechanisms for creating elements programmatically. It covers all available element types, the ExcalidrawElementSkeleton simplified input format, the convertToExcalidrawElements transformation function, and the newElement* constructor functions.

For information about element properties, transformations, and mutations after creation, see Element Properties and Transformations. For element binding mechanisms, see Element Binding System. For data restoration and migration of elements from stored formats, see Data Restoration and Migration.

Element Type Hierarchy

The following diagram shows the type hierarchy of all Excalidraw elements and their key properties:

Sources: packages/excalidraw/data/restore.ts244-418 packages/excalidraw/data/transform.ts176-211 packages/element/src/types.ts

Base Element Properties

All Excalidraw elements share a common set of base properties, regardless of their specific type:

PropertyTypeDescription
idstringUnique identifier, generated by randomId()
typestringElement type discriminator
x, ynumberPosition coordinates
width, heightnumberDimensions
angleRadiansRotation angle
strokeColorstringStroke color
backgroundColorstringFill color
fillStyle"solid" | "hachure" | "cross-hatch"Fill pattern
strokeWidthnumberStroke width
strokeStyle"solid" | "dashed" | "dotted"Stroke pattern
roughnessnumberRoughness level for hand-drawn effect
opacitynumberOpacity (0-100)
groupIdsreadonly GroupId[]Group memberships
frameIdFrameId | nullParent frame
roundnessStrokeRoundness | nullCorner/edge roundness
boundElementsreadonly Binding[]Bound elements (arrows, text)
versionnumberElement version for collaboration
versionNoncenumberRandom nonce for version
isDeletedbooleanSoft deletion flag
seednumberRandom seed for roughness
indexFractionalIndexZ-order fractional index
linkstring | nullHyperlink URL
lockedbooleanLocked from editing

Sources: packages/excalidraw/data/restore.ts177-220 packages/element/src/types.ts

Element Types

Generic Shape Elements

The three basic shape types—rectangle, ellipse, and diamond—share identical properties and are represented by the ExcalidrawGenericElement type:

Generic shapes are created using the newElement function. They can optionally contain bound text elements (see text binding below).

Sources: packages/excalidraw/data/transform.ts529-546 packages/excalidraw/data/restore.ts401-406

Linear Elements

Linear elements (line and arrow) contain an array of points defining their path:

PropertyTypeDescription
pointsreadonly LocalPoint[]Array of [x, y] coordinate pairs
lastCommittedPointLocalPoint | nullLast point during creation
startBindingPointBinding | nullBinding to element at start
endBindingPointBinding | nullBinding to element at end
startArrowheadArrowhead | nullStart arrowhead type
endArrowheadArrowhead | nullEnd arrowhead type

Line elements additionally have:

  • polygon: boolean - Whether to close the path as a polygon

Arrow elements are a specialized subtype:

  • Default endArrowhead is "arrow"
  • Can have elbowed: true for elbow arrows with orthogonal segments
  • Elbow arrows use FixedPointBinding instead of PointBinding

Sources: packages/excalidraw/data/restore.ts316-398 packages/excalidraw/data/transform.ts548-576

Text Elements

Text elements render text content and can exist standalone or bound to containers:

PropertyTypeDescription
textstringText content
fontSizenumberFont size in pixels
fontFamilyFontFamilyValuesFont family ID
textAlign"left" | "center" | "right"Horizontal alignment
verticalAlign"top" | "middle" | "bottom"Vertical alignment
containerIdstring | nullID of container element
originalTextstringOriginal unwrapped text
autoResizebooleanWhether to auto-resize
lineHeightnumberLine height multiplier

Text elements are created with newTextElement. The measureText function calculates dimensions based on font properties:

Sources: packages/excalidraw/data/restore.ts251-300 packages/excalidraw/data/transform.ts578-597

Image Elements

Image elements display embedded or linked images:

PropertyTypeDescription
fileIdFileIdReference to file in BinaryFiles
status"pending" | "saved" | "error"Loading status
scale[number, number]Scale factors [x, y]
cropImageCrop | nullCrop settings

Images are created with newImageElement and require a fileId that references a file in the BinaryFiles storage.

Sources: packages/excalidraw/data/restore.ts309-315 packages/excalidraw/data/transform.ts599-606

Free-Draw Elements

Free-draw elements represent hand-drawn paths:

PropertyTypeDescription
pointsreadonly LocalPoint[]Path points
pressuresreadonly number[]Pressure values (pen input)
simulatePressurebooleanWhether to simulate pressure
lastCommittedPointLocalPoint | nullLast point during drawing

Sources: packages/excalidraw/data/restore.ts301-308

Frame Elements

Frames are container elements that group other elements:

PropertyTypeDescription
namestring | nullFrame name
childrenreadonly string[]IDs of contained elements (skeleton only)

Two frame types exist:

  • frame: Standard frame created with newFrameElement
  • magicframe: AI-generated frame created with newMagicFrameElement

The children property only exists in the skeleton format and is used during conversion to set the frameId on child elements.

Sources: packages/excalidraw/data/restore.ts407-411 packages/excalidraw/data/transform.ts608-631

Embeddable Elements

Embeddable elements display external content:

PropertyTypeDescription
validatedboolean (legacy)Validation status (moved to private state)

Two embeddable types:

  • iframe: Generic iframe embed
  • embeddable: Validated embeddable content

Sources: packages/excalidraw/data/restore.ts404-406 packages/excalidraw/CHANGELOG.md206

Element Creation Patterns

ExcalidrawElementSkeleton

The ExcalidrawElementSkeleton type provides a simplified, declarative format for creating elements without specifying all required properties. It allows partial specification of element properties:

Key differences from full elements:

  • Only requires essential properties (type, position coordinates)
  • Optional id (auto-generated if not provided)
  • Optional label property to create bound text
  • Optional start/end properties on linear elements to create bindings
  • Frame children as array of IDs (converted to frameId on children)

Sources: packages/excalidraw/data/transform.ts176-211

convertToExcalidrawElements

The convertToExcalidrawElements function transforms an array of ExcalidrawElementSkeleton objects into fully-formed ExcalidrawElement objects:

Function signature:

Options:

  • regenerateIds: If true (default), generates new IDs. Set to false to preserve IDs from skeleton.

Key behaviors:

  1. Creates elements via type-specific constructors
  2. Handles default dimensions (DEFAULT_DIMENSION = 100)
  3. Creates bound text for label property
  4. Creates bindings for linear elements with start/end
  5. Converts frame children to child element frameId properties
  6. Synchronizes fractional indices via syncInvalidIndices

Sources: packages/excalidraw/data/transform.ts508-685

Element Creation Flow

Sources: packages/excalidraw/data/transform.ts520-685 packages/excalidraw/actions/actionBoundText.tsx224-273

Constructor Functions

newElement (Generic Shapes)

Creates rectangle, ellipse, or diamond elements:

Sources: packages/excalidraw/data/transform.ts540-544 packages/excalidraw/actions/actionBoundText.tsx238-273

newLinearElement (Lines)

Creates line elements with points:

Sources: packages/excalidraw/data/transform.ts551-557

newArrowElement (Arrows)

Creates arrow elements:

Sources: packages/excalidraw/data/transform.ts563-576

newTextElement (Text)

Creates text elements:

Text dimensions are calculated automatically via measureText based on font properties.

Sources: packages/excalidraw/data/transform.ts578-597 packages/excalidraw/actions/actionBoundText.tsx224-232

newImageElement (Images)

Creates image elements:

Sources: packages/excalidraw/data/transform.ts599-606

newFrameElement & newMagicFrameElement (Frames)

Creates frame or magicframe elements:

Sources: packages/excalidraw/data/transform.ts608-631

Special Creation Features

Label Property (Bound Text)

Both container shapes and linear elements can have a label property in their skeleton that automatically creates bound text:

The label is converted to a text element bound to the container via:

  1. bindTextToContainer for shapes
  2. Similar logic for arrows (via boundElements)

Process:

  1. Text element created with newTextElement
  2. Text positioned via computeBoundTextPosition
  3. Container resized via redrawTextBoundingBox
  4. Bidirectional binding established:
    • Text: containerId set to container ID
    • Container: boundElements includes text binding

Sources: packages/excalidraw/data/transform.ts219-244 packages/excalidraw/actions/actionBoundText.tsx155-173

Arrow Bindings (start/end)

Linear elements can specify start and end properties in their skeleton to create bindings to other elements:

Binding creation:

  1. If id specified: binds to existing element
  2. If type specified without id: creates new element
  3. Calls bindLinearElement to establish binding
  4. Adjusts points by 0.5 pixels to avoid overlap with bound elements

Sources: packages/excalidraw/data/transform.ts246-480

Frame Children Assignment

Frames specify children as an array of element IDs in the skeleton. During conversion, these IDs are converted to frameId properties on the child elements:

The frame itself gets positioned and sized based on the bounding box of its children (calculated via getCommonBounds).

Sources: packages/excalidraw/data/transform.ts608-665

Default Values and Constants

ConstantValueUsage
DEFAULT_DIMENSION100Default width/height for shapes
DEFAULT_LINEAR_ELEMENT_PROPS.width100Default width for lines/arrows
DEFAULT_LINEAR_ELEMENT_PROPS.height0Default height for lines/arrows
DEFAULT_FONT_FAMILYVariesDefault font family
DEFAULT_FONT_SIZEVariesDefault font size
DEFAULT_ELEMENT_PROPSObjectDefault stroke, fill, opacity, etc.

Sources: packages/excalidraw/data/transform.ts212-217 packages/excalidraw/data/restore.ts4-20

Element Restoration vs Creation

While this page focuses on creating new elements, the restoration process (handled by restoreElement and restoreElements) is used when:

  • Loading saved scenes
  • Importing data
  • Handling collaboration updates
  • Migrating from legacy formats

Key differences:

  • Restoration preserves existing IDs, versions, and timestamps
  • Handles legacy property migrations (e.g., strokeSharpnessroundness)
  • Repairs broken bindings and container relationships
  • Validates and syncs fractional indices

For details on restoration, see Data Restoration and Migration.

Sources: packages/excalidraw/data/restore.ts244-694