@property in CSS

@property in CSS ek rule hai jo custom CSS variables ko directly stylesheet me define karne ke liye use hota hai, bina JavaScript ke. Yeh variables ke liye type checking, default value aur inheritance control provide karta hai.


Syntax of @property

Example:

@property in CSS
  • syntax → variable ka data type define karta hai
  • inherits → parent se value inherit hogi ya nahi
  • initial-value → default value

Using @property with var()

Defined variable ko var() function se use karte hain.

Example:

Using @property with var()

Benefits of @property in CSS

  • Data type checking → galat values prevent karta hai
  • Default value → fallback ensure karta hai
  • Inheritance control → behavior control kar sakte ho

@property Example

Example:

@property Example

Overriding Custom Property

Default value ko classes me change kar sakte ho.

Example:

Overriding Custom Property

Type Checking and Fallback

Agar galat value di, toh browser default value use karega.

Example:

Type Checking and Fallback

Inheritance Control

Example:

Inheritance Control
  • true → parent se value milegi
  • false → inherit nahi karega

Animation Use with @property

@property in CSS se advanced animations (like gradients) possible ho jate hain.

Example:

Animation Use with @property

@property in CSS custom variables ko more powerful aur controlled banata hai by adding type safety, default values aur inheritance control. Iska use karke cleaner, safer aur advanced CSS design create kiya ja sakta hai.

Leave a Comment