Skip to content

Directives

ECSS adds a set of directives (at-rules) to plain CSS. Below is a brief summary and where each directive is allowed; details are on the page of the corresponding directive.

DirectivePurposeWhere allowed
@importimport declarations from another .ecss filetop level
@enumenumeration of allowed string valuestop level
@constnamed constanttop level and inside @block
@blockstyle block (becomes a component)top level
@paramblock parameterat the start of a @block body
@elementnested element of a blockinside @block
@if / @elseif / @elseconditional styles based on parameter valuesinside @block
@externalstyles of another block in the context of the current oneinside @block
@debugdebug outputinside @block

Top-level declarations

A file starts with these: @import, @enum, @const, @block. Block and enum names are written in PascalCase (Button, Theme); parameter and constant names are CSS variables with a -- prefix (--variant, --gap).

Inside a block

A @block body starts with @param declarations, followed by CSS rules and the @element, @if/@elseif/@else, @external, @const, @debug directives. Many of them can be nested within each other and within plain CSS rules:

ecss
@block Card {
  @param --active boolean;

  &:hover {
    @if (--active) {
      box-shadow: 0 0 0 2px currentColor;
    }
  }
}

Comments

Both line // and block /* … */ comments are supported. A JSDoc-style comment (/** … */) before @block, @enum, or @param becomes a hover hint in the editor:

ecss
/** Basic button. */
@block Button {
  /** Color scheme. */
  @param --variant Variant;
}