Atomico CSS Styling
Developmentatomico-css-stylingAtomico CSS Styling is an Agent Skill for development published in the atomicojs/atomico repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Use the css tagged template literal and adoptedStyleSheets for styling Atomico components. Triggers when the user needs to style web components, use CSS custom properties, create themeable components, or understand how Atomico manages stylesheets. Do NOT trigger for external CSS frameworks unless combined with Atomico's css utility.
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Inspect the Agent Skill at https://github.com/atomicojs/atomico/blob/HEAD/.agents/skills/atomico-css-styling/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/atomico-css-styling, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
CSS & Styling
css Tagged Template
Creates and caches CSSStyleSheet objects using the browser's
adoptedStyleSheets API for optimal performance.
Basic Usage
import { c, css } from "atomico";
const MyComponent = c(
() => (
<host shadowDom>
<h1>Styled component</h1>
</host>
),
{
styles: css`
:host {
display: block;
padding: 1rem;
font-family: system-ui;
}
h1 {
color: #333;
margin: 0;
}
`
}
);
How It Works
cssreceives a template literal and produces aCSSStyleSheet- Sheets are cached by CSS text — identical styles share one instance
- Sheets are applied to the component's
shadowRoot.adoptedStyleSheets - Styles are only applied after the first non-suspended render
Interpolation
const primaryColor = "#3b82f6";
const styles = css`
:host {
--primary: ${primaryColor};
color: var(--primary);
}
`;
Multiple Style Sheets
The styles option can be an array for composing shared styles:
const baseStyles = css`
:host { display: block; box-sizing: border-box; }
`;
const themeStyles = css`
:host { --bg: #fff; --fg: #111; }
`;
const MyComponent = c(
() => <host shadowDom>content</host>,
{
styles: [baseStyles, themeStyles, css`
h1 { color: var(--fg); }
`]
}
);
CSS Custom Properties (Theming)
Custom properties pierce shadow DOM boundaries, making them the primary mechanism for theming Atomico components.
Define in Component
const MyCard = c(
() => <host shadowDom><slot /></host>,
{
styles: css`
:host {
--card-bg: #f0f0f9;
--card-border: #dcdce1;
--card-radius: 0.5rem;
}
:host([active]) {
--card-bg: #a3ebd4;
--card-border: #6ee2c9;
}
:host {
background: var(--card-bg);
border: 1px solid var(--card-border);
border-radius: var(--card-radius);
padding: 1rem;
}
`
}
);
Override from Outside
/* Page CSS can override custom properties */
my-card {
--card-bg: #1a1a2e;
--card-border: #16213e;
}
Common Patterns
:host Selector
/* Default state */
:host { display: block; }
/* Attribute-based state */
:host([active]) { background: green; }
:host([disabled]) { opacity: 0.5; pointer-events: none; }
/* Context-based state */
:host(:hover) { transform: scale(1.02); }
:host(:focus-within) { outline: 2px solid blue; }
::slotted Pseudo-Element
/* Style slotted children (one level deep) */
::slotted(*) { margin: 0.5rem; }
::slotted(h1) { font-size: 2rem; }
::slotted([slot="header"]) { font-weight: bold; }
:host-context (Limited Support)
/* Style based on ancestor */
:host-context(.dark-theme) {
--bg: #1a1a2e;
}
⚠️ Important Notes
-
Shadow DOM required:
cssandstylesonly work withshadowDomenabled. Without shadow DOM, use regular page CSS. -
CSSStyleSheet caching: Identical CSS text produces the same sheet instance. This is memory-efficient for shared base styles.
-
No
<style>tags: Atomico usesadoptedStyleSheetsexclusively. Avoid injecting<style>elements manually. -
Specificity: Shadow DOM CSS is scoped. Styles don't leak out, and external styles don't leak in (except custom properties).