Skip to content
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

New color guides and some associated link updates #33071

Merged
merged 56 commits into from Apr 25, 2024
Merged

Conversation

estelle
Copy link
Member

@estelle estelle commented Apr 13, 2024

Four guides on CSS colors:

  • Applying color to HTML elements using CSS - This guide was rewritten and is now only about CSS properties that support <color> values. It's a guide to using CSS to apply color to a variety of types of content, including all CSS properties that accept <color> as a value.
  • CSS color values - New guide containing the removed content that was in applying color (above) . This content was completely rewritten and reordered
  • Using color wisely Content based on a section removed from the original very large applying color page. This content is mostly the same as what was removed from applying color, but with updates.
  • Color converter tool: A simplified tool that is much more intuitive. Adds HWB as a function. update content for accuracy and expanded color options. (The color() function will show in the tool when add color() function to color tool css-examples#176 is merged. it's not there at the moment).

(* these are the links to the previews of the main pages that have really changed / are new. Also, see the module landing page. All other files have minor edits, mostly "applying color" link removals. Hopefully, this section may be helpful once those link pages have passed muster as we go through rounds of reviews ;) )

This PR only includes updated links to "applying color", removing the link from CSS properties in which our readers, if they are using those properties, already know how to apply CSS to elements.

There will be a separate PR to add links to the three other guides. This PR is already big enough.

Fixes openwebdocs/project#194
Sidebar additions: mdn/yari#10945
Tool update: mdn/css-examples#176

…first day you learn CSS

I didn't remove the link from more basic properties, like color.
reordered stuff not fully relevant to the page and safari issue
@estelle estelle requested review from a team as code owners April 13, 2024 08:15
@estelle estelle requested review from dipikabh and removed request for a team April 13, 2024 08:15
@github-actions github-actions bot added Content:CSS Cascading Style Sheets docs Content:HTML Hypertext Markup Language docs size/xl >1000 LoC changed labels Apr 13, 2024
Copy link
Contributor

github-actions bot commented Apr 13, 2024

Preview URLs (24 pages)
External URLs (24)

URL: /en-US/docs/Web/CSS/background-color
Title: background-color


URL: /en-US/docs/Web/CSS/text-decoration-color
Title: text-decoration-color


URL: /en-US/docs/Web/CSS/CSS_colors/Color_values
Title: CSS color values


URL: /en-US/docs/Web/CSS/CSS_colors/Using_color_wisely
Title: Using color wisely


URL: /en-US/docs/Web/CSS/outline-color
Title: outline-color


URL: /en-US/docs/Web/CSS/forced-color-adjust
Title: forced-color-adjust

(comment last updated: 2024-04-25 17:39:37)

@estelle estelle marked this pull request as draft April 13, 2024 08:17
@estelle estelle changed the title Draft: new color guide and associated link updates New color guides and some associated link updates Apr 17, 2024
@estelle estelle marked this pull request as ready for review April 17, 2024 05:35
Copy link
Contributor

@chrisdavidmills chrisdavidmills left a comment

Choose a reason for hiding this comment

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

Wonderful work @estelle!

I've had a good look through your edits, and it is looking pretty much ready to go, IMO.

I've made a few more minor comments for you to look through, but I'm now setting this to approved, so you can get on and merge when done.


> **Note:** There is no guarantee, though, that `print-color-adjust: exact` will result in your CSS being used exactly as given.
> If the browser provides user preferences to change the output (such as a "don't print backgrounds" checkbox in a print dialog box), that overrides the value of `print-color-adjust`.
> **Note:** A few now obsolete HTML attributes accepted colors as values, such as `bgcolor` and `vlink`. These attribute only accepted {{cssxref("named-color")}} and three or six digit {{cssxref("hex-color")}} values.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
> **Note:** A few now obsolete HTML attributes accepted colors as values, such as `bgcolor` and `vlink`. These attribute only accepted {{cssxref("named-color")}} and three or six digit {{cssxref("hex-color")}} values.
> **Note:** A few now-obsolete HTML attributes accepted colors as values, such as `bgcolor` and `vlink`. These attributes only accepted {{cssxref("named-color")}} and three- or six-digit {{cssxref("hex-color")}} values.


The use of color is a fundamental form of human expression. Children experiment with color before they even have the manual dexterity to draw. Maybe that's why color is one of the first things people often want to experiment with when learning to develop websites. With [CSS](/en-US/docs/Web/CSS), there are lots of ways to add color to your [HTML](/en-US/docs/Web/HTML) [elements](/en-US/docs/Web/HTML/Element) to create just the look you want.
> **Note:** It is important to [use colors wisely](/en-US/docs/Web/CSS/CSS_colors/Using_color_wisely). Always select appropriate colors, ensure there is enough contrast between text and the background to ensure legibility, and always keep the needs of people with differing visual capabilities in mind.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
> **Note:** It is important to [use colors wisely](/en-US/docs/Web/CSS/CSS_colors/Using_color_wisely). Always select appropriate colors, ensure there is enough contrast between text and the background to ensure legibility, and always keep the needs of people with differing visual capabilities in mind.
> **Note:** It is important to [use colors wisely](/en-US/docs/Web/CSS/CSS_colors/Using_color_wisely). Always select appropriate colors, ensure the contrast between text and backgrounds is sufficient to ensure legibility, and always keep the needs of people with differing visual capabilities in mind.

Copy link
Member Author

Choose a reason for hiding this comment

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

went with:

ensuring the contrast between text and the background is sufficient


## See also

- [`<color>`](/en-US/docs/Web/CSS/color_value) data type
- [CSS color values](/en-US/docs/Web/CSS/CSS_colors/Color_values) guide
- [Using colors wisely](/en-US/docs/Web/CSS/CSS_colors/Using_color_wisely)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- [Using colors wisely](/en-US/docs/Web/CSS/CSS_colors/Using_color_wisely)
- [Using color wisely](/en-US/docs/Web/CSS/CSS_colors/Using_color_wisely)

@@ -6,31 +6,27 @@ page-type: guide

{{CSSRef}}

This tool makes it easy to create, adjust, and experiment with custom colors for the web. It also makes it easy to convert between various [color formats](/en-US/docs/Web/CSS/color_value) supported by [CSS](/en-US/docs/Web/CSS), including: HEXA colors, RGB (Red/Green/Blue) and HSL (Hue/Saturation/Lightness). Control over the alpha channel is also supported.
This tool lets you pick a color in the sRGB {{glossary("color space")}} and converts it between various CSS [color formats](/en-US/docs/Web/CSS/color_value), helping you understand the syntax of sRGB color notations, including:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This tool lets you pick a color in the sRGB {{glossary("color space")}} and converts it between various CSS [color formats](/en-US/docs/Web/CSS/color_value), helping you understand the syntax of sRGB color notations, including:
This tool lets you pick a color in the sRGB {{glossary("color space")}} and converts it between various CSS [color formats](/en-US/docs/Web/CSS/color_value), helping you understand the syntax of the following sRGB color notations:


Color keywords include standard primary and secondary colors (such as `red`, `blue`, or `orange`), shades of gray (from `black` to `white`, including colors like `darkgray` and `lightgrey`), and a variety of other blended colors, including `lightseagreen`, `cornflowerblue`, and `rebeccapurple`. Named colors use the [RGB](/en-US/docs/Glossary/RGB) model and are associated with the sRGB (`srgb`) color space.

There are over 160 named colors. There are named colors of special interest: [`transparent`](/en-US/docs/Web/CSS/named-color#transparent) sets a transparent color value, while [`currentcolor`](/en-US/docs/Web/CSS/color_value#currentcolor_keyword) sets the current value of the CSS {{cssxref("color")}} property. There are also named {{cssxref("system-colors")}}, such as `accentcolortext` and `buttonface`, that reflect the default color choices made by the user, the browser, or the operating system.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
There are over 160 named colors. There are named colors of special interest: [`transparent`](/en-US/docs/Web/CSS/named-color#transparent) sets a transparent color value, while [`currentcolor`](/en-US/docs/Web/CSS/color_value#currentcolor_keyword) sets the current value of the CSS {{cssxref("color")}} property. There are also named {{cssxref("system-colors")}}, such as `accentcolortext` and `buttonface`, that reflect the default color choices made by the user, the browser, or the operating system.
There are over 160 named colors. There are named colors of special interest: [`transparent`](/en-US/docs/Web/CSS/named-color#transparent) sets a transparent color value, while [`currentcolor`](/en-US/docs/Web/CSS/color_value#currentcolor_keyword) sets the current value of the CSS {{cssxref("color")}} property. There are also named {{cssxref("system-color")}}s, such as `accentcolortext` and `buttonface`, that reflect the default color choices made by the user, the browser, or the operating system.

Copy link
Contributor

Choose a reason for hiding this comment

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

(or just turn it into a regular link, either way the link would be fixed)

Copy link
Member Author

Choose a reason for hiding this comment

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

There are also named {{cssxref("system-color")}} colors, such as ...

<td style="background-color: hsl(0.15turn 90% 50%);">&nbsp;</td>
</tr>
<tr>
<td><code>hsl(270deg 90% 50%)</code></td>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<td><code>hsl(270deg 90% 50%)</code></td>
<td><code>hsl(270deg 90% 50% / 50%)</code></td>

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch!


Similar to `lch()` and `oklch()`, the `lightness` is either a {{cssxref("percentage")}} or for `lab()` a number between `0` and `100` and for `oklab()` a number between `0` and `1`, with `0` or `0%` being the complete lack of lightness, which is black.

The `a` value is `<number>` between `-125` and `125` for `lab()` or `-0.4` and `0.4` for `oklab()`, a `<percentage>` between `-100%` and `100%`, or the keyword `none` (equivalent to `0%` in this case). This value specifies the color's distance along the a-axis in the color space, which defines how green (moving towards -100%) or red (moving towards +100%) the color is. Note that these values are signed (allowing both positive and negative values) and theoretically unbounded, meaning that you can set values outside the ±125 or ±0.4 (±100%) limits. In practice, values cannot exceed ±160 or ±0.5, respectively.
Copy link
Contributor

Choose a reason for hiding this comment

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

LOL, I'll redo that one in a different comment. I think I forgot to add it ;-)

- A {{cssxref("percentage")}}, with `0%` being completely black and `100%` being completely white.
- A number between `0` and `100` for `lab()` and `0` and `1` for `oklab()`, where `0` is completely black and`1`/`100` is completely white.

The `a` value is `<number>` between `-125` and `125` for `lab()` or `-0.4` and `0.4` for `oklab()`, a `<percentage>` between `-100%` and `100%`, or the keyword `none` (equivalent to `0%` in this case). This value specifies the color's distance along the a-axis in the color space, which defines how green (moving towards -100%) or red (moving towards +100%) the color is. Note that these values are signed (allowing both positive and negative values) and theoretically unbounded, meaning that you can set values outside the ±125 or ±0.4 (±100%) limits. In practice, values cannot exceed ±160 or ±0.5, respectively.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The `a` value is `<number>` between `-125` and `125` for `lab()` or `-0.4` and `0.4` for `oklab()`, a `<percentage>` between `-100%` and `100%`, or the keyword `none` (equivalent to `0%` in this case). This value specifies the color's distance along the a-axis in the color space, which defines how green (moving towards -100%) or red (moving towards +100%) the color is. Note that these values are signed (allowing both positive and negative values) and theoretically unbounded, meaning that you can set values outside the ±125 or ±0.4 (±100%) limits. In practice, values cannot exceed ±160 or ±0.5, respectively.
The `a` value is a `<number>` between `-125` and `125` for `lab()` or `-0.4` and `0.4` for `oklab()`, a `<percentage>` between `-100%` and `100%`, or the keyword `none` (equivalent to `0%` in this case). This value specifies the color's distance along the a-axis in the color space, which defines how green (moving towards -100%) or red (moving towards +100%) the color is.
Note that these values are signed (allowing both positive and negative values) and theoretically unbounded, meaning that you can set values outside the ±125 or ±0.4 (±100%) limits. In practice, values cannot exceed ±160 or ±0.5, respectively.

}
```

In addition, as the older sRGB color notations discussed above - `hsl()`, `hwb()`, and `rgb()` - do not express the full spectrum of visible colors and the `color()` function supports a much wider color gamut, when using these functions to define relative colors (discussed next), the output color returned by querying {{domxref("HTMLElement.style")}} property or the {{domxref("CSSStyleDeclaration.getPropertyValue()")}} method will be a `color(srgb ...)` value. To see an example of converting these color functions to `color()` in the `srgb` color space, check out our [color picker tool](/en-US/docs/Web/CSS/CSS_colors/Color_picker_tool).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
In addition, as the older sRGB color notations discussed above - `hsl()`, `hwb()`, and `rgb()` - do not express the full spectrum of visible colors and the `color()` function supports a much wider color gamut, when using these functions to define relative colors (discussed next), the output color returned by querying {{domxref("HTMLElement.style")}} property or the {{domxref("CSSStyleDeclaration.getPropertyValue()")}} method will be a `color(srgb ...)` value. To see an example of converting these color functions to `color()` in the `srgb` color space, check out our [color picker tool](/en-US/docs/Web/CSS/CSS_colors/Color_picker_tool).
The older sRGB color notations discussed above `hsl()`, `hwb()`, and `rgb()`do not express the full spectrum of visible colors, while the `color()` function supports a much wider color gamut. As a result, when using the older functions types to define relative colors (discussed next), the output color returned by querying {{domxref("HTMLElement.style")}} property or the {{domxref("CSSStyleDeclaration.getPropertyValue()")}} method will be a `color(srgb ...)` value. To see an example of converting these color functions to `color()` in the `srgb` color space, check out our [color picker tool](/en-US/docs/Web/CSS/CSS_colors/Color_picker_tool).

Copy link
Contributor

Choose a reason for hiding this comment

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

I also think you should remove this paragraph from here, put it in place of the related paragraph in the next section, and remove the "(discussed next)" bit. It seems weird that the detail is here and not in the relative colors section.

Yes, this section uses color(), but this detail is not essential for an understanding of the example.

Copy link
Member Author

@estelle estelle Apr 25, 2024

Choose a reason for hiding this comment

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

changed to:

Understanding color() is important when it comes to relative colors, discussed next. The older sRGB color notations discussed above — hsl(), hwb(), and rgb()— do not express the full spectrum of visible colors, while the color() function supports a much wider color gamut. As a result, when using the older functions types to define relative colors, the output color returned by querying {{domxref("HTMLElement.style")}} property or the {{domxref("CSSStyleDeclaration.getPropertyValue()")}} method will be a color(srgb ...) value.

To see an example of converting the hsl(), hwb(), and rgb() color functions to color() in the srgb color space, check out our color picker tool.

to make it more relevant here (i want to add it to color() instead of relative because i want to express why learning color is actually important.


It's important to [understand color and luminance](/en-US/docs/Web/Accessibility/Understanding_Colors_and_Luminance) and to always consider [color blindness](https://medlineplus.gov/colorblindness.html) and [vestibular disorders](/en-US/docs/Web/Accessibility/Seizure_disorders). There are several kinds; the most common is red-green color blindness, which causes people to be unable to differentiate between the colors red and green. There are others, too, ranging from an inability to tell the difference between certain colors to the total inability to see color at all. There are even color and animation combinations that can lead your photosensitive users to experience [seizures](/en-US/docs/Web/Accessibility/Seizure_disorders#colors).

While higher [color contrast](https://digital.gov/guides/accessibility-for-teams/visual-design/#color-and-contrast) is often a good thing when it comes to accessibility, when animating, especially rapidly, [reducing color contrast](/en-US/docs/Web/Accessibility/Seizure_disorders#reduce_contrast) on animating elements reduces seizure risk. If you include animations, use the [`prefers-reduced-motion`](/en-US/docs/Web/CSS/@media/prefers-reduced-motion) feature of the {{cssxref("@media")}} query to reduce animations for users who have selected that preference.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
While higher [color contrast](https://digital.gov/guides/accessibility-for-teams/visual-design/#color-and-contrast) is often a good thing when it comes to accessibility, when animating, especially rapidly, [reducing color contrast](/en-US/docs/Web/Accessibility/Seizure_disorders#reduce_contrast) on animating elements reduces seizure risk. If you include animations, use the [`prefers-reduced-motion`](/en-US/docs/Web/CSS/@media/prefers-reduced-motion) feature of the {{cssxref("@media")}} query to reduce animations for users who have selected that preference.
While higher [color contrast](https://digital.gov/guides/accessibility-for-teams/visual-design/#color-and-contrast) is often a good thing when it comes to accessibility, when animating, especially rapidly, [reducing color contrast](/en-US/docs/Web/Accessibility/Seizure_disorders#reduce_contrast) on animating elements reduces seizure risk. If you include animations, use the [`prefers-reduced-motion`](/en-US/docs/Web/CSS/@media/prefers-reduced-motion) {{cssxref("@media")}} query feature to reduce animations for users who have selected that preference.

@estelle estelle merged commit 5f13cbe into mdn:main Apr 25, 2024
8 checks passed
@estelle estelle deleted the colorguides branch April 25, 2024 17:43
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:HTML Hypertext Markup Language docs size/xl >1000 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Color Spaces and Functions
3 participants