Skip to content

Conversation

@Shrinivassab
Copy link
Contributor

Add reference for CSS value serialization, especially colors

Fixes #32734

Description

Adds a new guide explaining CSS value serialization through JavaScript APIs, with a focus on how color values (hsl(), hwb(), etc.) are serialized to rgb()/rgba() format when accessed via getComputedStyle() or getPropertyValue().

Motivation

This documentation helps developers understand why and how CSS values, especially colors, might return in different formats than they were written. This addresses a common source of confusion when working with CSS values through JavaScript APIs.

Additional details

References:

Related issues and pull requests

Fixes #32734 - Creates documentation for CSS value serialization, especially for colors

Fixes mdn#32734

Adds a new guide explaining how CSS values especially colors are serialized when accessed via JavaScript APIs like getComputedStyle() and getPropertyValue().
@Shrinivassab Shrinivassab requested a review from a team as a code owner September 28, 2025 23:03
@Shrinivassab Shrinivassab requested review from sideshowbarker and removed request for a team September 28, 2025 23:03
@github-actions github-actions bot added the Content:WebAPI Web API docs label Sep 28, 2025
@github-actions github-actions bot added the size/m [PR only] 51-500 LoC changed label Sep 28, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Sep 28, 2025

Preview URLs

Flaws (108)

URL: /en-US/docs/Web/API/CSS_Object_Model/CSS_value_serialization
Title: CSS value serialization
Flaw count: 8

  • macros:
    • Macro produces link /en-US/docs/Web/CSS/named-color which is a redirect
    • Macro produces link /en-US/docs/Web/CSS/system-color which is a redirect
    • Macro produces link /en-US/docs/Web/CSS/hex-color which is a redirect
    • Macro produces link /en-US/docs/Web/CSS/url which is a redirect
    • Macro produces link /en-US/docs/Web/CSS/frequency which is a redirect
    • and 3 more flaws omitted

URL: /en-US/docs/Web/CSS/Guides/Colors
Title: CSS colors
Flaw count: 36

  • macros:
    • Macro produces link /en-US/docs/Web/CSS/color which is a redirect
    • Macro produces link /en-US/docs/Web/CSS/opacity which is a redirect
    • Macro produces link /en-US/docs/Web/CSS/background-color which is a redirect
    • Macro produces link /en-US/docs/Web/CSS/accent-color which is a redirect
    • Macro produces link /en-US/docs/Web/CSS/color which is a redirect
    • and 31 more flaws omitted

URL: /en-US/docs/Web/CSS/Guides/Values_and_units
Title: CSS values and units
Flaw count: 64

  • macros:
    • Macro produces link /en-US/docs/Web/CSS/interpolate-size which is a redirect
    • Macro produces link /en-US/docs/Web/CSS/abs which is a redirect
    • Macro produces link /en-US/docs/Web/CSS/acos which is a redirect
    • Macro produces link /en-US/docs/Web/CSS/asin which is a redirect
    • Macro produces link /en-US/docs/Web/CSS/atan which is a redirect
    • and 59 more flaws omitted

(comment last updated: 2025-11-17 17:49:31)

@Josh-Cena Josh-Cena requested review from estelle and removed request for sideshowbarker September 28, 2025 23:28
Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of content is incomplete or duplicative. I suspect you are using AI to write this, which is fine in principle, but next time please disclose this because it's not the quality we are expecting for a ready-for-review PR. Also, you should document length serialization as well at least, since that's the other common use case.

@Shrinivassab
Copy link
Contributor Author

Hi @Josh-Cena , Yes, I tried the Co-pilot version of Sonnet 3.5. I will keep it in mind to mentioned that in the PR, I was not sure, if we used Copilot need to raise as Draft PR or Ready to reviewPR.

@Shrinivassab
Copy link
Contributor Author

Let me know if any changes need to be updated or any grammatical error . Happy to update it. Thanks for the review.

@Josh-Cena Josh-Cena requested a review from a team as a code owner October 10, 2025 21:50
@Josh-Cena Josh-Cena requested review from pepelsbey and removed request for a team October 10, 2025 21:50
@Josh-Cena
Copy link
Member

We still need to link to it from many places, and possibly there are a lot of places that talk about value serialization (especially colors) that can be deduplicated. I will wait for @estelle.

Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add the serialization format to all the data type pages in the future.

@Shrinivassab Shrinivassab requested review from a team as code owners November 6, 2025 04:32
@Shrinivassab Shrinivassab requested review from sideshowbarker and removed request for a team November 6, 2025 04:32
@sideshowbarker sideshowbarker removed their request for review November 6, 2025 16:56
@Josh-Cena Josh-Cena force-pushed the css-value-serialization branch from 3dc8b26 to fb9973c Compare November 10, 2025 18:57
@Josh-Cena
Copy link
Member

The more I read into the specs and do tests, the more I believe that serialization is a hot mess and no one knows exactly how it works. I think just covering the basic data types is the most we can do, and even then I'm unsure because obviously the CSSStyleSheet does not use the computed value but it's not the declared value either (because color values are resolved).

Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@estelle PTAL, thanks

Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. Thank you. I just made a few grammar and linking suggestions. I also submitted a PR directly to your PR to add links to your guide from related CSS module landing pages. See Shrinivassab#1

- {{domxref("CSSStyleDeclaration.cssText")}}
- Accessing properties directly on {{domxref("CSSStyleDeclaration")}} objects (e.g., `element.style.backgroundColor`)

Different APIs return `CSSStyleDeclaration` objects at different stages of [value processing](/en-US/docs/Web/CSS/Guides/Cascade/Property_value_processing), which have slightly different serialization behaviors. For example, {{domxref("Window.getComputedStyle()")}} and {{domxref("HTMLElement.style")}} returns the [resolved value](/en-US/docs/Web/CSS/Guides/Cascade/Property_value_processing#resolved_value) of properties, while {{domxref("CSSStyleRule.style")}} returns _more or less_ the [declared value](/en-US/docs/Web/CSS/Guides/Cascade/Property_value_processing#declared_value).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Different APIs return `CSSStyleDeclaration` objects at different stages of [value processing](/en-US/docs/Web/CSS/Guides/Cascade/Property_value_processing), which have slightly different serialization behaviors. For example, {{domxref("Window.getComputedStyle()")}} and {{domxref("HTMLElement.style")}} returns the [resolved value](/en-US/docs/Web/CSS/Guides/Cascade/Property_value_processing#resolved_value) of properties, while {{domxref("CSSStyleRule.style")}} returns _more or less_ the [declared value](/en-US/docs/Web/CSS/Guides/Cascade/Property_value_processing#declared_value).
Different APIs return `CSSStyleDeclaration` objects at different stages of [value processing](/en-US/docs/Web/CSS/Guides/Cascade/Property_value_processing), which have slightly different serialization behaviors. For example, {{domxref("Window.getComputedStyle()")}} and {{domxref("HTMLElement.style")}} returns the [resolved value](/en-US/docs/Web/CSS/Guides/Cascade/Property_value_processing#resolved_value) of properties, while {{domxref("CSSStyleRule.style")}} return _more or less_ the [declared value](/en-US/docs/Web/CSS/Guides/Cascade/Property_value_processing#declared_value).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The subject is CSSStyleRule.style which is singular?

@Josh-Cena Josh-Cena requested a review from a team as a code owner November 17, 2025 17:47
@Josh-Cena Josh-Cena requested review from dipikabh and removed request for a team November 17, 2025 17:47
@github-actions github-actions bot added the Content:CSS Cascading Style Sheets docs label Nov 17, 2025
Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 🎉

@estelle estelle merged commit fdd310a into mdn:main Nov 17, 2025
9 checks passed
estelle added a commit that referenced this pull request Nov 18, 2025
…41322)

* docs: Add reference for CSS value serialization, especially colors

Fixes #32734

Adds a new guide explaining how CSS values especially colors are serialized when accessed via JavaScript APIs like getComputedStyle() and getPropertyValue().

* Update files/en-us/web/api/css_object_model/serializing_css_values/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Addressed PR comments

* Rewrite

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Rewrite

* Apply suggestions from code review

Co-authored-by: Estelle Weyl <[email protected]>

* Add guide links

---------

Co-authored-by: Joshua Chen <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
estelle added a commit that referenced this pull request Nov 18, 2025
…41322)

* docs: Add reference for CSS value serialization, especially colors

Fixes #32734

Adds a new guide explaining how CSS values especially colors are serialized when accessed via JavaScript APIs like getComputedStyle() and getPropertyValue().

* Update files/en-us/web/api/css_object_model/serializing_css_values/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Addressed PR comments

* Rewrite

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Rewrite

* Apply suggestions from code review

Co-authored-by: Estelle Weyl <[email protected]>

* Add guide links

---------

Co-authored-by: Joshua Chen <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
estelle added a commit that referenced this pull request Nov 18, 2025
…41322)

* docs: Add reference for CSS value serialization, especially colors

Fixes #32734

Adds a new guide explaining how CSS values especially colors are serialized when accessed via JavaScript APIs like getComputedStyle() and getPropertyValue().

* Update files/en-us/web/api/css_object_model/serializing_css_values/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Addressed PR comments

* Rewrite

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Rewrite

* Apply suggestions from code review

Co-authored-by: Estelle Weyl <[email protected]>

* Add guide links

---------

Co-authored-by: Joshua Chen <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
estelle added a commit that referenced this pull request Nov 18, 2025
…41322)

* docs: Add reference for CSS value serialization, especially colors

Fixes #32734

Adds a new guide explaining how CSS values especially colors are serialized when accessed via JavaScript APIs like getComputedStyle() and getPropertyValue().

* Update files/en-us/web/api/css_object_model/serializing_css_values/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Addressed PR comments

* Rewrite

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Rewrite

* Apply suggestions from code review

Co-authored-by: Estelle Weyl <[email protected]>

* Add guide links

---------

Co-authored-by: Joshua Chen <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
estelle added a commit that referenced this pull request Nov 18, 2025
…41322)

* docs: Add reference for CSS value serialization, especially colors

Fixes #32734

Adds a new guide explaining how CSS values especially colors are serialized when accessed via JavaScript APIs like getComputedStyle() and getPropertyValue().

* Update files/en-us/web/api/css_object_model/serializing_css_values/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Addressed PR comments

* Rewrite

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Rewrite

* Apply suggestions from code review

Co-authored-by: Estelle Weyl <[email protected]>

* Add guide links

---------

Co-authored-by: Joshua Chen <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
estelle added a commit that referenced this pull request Nov 18, 2025
…41322)

* docs: Add reference for CSS value serialization, especially colors

Fixes #32734

Adds a new guide explaining how CSS values especially colors are serialized when accessed via JavaScript APIs like getComputedStyle() and getPropertyValue().

* Update files/en-us/web/api/css_object_model/serializing_css_values/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Addressed PR comments

* Rewrite

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Rewrite

* Apply suggestions from code review

Co-authored-by: Estelle Weyl <[email protected]>

* Add guide links

---------

Co-authored-by: Joshua Chen <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
estelle added a commit that referenced this pull request Nov 18, 2025
…41322)

* docs: Add reference for CSS value serialization, especially colors

Fixes #32734

Adds a new guide explaining how CSS values especially colors are serialized when accessed via JavaScript APIs like getComputedStyle() and getPropertyValue().

* Update files/en-us/web/api/css_object_model/serializing_css_values/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Addressed PR comments

* Rewrite

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Rewrite

* Apply suggestions from code review

Co-authored-by: Estelle Weyl <[email protected]>

* Add guide links

---------

Co-authored-by: Joshua Chen <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
estelle added a commit that referenced this pull request Nov 18, 2025
…41322)

* docs: Add reference for CSS value serialization, especially colors

Fixes #32734

Adds a new guide explaining how CSS values especially colors are serialized when accessed via JavaScript APIs like getComputedStyle() and getPropertyValue().

* Update files/en-us/web/api/css_object_model/serializing_css_values/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Addressed PR comments

* Rewrite

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Rewrite

* Apply suggestions from code review

Co-authored-by: Estelle Weyl <[email protected]>

* Add guide links

---------

Co-authored-by: Joshua Chen <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
estelle added a commit that referenced this pull request Nov 18, 2025
…41322)

* docs: Add reference for CSS value serialization, especially colors

Fixes #32734

Adds a new guide explaining how CSS values especially colors are serialized when accessed via JavaScript APIs like getComputedStyle() and getPropertyValue().

* Update files/en-us/web/api/css_object_model/serializing_css_values/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Addressed PR comments

* Rewrite

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Update files/en-us/web/api/css_object_model/css_value_serialization/index.md

Co-authored-by: Estelle Weyl <[email protected]>

* Rewrite

* Apply suggestions from code review

Co-authored-by: Estelle Weyl <[email protected]>

* Add guide links

---------

Co-authored-by: Joshua Chen <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:CSS Cascading Style Sheets docs Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reference for CSS value serialization, especially as it relates to colors

3 participants