Function: injectStyle()
ts
function injectStyle(
id,
css,
options?): () => void;Inject or update a <style> element in <head> identified by id. Calling again with the same id replaces the CSS instead of creating a new element.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The id attribute of the <style> element. |
css | string | The CSS string to inject. |
options? | InjectStyleOptions | Optional configuration for the <style> element. |
Returns
() => void
Examples
ts
injectStyle('theme-root', ':root { --color-primary: #007aff; }')
// update later — same element, new content
injectStyle('theme-root', ':root { --color-primary: #ff3b30; }')ts
const dispose = injectStyle('print-style', 'body { color: black; }', { media: 'print' })
dispose() // removes the style elementSince
1.3.0