addAdoptedStyleSheet

addAdoptedStyleSheet(document, styleSheet) adds a single CSSStyleSheet to a Document or ShadowRoot. It is idempotent — adding the same sheet twice leaves a single entry. Remove it again with removeAdoptedStyleSheet.

Arguments

Argument Type Description
document Document | ShadowRoot Target whose adoptedStyleSheets to add to.
styleSheet CSSStyleSheet The sheet to adopt.

Examples

Add and remove a sheet

Adopts a stylesheet built with sheet(), then removes it later. Adding twice is a no-op.

import {
	sheet,
	addAdoptedStyleSheet,
	removeAdoptedStyleSheet,
} from 'pota/use/css'

const s = sheet('body { background: black }')
addAdoptedStyleSheet(document, s)
// ...later
removeAdoptedStyleSheet(document, s)