CSS • Chapter 20 • Foundations to Production
CSS Colors
Every topic includes a CSS/HTML coding example, ten focused teaching examples, code explanation, expected result, practice, and responsive/translated-layout checks.
20.1 Hex Colors
Hex Colors is part of the CSS system covered in Chapter 20. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size. The goal is to connect the syntax to the browser's layout and cascade decisions rather than memorize a property name.
For Hex Colors in Chapter 20, inspect the matched selector, computed value, containing block or formatting context, intrinsic size, and any min/max constraints. When translation is enabled, also inspect whether longer text or RTL direction changes the available inline space.
Start with one small example for Hex Colors, resize the viewport, increase text size, translate the label, and add a competing rule. This shows whether the technique remains predictable under real content rather than only in a fixed desktop mockup. This explanation is specific to Chapter 20, topic 1.
Concept in plain language
Hex Colors is part of the CSS system covered in Chapter 20. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size.
10 teaching examples
Example 1: Smallest useful case
Build a minimal lesson sidebar for Hex Colors. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 20, topic 1, example 1.
Example 2: Change one value
Change one important CSS value in the contact form example for Hex Colors. Predict the visual difference before reloading the page. Chapter 20, topic 1, example 2.
Example 3: Narrow-screen test
Test Hex Colors in the button group at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 20, topic 1, example 3.
Example 4: Translated-text test
Translate the data table into a language with longer labels while using Hex Colors. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 20, topic 1, example 4.
Example 5: Arabic/Persian test
Switch the media player to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 20, topic 1, example 5.
Example 6: Accessibility test
Check Hex Colors in the notification with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 20, topic 1, example 6.
Example 7: Cascade test
Add a competing rule to the language selector and determine why the declaration for Hex Colors wins or loses using the browser's Styles and Computed panels. Chapter 20, topic 1, example 7.
Example 8: Content-stress test
Fill the course card with very long words, URLs, translated text, images, and nested controls. Adjust Hex Colors without hiding meaningful content. Chapter 20, topic 1, example 8.
Example 9: Refactoring test
Rewrite the navigation bar so Hex Colors uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 20, topic 1, example 9.
Example 10: Production review
Review Hex Colors in the article for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 20, topic 1, example 10.
CSS/HTML coding example
<!-- HTML -->
<div class="swatch">Color sample</div>
<style>
.swatch { background: #6d28d9; color:white; padding:1rem; }
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate Hex Colors.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The color notation demonstrates Hex Colors.
- Resize the viewport and test long translated content. Confirm that flex/grid items use min-width:0 where needed and that only code or genuinely wide content scrolls locally.
- Switch to Arabic or Persian and verify logical start/end spacing, text alignment, sidebar direction, and LTR isolation for code.
Expected result: The browser visibly demonstrates Hex Colors without requiring the page to exceed the viewport width. If the example contains wide code, only the code block scrolls horizontally. This expected result belongs to Chapter 20, topic 1.
Practice exercise
Build a fresh example for Hex Colors from Chapter 20. Change one value, inspect the computed styles, test at 320px and tablet width, translate the visible text, switch the page to RTL, and explain why the final declaration or layout behavior occurs.
20.2 rgb
rgb is part of the CSS system covered in Chapter 20. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size. The goal is to connect the syntax to the browser's layout and cascade decisions rather than memorize a property name.
For rgb in Chapter 20, inspect the matched selector, computed value, containing block or formatting context, intrinsic size, and any min/max constraints. When translation is enabled, also inspect whether longer text or RTL direction changes the available inline space.
Start with one small example for rgb, resize the viewport, increase text size, translate the label, and add a competing rule. This shows whether the technique remains predictable under real content rather than only in a fixed desktop mockup. This explanation is specific to Chapter 20, topic 2.
Concept in plain language
rgb is part of the CSS system covered in Chapter 20. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size.
10 teaching examples
Example 1: Smallest useful case
Build a minimal data table for rgb. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 20, topic 2, example 1.
Example 2: Change one value
Change one important CSS value in the media player example for rgb. Predict the visual difference before reloading the page. Chapter 20, topic 2, example 2.
Example 3: Narrow-screen test
Test rgb in the notification at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 20, topic 2, example 3.
Example 4: Translated-text test
Translate the language selector into a language with longer labels while using rgb. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 20, topic 2, example 4.
Example 5: Arabic/Persian test
Switch the course card to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 20, topic 2, example 5.
Example 6: Accessibility test
Check rgb in the navigation bar with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 20, topic 2, example 6.
Example 7: Cascade test
Add a competing rule to the article and determine why the declaration for rgb wins or loses using the browser's Styles and Computed panels. Chapter 20, topic 2, example 7.
Example 8: Content-stress test
Fill the profile panel with very long words, URLs, translated text, images, and nested controls. Adjust rgb without hiding meaningful content. Chapter 20, topic 2, example 8.
Example 9: Refactoring test
Rewrite the search form so rgb uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 20, topic 2, example 9.
Example 10: Production review
Review rgb in the dashboard for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 20, topic 2, example 10.
CSS/HTML coding example
<!-- HTML -->
<div class="swatch">Color sample</div>
<style>
.swatch { background: rgb(109 40 217); color:white; padding:1rem; }
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate rgb.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The color notation demonstrates rgb.
- Resize the viewport and test long translated content. Confirm that flex/grid items use min-width:0 where needed and that only code or genuinely wide content scrolls locally.
- Switch to Arabic or Persian and verify logical start/end spacing, text alignment, sidebar direction, and LTR isolation for code.
Expected result: The browser visibly demonstrates rgb without requiring the page to exceed the viewport width. If the example contains wide code, only the code block scrolls horizontally. This expected result belongs to Chapter 20, topic 2.
Practice exercise
Build a fresh example for rgb from Chapter 20. Change one value, inspect the computed styles, test at 320px and tablet width, translate the visible text, switch the page to RTL, and explain why the final declaration or layout behavior occurs.
20.3 hsl
hsl is part of the CSS system covered in Chapter 20. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size. The goal is to connect the syntax to the browser's layout and cascade decisions rather than memorize a property name.
For hsl in Chapter 20, inspect the matched selector, computed value, containing block or formatting context, intrinsic size, and any min/max constraints. When translation is enabled, also inspect whether longer text or RTL direction changes the available inline space.
Start with one small example for hsl, resize the viewport, increase text size, translate the label, and add a competing rule. This shows whether the technique remains predictable under real content rather than only in a fixed desktop mockup. This explanation is specific to Chapter 20, topic 3.
Concept in plain language
hsl is part of the CSS system covered in Chapter 20. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size.
10 teaching examples
Example 1: Smallest useful case
Build a minimal language selector for hsl. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 20, topic 3, example 1.
Example 2: Change one value
Change one important CSS value in the course card example for hsl. Predict the visual difference before reloading the page. Chapter 20, topic 3, example 2.
Example 3: Narrow-screen test
Test hsl in the navigation bar at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 20, topic 3, example 3.
Example 4: Translated-text test
Translate the article into a language with longer labels while using hsl. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 20, topic 3, example 4.
Example 5: Arabic/Persian test
Switch the profile panel to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 20, topic 3, example 5.
Example 6: Accessibility test
Check hsl in the search form with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 20, topic 3, example 6.
Example 7: Cascade test
Add a competing rule to the dashboard and determine why the declaration for hsl wins or loses using the browser's Styles and Computed panels. Chapter 20, topic 3, example 7.
Example 8: Content-stress test
Fill the photo gallery with very long words, URLs, translated text, images, and nested controls. Adjust hsl without hiding meaningful content. Chapter 20, topic 3, example 8.
Example 9: Refactoring test
Rewrite the pricing table so hsl uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 20, topic 3, example 9.
Example 10: Production review
Review hsl in the lesson sidebar for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 20, topic 3, example 10.
CSS/HTML coding example
<!-- HTML -->
<div class="swatch">Color sample</div>
<style>
.swatch { background: hsl(262 83% 58%); color:white; padding:1rem; }
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate hsl.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The color notation demonstrates hsl.
- Resize the viewport and test long translated content. Confirm that flex/grid items use min-width:0 where needed and that only code or genuinely wide content scrolls locally.
- Switch to Arabic or Persian and verify logical start/end spacing, text alignment, sidebar direction, and LTR isolation for code.
Expected result: The browser visibly demonstrates hsl without requiring the page to exceed the viewport width. If the example contains wide code, only the code block scrolls horizontally. This expected result belongs to Chapter 20, topic 3.
Practice exercise
Build a fresh example for hsl from Chapter 20. Change one value, inspect the computed styles, test at 320px and tablet width, translate the visible text, switch the page to RTL, and explain why the final declaration or layout behavior occurs.
20.4 lab and lch
lab and lch is part of the CSS system covered in Chapter 20. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size. The goal is to connect the syntax to the browser's layout and cascade decisions rather than memorize a property name.
For lab and lch in Chapter 20, inspect the matched selector, computed value, containing block or formatting context, intrinsic size, and any min/max constraints. When translation is enabled, also inspect whether longer text or RTL direction changes the available inline space.
Start with one small example for lab and lch, resize the viewport, increase text size, translate the label, and add a competing rule. This shows whether the technique remains predictable under real content rather than only in a fixed desktop mockup. This explanation is specific to Chapter 20, topic 4.
Concept in plain language
lab and lch is part of the CSS system covered in Chapter 20. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size.
10 teaching examples
Example 1: Smallest useful case
Build a minimal article for lab and lch. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 20, topic 4, example 1.
Example 2: Change one value
Change one important CSS value in the profile panel example for lab and lch. Predict the visual difference before reloading the page. Chapter 20, topic 4, example 2.
Example 3: Narrow-screen test
Test lab and lch in the search form at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 20, topic 4, example 3.
Example 4: Translated-text test
Translate the dashboard into a language with longer labels while using lab and lch. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 20, topic 4, example 4.
Example 5: Arabic/Persian test
Switch the photo gallery to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 20, topic 4, example 5.
Example 6: Accessibility test
Check lab and lch in the pricing table with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 20, topic 4, example 6.
Example 7: Cascade test
Add a competing rule to the lesson sidebar and determine why the declaration for lab and lch wins or loses using the browser's Styles and Computed panels. Chapter 20, topic 4, example 7.
Example 8: Content-stress test
Fill the contact form with very long words, URLs, translated text, images, and nested controls. Adjust lab and lch without hiding meaningful content. Chapter 20, topic 4, example 8.
Example 9: Refactoring test
Rewrite the button group so lab and lch uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 20, topic 4, example 9.
Example 10: Production review
Review lab and lch in the data table for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 20, topic 4, example 10.
CSS/HTML coding example
<!-- HTML -->
<div class="swatch">Color sample</div>
<style>
.swatch { background: lch(55% 70 300); color:white; padding:1rem; }
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate lab and lch.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The color notation demonstrates lab and lch.
- Resize the viewport and test long translated content. Confirm that flex/grid items use min-width:0 where needed and that only code or genuinely wide content scrolls locally.
- Switch to Arabic or Persian and verify logical start/end spacing, text alignment, sidebar direction, and LTR isolation for code.
Expected result: The browser visibly demonstrates lab and lch without requiring the page to exceed the viewport width. If the example contains wide code, only the code block scrolls horizontally. This expected result belongs to Chapter 20, topic 4.
Practice exercise
Build a fresh example for lab and lch from Chapter 20. Change one value, inspect the computed styles, test at 320px and tablet width, translate the visible text, switch the page to RTL, and explain why the final declaration or layout behavior occurs.
20.5 oklab and oklch
oklab and oklch is part of the CSS system covered in Chapter 20. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size. The goal is to connect the syntax to the browser's layout and cascade decisions rather than memorize a property name.
For oklab and oklch in Chapter 20, inspect the matched selector, computed value, containing block or formatting context, intrinsic size, and any min/max constraints. When translation is enabled, also inspect whether longer text or RTL direction changes the available inline space.
Start with one small example for oklab and oklch, resize the viewport, increase text size, translate the label, and add a competing rule. This shows whether the technique remains predictable under real content rather than only in a fixed desktop mockup. This explanation is specific to Chapter 20, topic 5.
Concept in plain language
oklab and oklch is part of the CSS system covered in Chapter 20. The key is to understand what box, selector, cascade rule, layout algorithm, or user preference the declaration affects, then test the result at more than one viewport size.
10 teaching examples
Example 1: Smallest useful case
Build a minimal dashboard for oklab and oklch. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 20, topic 5, example 1.
Example 2: Change one value
Change one important CSS value in the photo gallery example for oklab and oklch. Predict the visual difference before reloading the page. Chapter 20, topic 5, example 2.
Example 3: Narrow-screen test
Test oklab and oklch in the pricing table at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 20, topic 5, example 3.
Example 4: Translated-text test
Translate the lesson sidebar into a language with longer labels while using oklab and oklch. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 20, topic 5, example 4.
Example 5: Arabic/Persian test
Switch the contact form to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 20, topic 5, example 5.
Example 6: Accessibility test
Check oklab and oklch in the button group with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 20, topic 5, example 6.
Example 7: Cascade test
Add a competing rule to the data table and determine why the declaration for oklab and oklch wins or loses using the browser's Styles and Computed panels. Chapter 20, topic 5, example 7.
Example 8: Content-stress test
Fill the media player with very long words, URLs, translated text, images, and nested controls. Adjust oklab and oklch without hiding meaningful content. Chapter 20, topic 5, example 8.
Example 9: Refactoring test
Rewrite the notification so oklab and oklch uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 20, topic 5, example 9.
Example 10: Production review
Review oklab and oklch in the language selector for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 20, topic 5, example 10.
CSS/HTML coding example
<!-- HTML -->
<div class="swatch">Color sample</div>
<style>
.swatch { background: oklch(58% .22 295); color:white; padding:1rem; }
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate oklab and oklch.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The color notation demonstrates oklab and oklch.
- Resize the viewport and test long translated content. Confirm that flex/grid items use min-width:0 where needed and that only code or genuinely wide content scrolls locally.
- Switch to Arabic or Persian and verify logical start/end spacing, text alignment, sidebar direction, and LTR isolation for code.
Expected result: The browser visibly demonstrates oklab and oklch without requiring the page to exceed the viewport width. If the example contains wide code, only the code block scrolls horizontally. This expected result belongs to Chapter 20, topic 5.
Practice exercise
Build a fresh example for oklab and oklch from Chapter 20. Change one value, inspect the computed styles, test at 320px and tablet width, translate the visible text, switch the page to RTL, and explain why the final declaration or layout behavior occurs.
Chapter 20 review — 10 questions and answers
1. What should you inspect first when Hex Colors does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for Hex Colors. Then reduce the example until the winning declaration is clear.
2. How should Hex Colors be checked before publishing?
Answer: Test Hex Colors on narrow and wide screens, with long translated text, at increased zoom, and in RTL where direction can affect layout. Add a fallback if browser support or user preferences require one.
3. What should you inspect first when rgb does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for rgb. Then reduce the example until the winning declaration is clear.
4. How should rgb be checked before publishing?
Answer: Test rgb on narrow and wide screens, with long translated text, at increased zoom, and in RTL where direction can affect layout. Add a fallback if browser support or user preferences require one.
5. What should you inspect first when hsl does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for hsl. Then reduce the example until the winning declaration is clear.
6. How should hsl be checked before publishing?
Answer: Test hsl on narrow and wide screens, with long translated text, at increased zoom, and in RTL where direction can affect layout. Add a fallback if browser support or user preferences require one.
7. What should you inspect first when lab and lch does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for lab and lch. Then reduce the example until the winning declaration is clear.
8. How should lab and lch be checked before publishing?
Answer: Test lab and lch on narrow and wide screens, with long translated text, at increased zoom, and in RTL where direction can affect layout. Add a fallback if browser support or user preferences require one.
9. What should you inspect first when oklab and oklch does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for oklab and oklch. Then reduce the example until the winning declaration is clear.
10. How should oklab and oklch be checked before publishing?
Answer: Test oklab and oklch on narrow and wide screens, with long translated text, at increased zoom, and in RTL where direction can affect layout. Add a fallback if browser support or user preferences require one.