WikiGalaxy

Personalize

CSS @property

Introduction to CSS @property:

The CSS @property rule is a powerful feature that allows developers to define custom properties (also known as CSS variables) with specific syntax, initial value, and inheritance behavior. This feature enhances the flexibility and control over CSS variables, enabling developers to create more dynamic and interactive styles.

Defining a Custom Property:

To define a custom property using @property, you declare it at the top of your CSS file. You can specify the type, initial value, and whether it inherits. This allows for better management and predictability of CSS variables.

Syntax:

The syntax for using @property is straightforward. Here is a basic example:


        @property --my-color {
          syntax: '';
          initial-value: #000000;
          inherits: false;
        }
      

Usage in CSS:

Once defined, you can use your custom property just like any other CSS variable. For instance, applying it to a background color:


        .my-element {
          background-color: var(--my-color);
        }
      

Benefits:

The benefits of using @property include improved control over CSS variables, the ability to define defaults, and enhanced readability and maintainability of your stylesheets.

Browser Support:

As of now, browser support for @property is limited. It's essential to check compatibility before implementing it in production environments.

Console Output:

No console output for CSS styling.

logo of wikigalaxy

Newsletter

Subscribe to our newsletter for weekly updates and promotions.

Privacy Policy

 • 

Terms of Service

Copyright © WikiGalaxy 2025