What is @property in css

@property in CSS is a powerful feature that allows you to define custom properties, similar to variables in programming languages. These custom properties can be used to store and reuse values throughout your CSS stylesheet, making your code more modular, maintainable, and easier to customize.


Key features of @property:

  • Custom property definition: You can create custom properties with a unique name, starting with a double hyphen (--).
  • Syntax specification: You can specify the expected data type for the property's value, such as <color>, <length>, <number>, or <string>.
  • Initial value: You can set a default value for the property.
  • Inheritance: You can control whether the property is inherited by child elements.

Syntax Data Types in CSS @property

When defining a custom property using @property in CSS, you can specify the expected data type for its value using the syntax property. This helps ensure that the property is used correctly and prevents unexpected behavior.

Here are the common syntax data types available in CSS:
  1. <color>: Specifies a color value. Can be expressed in various formats like hex, RGB, HSL, etc.
  2. <image>: Specifies an image URL.
  3. <length>: Specifies a length value, including units like px, em, rem, cm, pt, etc.
  4. <size>: Includes <length> and viewport-relative units like vw, vh.
  5. <number>: Specifies a numeric value.
  6. <integer>: Specifies an integer value.
  7. <string>: Specifies a string value.
  8. <angle>: Specifies an angle value.
  9. <time>: Specifies a time value.
  10. <frequency>: Specifies a frequency value.
  11. <resolution>: Specifies a resolution value.

Browser compatibility



Detailed video instructions


Download code in video


Previous Post Next Post