Styling

One playground in six complete looks, each with the CSS that makes it: custom properties, parts, and a start from nothing.

Framework decisions behind it: D76.

A playground takes its look from the page. By default it is quiet: your text colour, your font, no ground of its own. Below it wears six complete looks. The CSS of each is shown below it, and is the CSS that applies.

Six looks, one playground

Look
// The same playground in every look. const greet = (name) => `Hello, ${name}.`; console.log(greet("styling"));
The default look: no CSS

How a look is made

Colours, sizes and corners are custom properties that start with --pg-. They cross the shadow boundary, so a rule on code-playground sets them. Every part has a name for ::part(), which reaches it from outside. Default styles sit in a cascade layer, so an ordinary rule of yours wins without !important.

The playground sets no container of its own. Give it container-type: inline-size and a container query answers its width, not the screen's, as in the side by side look. The last look sets the unstyled attribute, which drops the defaults, and adds a sheet of its own with addStyleSheet().