Config

The DotLottie constructor accepts a config object with the following properties:

Config Options

PropertyTypeDefaultDescription
canvasHTMLCanvasElement | OffscreenCanvasrequiredCanvas element for rendering
srcstringundefinedURL to load animation from
datastring | ArrayBuffer | objectundefinedAnimation data (JSON string, ArrayBuffer for .lottie, or object)
autoplaybooleanfalseAuto-start animation on load
loopbooleanfalseLoop the animation
loopCountnumber0Number of loops (0 for infinite)
speednumber1Animation playback speed
mode'forward' | 'reverse' | 'bounce' | 'reverse-bounce''forward'Playback mode
useFrameInterpolationbooleantrueEnable frame interpolation for smooth playback
segment[number, number]undefinedFrame segment to play [startFrame, endFrame]
backgroundColorstringundefinedCanvas background color (hex, rgb, etc.)
renderConfigRenderConfig{}Rendering configuration options
layoutLayoutundefinedAnimation layout and fitting options
markerstringundefinedNamed marker to play from
animationIdstringundefinedAnimation ID (for .lottie files with multiple animations)
themeIdstringundefinedTheme ID to apply
stateMachineIdstringundefinedState machine ID to load
stateMachineConfigStateMachineConfigundefinedState machine configuration

RenderConfig

PropertyTypeDefaultDescription
autoResizebooleantrueAuto-resize canvas to match container
devicePixelRationumberwindow.devicePixelRatioDevice pixel ratio for high-DPI displays
freezeOnOffscreenbooleantruePause rendering when canvas is offscreen

Layout

PropertyTypeDefaultDescription
fit'contain' | 'cover' | 'fill' | 'none' | 'fit-width' | 'fit-height''contain'How to fit animation in canvas
align[number, number][0.5, 0.5]Alignment within canvas [x, y] from 0 to 1

StateMachineConfig

PropertyTypeDescription
openUrlPolicyobjectURL opening policy configuration
openUrlPolicy.requireUserInteractionbooleanRequire user interaction before opening URLs
openUrlPolicy.whiteliststring[]Allowed URL patterns

Example Configuration

const dotLottie = new DotLottie({
canvas: document.querySelector('#canvas'),
autoplay: true,
loop: true,
speed: 1.5,
src: 'animation.lottie',
backgroundColor: '#ff0000',
segment: [10, 50],
renderConfig: {
autoResize: true,
devicePixelRatio: 2
},
layout: {
fit: 'contain',
align: [0.5, 0.5]
},
stateMachineConfig: {
openUrlPolicy: {
requireUserInteraction: true,
whitelist: ['https://trusted-domain.com']
}
}
});