Jens Oliver Meiert

CSS @-Rules, an Overview

Post from September 11, 2017, filed under .

Did you know that @media and @import are the two most popular at-rules? (An educated guess, please correct me if you have data showing otherwise.) But what are the other at-rules, how many are there? I felt motivated to rummage through a few specs and confirm what’s there. A brief overview, as a distant cousin of the much larger HTML elements and CSS properties indexes, and one I’ll likewise keep up-to-date.

Name Description Status Example
@charset […] artifact of the algorithm used to determine the fallback encoding for the stylesheet.” REC
@charset 'utf-8';
@counter-style […] allows authors to define a custom counter style.” CR
@counter-style triangle {
  system: cyclic;
  symbols: ‣;
  suffix: ' ';
}
@font-face […] allows for linking to fonts that are automatically fetched and activated when needed.” REC
@font-face {
  font-family: Headline;
  src: local(Futura-Medium), url(fonts.svg#MyGeometricModern) format('svg');
}
@import […] allows users to import style rules from other style sheets.” REC
@import url('fineprint.css') print;
@keyframes […] specify the values for the animating properties at various points during the animation. The keyframes specify the behavior of one cycle of the animation; the animation may iterate one or more times.” WD
@keyframes diagonal-slide {

  from {
    left: 0;
    top: 0;
  }

  to {
    left: 100px;
    top: 100px;
  }

}
@media […] declare that sections apply to certain media types.” REC
@media screen and (color), projection and (color) {
  /* … */
}
@namespace […] declares a namespace prefix and associates it with a given namespace name.” REC
@namespace svg 'http://www.w3.org/2000/svg';
@page and sub-rules * […] specify various aspects of a page box, such as its dimensions, orientation, and margins.” WD
@page {

  color: red;

  @top-center {
    content: 'Page ' counter(page);
  }

}
@supports [Test] whether the user agent supports CSS property:value pairs.“ CR
@supports ( display: flexbox ) {
  /* … */
}
@viewport […] a feature of a user agent for continuous media and used to establish the initial containing block for continuous media.” WD
@viewport {
  width: 320px auto;
}

Missing here, and not, is @font-feature-values and related at-rules. It’s being worked on in the Fonts Module but, per one of the authors, at risk. I’ll extend this post once anything makes it to official standard (recommendation) status. @document was also at one point considered, then, but got dropped.

* @page has 16 sub-rules, from @bottom-center to @top-right-corner. I decided against listing them in the table because that seemed to reduce, not increase comprehension—after all, they’re all related to @page, and all that differs is directionality. If you feel that these sub-rules are important to call out, or if you have suggestions around the matter, please email me.

About the Author

Jens Oliver Meiert, photo of July 27, 2015.

Jens Oliver Meiert is a developer (O’Reilly, W3C, ex-Google) and philosopher. He experiments with art and adventure. Here on meiert.com he shares and generalizes and exaggerates some of his thoughts and experiences.

There’s more Jens in the archives and at Amazon. If you have any questions or concerns (or recommendations) about what he writes, leave a comment or a message.

Read More

Have a look at the most popular posts, possibly including:

Comments (Open)

What’s your point of view? Comment.

Leave a Comment

Leave a Comment

Respect the comment guidelines. HTML allowed: <a href=""> <blockquote> <code> <em> <strong>

Flattr? Found a mistake? Email me, jens@meiert.com.

You are here: HomeArchive2017 → CSS @-Rules, an Overview

Last update: September 11, 2017

“If there is any secret, it is missed by seeking.”