At-rules in CSS.

What are CSS at-rules?

CSS at-rules all start with the @ sign. These are the instructions of highest level in CSS. Most often, their use is to define an element that will then be reused in classic CSS rules. But they have other uses:

  • Guidelines for processing the rest of the style sheet. This is the case, for example, with @charset.
  • Import another style sheet: @import.
  • At-rules can introduce a bit of algorithms in CSS, as with @supports, @when ... @else, @media, etc.
  • Define reusable elements: @keyframes, @counter-style, @font-face, etc.
  • Finally, a directive behaves like a selector: @page.

At-rules in CSS.

Cascading Style Sheets Level 2 - Revision 1 Specification

@charset
Langue française
Indicates the character set used in the style sheet.

CSS @apply Rule

@apply
Langue française
Applies a group of previously defined properties.

CSS Anchor Positioning

CSS Animations

@keyframes
Langue française
Defines the name of an animation and which properties are animated.

CSS Cascading and Inheritance

@import
Langue française
Importing a style sheet.
@layer
Langue française
Defines cascade layers to help manage priorities between CSS rules.

CSS Color Module

@color-profile
Langue française
Specifies a color profile that can then be used by the color() function.

CSS Conditional Rules Module

@else
Langue française
Completes the @when directive. Defines CSS rules that will only be processed under certain conditions.
@supports
Langue française
Tests browser compatibility with the specified syntax.
@when
Langue française
Defines conditional CSS rules, which will only be processed under certain conditions.

CSS Containment Module

@container
Langue française
Allows you to write conditional CSS rules based on the characteristics of the container.

CSS Counter Styles

@counter-style
Langue française
Creation of a custom counter that can be used in numbered lists.

CSS Device Adaptation Module

@viewport
Langue française
Defines the characteristics of the display window. This directive is an alternative to the HTML meta tag of the same name.

CSS Fonts Module

@font-face
Langue française
Defines all settings for a downloadable font.
@font-feature-values
Langue française
Defines the typographic variations to use.
@font-palette-values
Langue française
Defines a color palette that can then be applied to a font.

CSS Namespaces Module Level 3

@namespace
Langue française
Allows defining namespaces in CSS.

CSS Paged Media Module

@page
Langue française
Page characteristics, when printed.

CSS View Transitions Module

@view-transition
Enables or disables view transitions between pages.

Media Queries

@custom-media
Langue française
Defines a custom media query.
@media
Langue française
Assignment of CSS rules depending on the device (smartphone, desktop screen, etc...).