-
Notifications
You must be signed in to change notification settings - Fork 23k
Refine CSS Value Processing document #40546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
00b8842
7a730ad
e16c142
0a5567b
da297a2
a7ff563
a2bc22b
ddb85e1
57d9f35
118b89e
10974c4
c24c91f
21f4c15
49ed161
8b7cd2a
4bfb703
6515be7
6467d7d
1206ee9
9702e1e
864427f
af0de08
e94c0b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,50 +10,152 @@ For every element in a document tree, the browser assigns a value to every CSS p | |||||||||||
|
|
||||||||||||
| ## Property values | ||||||||||||
|
|
||||||||||||
| Every CSS property's value comes from the declaration with the greatest {{cssxref("specificity")}}. If two or more declarations with the same specificity provide different property values for the same element, the declaration value whose selector has the greatest algorithmic weight gets applied. | ||||||||||||
| Every CSS property that has declarations applied to it is set to its [cascaded value](#cascaded_value), which comes from the property declaration that ranks highest in the [cascade sorting order](/en-US/docs/Web/CSS/CSS_cascade/Cascade#cascading_order) based on the [cascade algorithm](/en-US/docs/Web/CSS/CSS_cascade/Cascade). | ||||||||||||
|
|
||||||||||||
| Each property value comes from a single property-value pair; is single value is applied from each property. Even if the value is a comma separated list of values, that list of values came from a single declaration. | ||||||||||||
| When there are multiple [declared values](#declared_value), with multiple declarations providing the same or different property values for the same element, each property value must still come from a single property name-value pair as only a single value is applied from each property. Even if the value is a comma-separated list of values, that list of values came from a single declaration. | ||||||||||||
sakupi01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||
|
|
||||||||||||
| To determine which specified value is applied, the user agent gathers and processes all the styles from different sources, such as inline styles, and internal and external stylesheets. | ||||||||||||
| To determine which [declared value](#declared_value) is applied, the user agent gathers and processes all the styles from different sources, such as inline styles, and internal and external stylesheets. | ||||||||||||
sakupi01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
|
||||||||||||
| Certain properties inherit values from their parent elements unless explicitly overridden. [Inheritance](/en-US/docs/Web/CSS/CSS_cascade/Inheritance) occurs when no style information exists for a specific property on an element. If the property is inherited, the value is set to the [computed value](#computed_value) of the parent element. If the property is not inherited, its value is set to the [initial value](#initial_value) for that element. | ||||||||||||
| The [cascade](/en-US/docs/Web/CSS/CSS_cascade/Cascade) determines which value should be applied when multiple conflicting styles target the same element. The [cascade algorithm](/en-US/docs/Web/CSS/CSS_cascade/Cascade#cascading_order) defines how user agents combine property values originating from different sources, scopes, and/or [layers](/en-US/docs/Web/CSS/CSS_cascade/Cascade#cascade_layers). When a selector matches an element, the property's [declared value](#declared_value) from the [origin](/en-US/docs/Web/CSS/CSS_cascade/Cascade#origin_types) with the highest precedence gets applied, even if a selector from a lower precedence [origin](/en-US/docs/Web/CSS/CSS_cascade/Cascade#origin_types) or [layers](/en-US/docs/Web/CSS/CSS_cascade/Cascade#cascade_layers) has greater {{cssxref("specificity")}}. | ||||||||||||
|
|
||||||||||||
| The [cascade](/en-US/docs/Web/CSS/CSS_cascade/Cascade) determines which value should be applied when multiple conflicting styles target the same element. The cascade algorithm defines how user agents combine property values originating from different sources, scopes, and/or layers. When a selector matches an element, the property's [specified value](#specified_value) from the origin with the highest precedence gets applied, even if a selector from a lower precedence origin or layer has greater {{cssxref("specificity")}}. | ||||||||||||
| Certain properties inherit values from their parent elements unless explicitly overridden. [inheritance](/en-US/docs/Web/CSS/CSS_cascade/Inheritance) occurs when no style information exists for a specific property on an element. If the property is inherited, the value is set to the [computed value](#computed_value) of the parent element. If the property is not inherited, its value is set to the [initial value](#initial_value) for that element. | ||||||||||||
sakupi01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||
|
|
||||||||||||
| After applying the cascading rules and resolving values step by step, the browser ensures the visual presentation matches the processed CSS. | ||||||||||||
| After applying the [cascading](#cascading) rules and defaulting values step by step, the browser ensures the visual presentation matches the processed CSS. | ||||||||||||
|
|
||||||||||||
| ## Processing overview | ||||||||||||
estelle marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
|
|
||||||||||||
| Before diving into the individual value stages, it's important to understand the three main phases that occur in value processing; [filtering](#filtering), [cascading](#cascading), and [defaulting](#defaulting). | ||||||||||||
|
|
||||||||||||
| ### Filtering | ||||||||||||
|
|
||||||||||||
| **Filtering** is the process of identifying all declarations that apply to each element. A declaration applies to an element only if: | ||||||||||||
|
|
||||||||||||
| - It belongs to a style sheet that currently applies to this document | ||||||||||||
| - Any [conditional rules](/en-US/docs/Web/CSS/CSS_conditional_rules) (like {{cssxref("@media")}} or {{cssxref("@supports")}}) that contain it are currently true, and it belongs to a style rule whose selector matches the element | ||||||||||||
| - It is syntactically valid: the property name is recognized by the browser and the value matches the expected syntax for that property | ||||||||||||
sakupi01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||
|
|
||||||||||||
| Only valid declarations become declared values. Declarations with invalid property names or invalid values get filtered out according to [CSS error handling rules](/en-US/docs/Web/CSS/CSS_syntax/Error_handling). | ||||||||||||
|
|
||||||||||||
| In this example, only the {{cssxref("font-size")}} and {{cssxref("font-weight")}} declarations are processed. The [CSS parser filters out errors](/en-US/docs/Web/CSS/CSS_syntax/Error_handling#css_parser_errors), ignoring or "filtering" out the declaration with the invalid property name: | ||||||||||||
|
|
||||||||||||
sakupi01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
| ```css | ||||||||||||
| p { | ||||||||||||
| font-size: 1.25em; | ||||||||||||
| colr: blue; | ||||||||||||
| font-weight: bold; | ||||||||||||
| } | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| When filtering is complete, every element has zero or more [declared values](#declared-value) for every CSS property. These declared values are the starting point for the [cascading](#cascading) processing stage. | ||||||||||||
|
|
||||||||||||
| ### Cascading | ||||||||||||
|
|
||||||||||||
| [Cascade](/en-US/docs/Web/CSS/CSS_cascade/Cascade) resolves conflicts when multiple declarations apply to the same property on the same element. [cascade](/en-US/docs/Web/CSS/CSS_cascade/Cascade) sorts declarations using [the cascade sorting order](/en-US/docs/Web/CSS/CSS_cascade/Cascade#cascading_order) algorithm. | ||||||||||||
sakupi01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||
|
|
||||||||||||
| For example, if you have the following declarations for `<p class="large">CSS is fun!</p>`, the second declaration wins because it has higher specificity. Both declarations have author origin, but the second selector has specificity of 0,1,1 while the first has 0,0,1: | ||||||||||||
sakupi01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||
|
|
||||||||||||
| ```css | ||||||||||||
| p { | ||||||||||||
| font-size: 1em; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| p.large { | ||||||||||||
| font-size: 1.5em; | ||||||||||||
| } | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| After cascading, the browser determines the [**cascaded value**](#cascaded_value) for each property on each element. This value is the one that will be used in the next processing stage; [defaulting](#defaulting). | ||||||||||||
sakupi01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||
|
|
||||||||||||
| ### Defaulting | ||||||||||||
|
|
||||||||||||
| **Defaulting** ensures every property on every element has a value, even when no declarations apply. This involves: | ||||||||||||
sakupi01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||
|
|
||||||||||||
| - Using **inherited values** for [inherited properties](/en-US/docs/Web/CSS/CSS_cascade/Inheritance#inherited_properties) | ||||||||||||
| - Using **initial values** for [non-inherited properties](/en-US/docs/Web/CSS/CSS_cascade/Inheritance#non-inherited_properties) | ||||||||||||
| - Applying **explicit defaulting keywords** ([`initial`](/en-US/docs/Web/CSS/initial), [`inherit`](/en-US/docs/Web/CSS/inherit), [`unset`](/en-US/docs/Web/CSS/unset), [`revert`](/en-US/docs/Web/CSS/revert), [`revert-layer`](/en-US/docs/Web/CSS/revert-layer)) | ||||||||||||
|
||||||||||||
| - Using **inherited values** for [inherited properties](/en-US/docs/Web/CSS/CSS_cascade/Inheritance#inherited_properties) | |
| - Using **initial values** for [non-inherited properties](/en-US/docs/Web/CSS/CSS_cascade/Inheritance#non-inherited_properties) | |
| - Applying **explicit defaulting keywords** ([`initial`](/en-US/docs/Web/CSS/initial), [`inherit`](/en-US/docs/Web/CSS/inherit), [`unset`](/en-US/docs/Web/CSS/unset), [`revert`](/en-US/docs/Web/CSS/revert), [`revert-layer`](/en-US/docs/Web/CSS/revert-layer)) | |
| - Setting `inherit` for [inherited properties](/en-US/docs/Web/CSS/CSS_cascade/Inheritance#inherited_properties) | |
| - Setting `initial` for [non-inherited properties](/en-US/docs/Web/CSS/CSS_cascade/Inheritance#non-inherited_properties) |
and the last be removed?
Aren't these already in the browsers UA stylesheet? So is the parser doing this explicitly, or is it just reading the UA styles?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estelle
Thank you!
initial or inherit keywords itself are not going to be set by CSS parser if I am being accurate to the spec. It could be any initial value defined in spec(, which is not limited to initial) or inherited from the parent (, which is also not limited to inherit), if I read the spec correctly:
https://www.w3.org/TR/css-cascade-4/#defaulting
I also thought using the word "The CSS parser" here is misleading. The parsing phase corresponds to Filtering phase, which is 2 phases before Defaulting phase.
Also, explicit defaulting keywords also contributes to set specified values which is a result of Defaulting process here. (Each explicit defaulting keywords are also converted to the proper specified values.)
So, I thought it'd be better to mention about explicit defaulting keywords conversion, not entirely deleting.
What do you think about: fixed defaulting description with accuracy?
sakupi01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The terminology "Initial value" is used IN the resolution phase of specified value, that is Defaulting phase - it's not the term to describe the part of value processing flow.
https://www.w3.org/TR/css-cascade-4/#value-stages
https://www.w3.org/TR/css-cascade-4/#defaulting
Uh oh!
There was an error while loading. Please reload this page.