-
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 1 commit
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,156 @@ 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's value comes from the declaration that wins the {{cssxref("Cascade")}} algorithm. When multiple declarations provide different property values for the same element, the declaration that ranks highest in the [Cascade Sorting Order](/en-US/docs/Web/CSS/CSS_cascade/Cascade#cascading_order) gets applied. | ||||||||||||
sakupi01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||
|
|
||||||||||||
| 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. | ||||||||||||
| Each property value comes from a single property name-value pair; 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. | ||||||||||||
|
||||||||||||
|
|
||||||||||||
| 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.
Outdated
Show resolved
Hide resolved
|
||||||||||||
|
|
||||||||||||
| The {{cssxref("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. When a selector matches an element, the property's [declared value](#declared-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")}}. | ||||||||||||
sakupi01 marked this conversation as resolved.
Outdated
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 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")}}. | ||||||||||||
| 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). | ||||||||||||
sakupi01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||
|
|
||||||||||||
| ### Filtering | ||||||||||||
|
|
||||||||||||
| **Filtering** is the process of identifying all declarations that apply to each element. During this phase, the browser: | ||||||||||||
|
|
||||||||||||
| - Verifies that declarations belong to active stylesheets | ||||||||||||
| - Checks that property names are valid and recognized | ||||||||||||
sakupi01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||
| - Validates that property values match the expected syntax | ||||||||||||
| - Eliminates declarations that are syntactically invalid | ||||||||||||
|
|
||||||||||||
sakupi01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
| ```css | ||||||||||||
| /* Valid declarations become declared values */ | ||||||||||||
| p { | ||||||||||||
| font-size: 1.25em; /* Valid */ | ||||||||||||
| colr: blue; /* Invalid property name - filtered out */ | ||||||||||||
| font-weight: bold; /* Valid */ | ||||||||||||
sakupi01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||
| } | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| As a result of filtering, each element has zero or more [**declared values**](#declared-value) for each property. These declared values are the starting point for the next processing stages; [Cascading](#cascading). | ||||||||||||
sakupi01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||
|
|
||||||||||||
| ### Cascading | ||||||||||||
|
|
||||||||||||
| {{cssxref("Cascade")}} resolves conflicts when multiple declarations apply to the same property on the same element. {{cssxref("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
|
||||||||||||
|
|
||||||||||||
| After applying the cascading rules and resolving values step by step, the browser ensures the visual presentation matches the processed CSS. | ||||||||||||
| 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: | ||||||||||||
|
|
||||||||||||
| ```css | ||||||||||||
| /* Multiple font-size declarations */ | ||||||||||||
| p { | ||||||||||||
| font-size: 1em; | ||||||||||||
| } /* Author origin, specificity: 0,0,1 */ | ||||||||||||
| p.large { | ||||||||||||
| font-size: 1.5em; | ||||||||||||
| } /* Author origin, specificity: 0,1,1 - wins! */ | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| 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). | ||||||||||||
|
|
||||||||||||
| ### 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?
Uh oh!
There was an error while loading. Please reload this page.