Skip to main content

Type Selector

A CSS type selector is used to target DOM elements according to their tag name.

This page goes over how Stylable handles type selector, for more details about the language feature itself, checkout MDN type selector.


Native element

A native element behaves exactly as it does in CSS, and requires no special treatment in Stylable.

/* scoped under local class */
.root div {}

/* scoped to local class */
div.root {}

Component element

Use a capital first letter to refer to a default import of a stylesheet root.

@st-import Comp from './';

/* style all Comp nested under root */
.root Comp {}


Stylable validates that a type selector is scoped to the stylesheet it is in. To target a type selector, compound it or scope it under a local class in order to avoid styling unrelated elements outside the scope of the stylesheet.

/* error - unscoped selector */
div {}

/* valid */
.root div {}
div.root {}
reuse scope

Scope rules with the @st-scope at-rule to minimize selector verbosity.

@st-scope .root {
div {}

Import and Export

Component elements, with capital first letter, can be exported from a stylesheet if used in a selector. You can import them within the @st-import named import brackets.
@st-import Button from './';
@st-import Menu from './';

.root Button {}
.root Menu {}
@st-import [Button, Menu] from './';

@st-scope .root {
/* customize all buttons nested in theme root */
Button {}
/* customize all menus nested in theme root */
Menu {}


Elements are not available on the Stylable stylesheet runtime.


Native elements are not namespaced. However, if an element originates from a class, like a component element default import, then it is transformed during build.
@st-import Button from './';

.root Button {}
.root div {}

/* OUTPUT */
.entry__root .button__root {}
.entry__root div {}