--- title: "Composition" description: "The main editing surface returned by openComposition — query, mutate, animate, and serialize a composition." --- `Composition` is the object returned by [`openComposition`](/sdk/reference/open-composition). Every SDK edit goes through this interface. Typed methods are convenience wrappers over `dispatch()`; all validation runs in `dispatch()` regardless of which entry point you use. ```typescript import { openComposition } from "@hyperframes/sdk"; import type { Composition } from "@hyperframes/sdk"; const comp: Composition = await openComposition(html); ``` For a practical walkthrough see [Querying and editing](/sdk/guides/querying-and-editing). --- ## Typed edit methods Typed methods are the recommended way to apply common edits. Each one calls `dispatch()` internally, so all patch events, history, and persistence behavior is identical. ### `setStyle` ```typescript setStyle(id: HfId, styles: Record): void ``` Apply inline CSS styles to one element. Use camelCase property names (matching `CSSStyleDeclaration`). Pass `null` as a value to remove that property. ```typescript comp.setStyle("hf-title", { color: "#FFD60A", fontSize: "96px" }); comp.setStyle("hf-card", { borderRadius: null }); // removes border-radius ``` ### `setText` ```typescript setText(id: HfId, value: string): void ``` Replace the display text of an element. Targets the element's direct text content, not all descendant text. ```typescript comp.setText("hf-headline", "Product launch — June 2026"); ``` ### `setAttribute` ```typescript setAttribute(id: HfId, name: string, value: string | null): void ``` Set or remove an HTML attribute. Pass `null` to remove the attribute entirely. ```typescript comp.setAttribute("hf-logo", "src", "/assets/logo-v2.png"); comp.setAttribute("hf-video", "autoplay", null); // removes autoplay ``` ### `setTiming` ```typescript setTiming(id: HfId, timing: { start?: number; duration?: number; trackIndex?: number }): void ``` Update the `data-start`, `data-duration`, and/or `data-track` attributes of one element. All fields are optional; omitted fields are left unchanged. ```typescript comp.setTiming("hf-title", { start: 0.5, duration: 2.5 }); comp.setTiming("hf-cta", { trackIndex: 1 }); ``` ### `removeElement` ```typescript removeElement(id: HfId): void ``` Remove an element and all its descendants from the composition. The inverse is an `addElement` of the removed subtree, so `undo()` restores it exactly. ```typescript comp.removeElement("hf-old-badge"); ``` ### `addElement` ```typescript addElement(parent: HfId | null, index: number, html: string): HfId ``` Insert an HTML fragment as a child of `parent` at zero-based sibling `index`. Pass `null` for `parent` to insert at the document body root. The fragment must be single-root and must not contain `