webflow.createStyle(name)
webflow.createStyle(name)
Create a new Style with a provided name.
Syntax
webflow.createStyle(name: string): Promise<Style>
Parameters
name
: String - The name of the style.
Returns
Promise<Style>
A Promise that resolves to a Style object.
Example
// Create new style
const newStyle = await webflow.createStyle(styleName);
// Set properties for the style
newStyle.setProperties({
"background-color": "blue",
"font-size": "16px",
"font-weight": "bold",
});
// Get Selected Element
const selectedElement = await webflow.getSelectedElement()
if (selectedElement?.styles) {
// Apply style to selected element
await selectedElement.setStyles([newStyle])
} else {
console.log("No element selected")
}
Designer Ability
Designer Ability | Locale | Branch | Workflow | Sitemode |
---|---|---|---|---|
canCreateStyleBlocks | Primary | Any | Canvas | Design |