Skip to content
AliasCSS Logo
v1.5.6
Docs / Responsive and scopes

Responsive and scopes

A scope starts with @ and says where a class applies, such as a breakpoint, a media feature, a container or a cascade layer. Four rules cover every responsive layout.

Breakpoints

Scope Applies
@xs- below 576px (max-width: 575.99px)
@sm- from 576px
@md- from 768px
@lg- from 992px
@xl- from 1200px
@xxl- from 1408px. There is no 2xl.
@xs-d-none
@md-p-24px
@lg--hover-c-red
Generated CSS
@layer xs {
  @media (max-width: 575.99px) {
    .\@xs-d-none {
      display: none;
    }
  }
}
@layer md {
  @media (min-width: 768px) {
    .\@md-p-24px {
      padding: 24px;
    }
  }
}
@layer lg {
  @media (min-width: 992px) {
    .\@lg--hover-c-red:hover {
      color: red;
    }
  }
}

Always write the @. Since 1.5.4 the bare form (md-d-none) compiles to nothing, because it collided with property names like print-color-adjust. The one exception is dark- and light-, which still work without it.

The prefix is @md, not @md-. A dash joins it to a property; a state or a combinator already starts with its own separator, so it follows directly:

Class Selector
@md-d-none the element
@md--hover-c-red :hover
@md_li-c-red every li inside
@md__li-c-red direct li children
@md[c-red,p-4px] several styles at once

@md-_li-… and @md-__li-… don’t compile.

Every breakpoint class goes into a cascade layer named after it, so the generated CSS stays ordered however your classes are ordered in the markup.

The four rules

1. A plain class always beats a breakpoint class. Breakpoints live in layers, and unlayered CSS wins over layered CSS. p-32px @xs-p-16px is 32px everywhere. Give every size a scope instead:

<div class="@xs-p-16px @sm-p-24px @md-p-32px">

2. @xs is a max-width, the others are min-widths. If you start with @xs, also set @sm, or screens from 576px to 767px get nothing:

<div class="@xs-x-col-12 @sm-x-col-12 @lg-x-col-8">

3. Larger breakpoints win over smaller ones. @md overrides @sm, @lg overrides @md.

4. A default that a breakpoint changes later goes in the components layer. The components layer sits below every breakpoint layer, so a breakpoint can still override it:

@components[d-none]
@lg-d-block
Generated CSS
@layer components {
  .\@components\[d-none\] {
    display: none;
  }
}
@layer lg {
  @media (min-width: 992px) {
    .\@lg-d-block {
      display: block;
    }
  }
}

That element is hidden below 992px and a block from there. The same works for any property: @components[p-16px] @lg-p-32px is 16px everywhere and 32px from @lg. A plain class can’t do this (rule 1), and @xs stops at 575px.

Media features

Scope Media query
@dark- prefers-color-scheme: dark
@light- prefers-color-scheme: light
@motion-reduce- prefers-reduced-motion: reduce
@hover-capable- hover: hover, for hover effects that shouldn’t stick on touch screens
@print- print
@motion-reduce-transition-duration-0s
@hover-capable--hover-tf-translateY--2px
@print-d-none
Generated CSS
@media (prefers-reduced-motion: reduce) {
  .\@motion-reduce-transition-duration-0s {
    transition-duration: 0s;
  }
}
@media screen and (hover: hover) {
  .\@hover-capable--hover-tf-translateY--2px:hover {
    transform: translateY(-2px);
  }
}
@media print {
  .\@print-d-none {
    display: none;
  }
}

Container queries

Mark a container with container-type-inline-size, then use @container- with the same breakpoint names. The element responds to its container’s width instead of the window’s:

container-type-inline-size
@container-md-d-grid
Generated CSS
.container-type-inline-size {
  container-type: inline-size;
}
@container (min-width: 768px) {
  .\@container-md-d-grid {
    display: grid;
  }
}

Cascade layers

AliasCSS declares its layers in this order:

@layer reset, base, theme, components, utilities;

followed by the breakpoint layers. Scope a class into one with @reset-, @base-, @theme-, @components- or @utils-. Component libraries use this to stay overridable: put a component’s own styles in @components[…], and any class a caller adds wins without a merge helper.

Entry styles and several scopes

@starting-style- (or @ss-) writes the styles an element starts from when it first appears, for transitions without keyframes. Several scopes can be combined in brackets:

@starting-style-o-0
@[components,starting-style]-o-0
Generated CSS
@starting-style {
  .\@starting-style-o-0 {
    opacity: 0;
  }
}
@layer components {
  @starting-style {
    .\@\[components\,starting-style\]-o-0 {
      opacity: 0;
    }
  }
}