--- id: css-property title: "CSS @property" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["@property rule", "CSS at-property", "typed custom properties", "registered custom properties", "CSS property syntax inherits initial-value"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.87 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["css", "web", "frontend", "w3schools", "css-variables", "at-rules", "animation"] raw_sources: ["https://www.w3schools.com/css/css3_property.asp"] applied_in: [] github_commit: "" --- # [[CSS @property]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) `@property` defines custom CSS properties (CSS variables) directly in the stylesheet β€” without JavaScript β€” adding data-type checking, a required default value, and explicit control over inheritance. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **What it is** β€” `@property` is used to define custom CSS properties (CSS variables) directly in the stylesheet without having to run any JavaScript. [S1] - **Data type checking** β€” ensures custom properties are used correctly via a declared `syntax` (e.g. `""`). [S1] - **Default value requirement** β€” `initial-value` provides a fallback if an invalid value is assigned. [S1] - **Inheritance control** β€” `inherits: true | false` gives full control over whether the value inherits. [S1] - **Consumed with `var()`** β€” once defined, the property is used like any custom property, e.g. `background-color: var(--myColor);`. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Typed declaration pattern** β€” `@property --name { syntax: ""; inherits: ; initial-value: ; }`. [S1] - **Invalid-value fallback** β€” when a value violates the declared `syntax` (e.g. assigning `2` where a `` is expected), the property falls back to its `initial-value` instead of breaking. [S1] - **Animatable custom colors** β€” declaring color custom properties with `@property` enables them to participate in transitions/animations (e.g. a gradient that animates between `--startColor` and `--endColor`). [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) `@property` is used to define custom CSS properties (CSS variables) directly in the stylesheet without having to run any JavaScript, with data type checking, default values, and inheritance control. [S1] **Basic syntax** [S1] ```css @property --myColor { syntax: ""; inherits: true; initial-value: lightgray; } ``` Usage with the `var()` function: [S1] ```css body { background-color: var(--myColor); } ``` **Example 1 β€” two custom properties** [S1] ```css @property --my-bg-color { syntax: ""; inherits: true; initial-value: lightgray; } @property --my-txt-color { syntax: ""; inherits: true; initial-value: darkblue; } div { width: 300px; height: 150px; padding: 15px; background-color: var(--my-bg-color); color: var(--my-txt-color); } ``` **Example 2 β€” overriding custom properties per class** [S1] ```css @property --my-bg-color { syntax: ""; inherits: true; initial-value: lightgray; } div { width: 300px; height: 150px; padding: 15px; background-color: var(--my-bg-color); } .fresh { --my-bg-color: #ff6347; } .nature { --my-bg-color: rgb(120, 180, 30); } ``` **Example 3 β€” type checking with an invalid value** [S1] Here `.nature` assigns `2`, which is not a valid ``, so the property falls back to its `initial-value`: [S1] ```css @property --my-bg-color { syntax: ""; inherits: true; initial-value: lightgray; } div { width: 300px; height: 150px; padding: 15px; background-color: var(--my-bg-color); } .fresh { --my-bg-color: #ff6347; } .nature { --my-bg-color: 2; } ``` **Example 4 β€” `inherits: false`** [S1] ```css @property --my-bg-color { syntax: ""; inherits: false; initial-value: lightgray; } ``` **Example 5 β€” `inherits: true`** [S1] ```css @property --my-bg-color { syntax: ""; inherits: true; initial-value: lightgray; } ``` **Example 6 β€” animated gradient colors** [S1] ```css @property --startColor { syntax: ""; initial-value: #EADEDB; inherits: false; } @property --endColor { syntax: ""; initial-value: #BC70A4; inherits: false; } ``` **Key benefits listed by the source** [S1] - **Data type checking** ensures custom properties are used correctly. - **Default value requirement** provides a fallback if invalid values are assigned. - **Inheritance control** gives full control over value inheritance behavior. ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's applied examples progress from declaring typed color properties (Example 1), overriding them per class `.fresh` / `.nature` (Example 2), demonstrating fallback to `initial-value` on an invalid `2` (Example 3), contrasting `inherits: false` vs `inherits: true` (Examples 4–5), and finally declaring `--startColor`/`--endColor` for an animated gradient (Example 6). No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Define a typed custom property (language: CSS): ```css @property --my-bg-color { syntax: ""; inherits: true; initial-value: lightgray; } ``` Consume it (language: CSS): ```css div { background-color: var(--my-bg-color); } ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.87 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[CSS Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSS Variables]], [[CSS Variables and JavaScript]], [[CSS Variables in Media Queries]], [[CSS var Function]] - **μ°Έμ‘° λ§₯락:** Referenced when custom properties need type safety, guaranteed fallbacks, or animation support without JavaScript. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” CSS @property β€” https://www.w3schools.com/css/css3_property.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "CSS @property" page (Astra wiki-curation, P-Reinforce v3.1 format).