CSS • Chapter 37 • Foundations to Production
Container Queries
Every topic includes a CSS/HTML coding example, ten focused teaching examples, code explanation, expected result, practice, and responsive/translated-layout checks.
37.1 container-type
container-type is part of the CSS system covered in Chapter 37. 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 container-type in Chapter 37, 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 container-type, 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 37, topic 1.
Concept in plain language
container-type is part of the CSS system covered in Chapter 37. 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 pricing table for container-type. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 37, topic 1, example 1.
Example 2: Change one value
Change one important CSS value in the lesson sidebar example for container-type. Predict the visual difference before reloading the page. Chapter 37, topic 1, example 2.
Example 3: Narrow-screen test
Test container-type in the contact form at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 37, topic 1, example 3.
Example 4: Translated-text test
Translate the button group into a language with longer labels while using container-type. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 37, topic 1, example 4.
Example 5: Arabic/Persian test
Switch the data table to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 37, topic 1, example 5.
Example 6: Accessibility test
Check container-type in the media player with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 37, topic 1, example 6.
Example 7: Cascade test
Add a competing rule to the notification and determine why the declaration for container-type wins or loses using the browser's Styles and Computed panels. Chapter 37, topic 1, example 7.
Example 8: Content-stress test
Fill the language selector with very long words, URLs, translated text, images, and nested controls. Adjust container-type without hiding meaningful content. Chapter 37, topic 1, example 8.
Example 9: Refactoring test
Rewrite the course card so container-type uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 37, topic 1, example 9.
Example 10: Production review
Review container-type in the navigation bar for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 37, topic 1, example 10.
CSS/HTML coding example
<!-- HTML -->
<section class="card-list"><article class="card">Card</article></section>
<style>
.card-list { container-type:inline-size; }
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate container-type.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- container-type establishes a query container for inline-size queries.
- 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 container-type 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 37, topic 1.
Practice exercise
Build a fresh example for container-type from Chapter 37. 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.
37.2 container-name
container-name is part of the CSS system covered in Chapter 37. 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 container-name in Chapter 37, 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 container-name, 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 37, topic 2.
Concept in plain language
container-name is part of the CSS system covered in Chapter 37. 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 button group for container-name. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 37, topic 2, example 1.
Example 2: Change one value
Change one important CSS value in the data table example for container-name. Predict the visual difference before reloading the page. Chapter 37, topic 2, example 2.
Example 3: Narrow-screen test
Test container-name in the media player at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 37, topic 2, example 3.
Example 4: Translated-text test
Translate the notification into a language with longer labels while using container-name. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 37, topic 2, example 4.
Example 5: Arabic/Persian test
Switch the language selector to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 37, topic 2, example 5.
Example 6: Accessibility test
Check container-name in the course card with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 37, topic 2, example 6.
Example 7: Cascade test
Add a competing rule to the navigation bar and determine why the declaration for container-name wins or loses using the browser's Styles and Computed panels. Chapter 37, topic 2, example 7.
Example 8: Content-stress test
Fill the article with very long words, URLs, translated text, images, and nested controls. Adjust container-name without hiding meaningful content. Chapter 37, topic 2, example 8.
Example 9: Refactoring test
Rewrite the profile panel so container-name uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 37, topic 2, example 9.
Example 10: Production review
Review container-name in the search form for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 37, topic 2, example 10.
CSS/HTML coding example
<!-- HTML -->
<section class="card-list"><article class="card">Card</article></section>
<style>
.card-list { container-name:cards; container-type:inline-size; }
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate container-name.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- container-name lets @container target a specific container.
- 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 container-name 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 37, topic 2.
Practice exercise
Build a fresh example for container-name from Chapter 37. 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.
37.3 @container Size Queries
@container Size Queries is part of the CSS system covered in Chapter 37. 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 @container Size Queries in Chapter 37, 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 @container Size Queries, 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 37, topic 3.
Concept in plain language
@container Size Queries is part of the CSS system covered in Chapter 37. 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 notification for @container Size Queries. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 37, topic 3, example 1.
Example 2: Change one value
Change one important CSS value in the language selector example for @container Size Queries. Predict the visual difference before reloading the page. Chapter 37, topic 3, example 2.
Example 3: Narrow-screen test
Test @container Size Queries in the course card at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 37, topic 3, example 3.
Example 4: Translated-text test
Translate the navigation bar into a language with longer labels while using @container Size Queries. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 37, topic 3, example 4.
Example 5: Arabic/Persian test
Switch the article to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 37, topic 3, example 5.
Example 6: Accessibility test
Check @container Size Queries in the profile panel with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 37, topic 3, example 6.
Example 7: Cascade test
Add a competing rule to the search form and determine why the declaration for @container Size Queries wins or loses using the browser's Styles and Computed panels. Chapter 37, topic 3, example 7.
Example 8: Content-stress test
Fill the dashboard with very long words, URLs, translated text, images, and nested controls. Adjust @container Size Queries without hiding meaningful content. Chapter 37, topic 3, example 8.
Example 9: Refactoring test
Rewrite the photo gallery so @container Size Queries uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 37, topic 3, example 9.
Example 10: Production review
Review @container Size Queries in the pricing table for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 37, topic 3, example 10.
CSS/HTML coding example
<!-- HTML -->
<section class="card-list"><article class="card">Adaptive card</article></section>
<style>
.card-list { container-type:inline-size; }
@container (width > 35rem) { .card { display:grid; grid-template-columns:10rem 1fr; } }
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate @container Size Queries.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The card adapts to its container width rather than the viewport.
- 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 @container Size Queries 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 37, topic 3.
Practice exercise
Build a fresh example for @container Size Queries from Chapter 37. 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.
37.4 Container Query Units
Container Query Units is part of the CSS system covered in Chapter 37. 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 Container Query Units in Chapter 37, 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 Container Query Units, 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 37, topic 4.
Concept in plain language
Container Query Units is part of the CSS system covered in Chapter 37. 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 navigation bar for Container Query Units. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 37, topic 4, example 1.
Example 2: Change one value
Change one important CSS value in the article example for Container Query Units. Predict the visual difference before reloading the page. Chapter 37, topic 4, example 2.
Example 3: Narrow-screen test
Test Container Query Units in the profile panel at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 37, topic 4, example 3.
Example 4: Translated-text test
Translate the search form into a language with longer labels while using Container Query Units. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 37, topic 4, example 4.
Example 5: Arabic/Persian test
Switch the dashboard to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 37, topic 4, example 5.
Example 6: Accessibility test
Check Container Query Units in the photo gallery with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 37, topic 4, example 6.
Example 7: Cascade test
Add a competing rule to the pricing table and determine why the declaration for Container Query Units wins or loses using the browser's Styles and Computed panels. Chapter 37, topic 4, example 7.
Example 8: Content-stress test
Fill the lesson sidebar with very long words, URLs, translated text, images, and nested controls. Adjust Container Query Units without hiding meaningful content. Chapter 37, topic 4, example 8.
Example 9: Refactoring test
Rewrite the contact form so Container Query Units uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 37, topic 4, example 9.
Example 10: Production review
Review Container Query Units in the button group for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 37, topic 4, example 10.
CSS/HTML coding example
<!-- HTML -->
<article class="card">Container-relative padding</article>
<style>
.card { padding:clamp(1rem,4cqi,2rem); }
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate Container Query Units.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- cqi is based on the container's inline size.
- 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 Container Query Units 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 37, topic 4.
Practice exercise
Build a fresh example for Container Query Units from Chapter 37. 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.
37.5 Style Queries
Style Queries is part of the CSS system covered in Chapter 37. 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 Style Queries in Chapter 37, 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 Style Queries, 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 37, topic 5.
Concept in plain language
Style Queries is part of the CSS system covered in Chapter 37. 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 search form for Style Queries. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 37, topic 5, example 1.
Example 2: Change one value
Change one important CSS value in the dashboard example for Style Queries. Predict the visual difference before reloading the page. Chapter 37, topic 5, example 2.
Example 3: Narrow-screen test
Test Style Queries in the photo gallery at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 37, topic 5, example 3.
Example 4: Translated-text test
Translate the pricing table into a language with longer labels while using Style Queries. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 37, topic 5, example 4.
Example 5: Arabic/Persian test
Switch the lesson sidebar to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 37, topic 5, example 5.
Example 6: Accessibility test
Check Style Queries in the contact form with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 37, topic 5, example 6.
Example 7: Cascade test
Add a competing rule to the button group and determine why the declaration for Style Queries wins or loses using the browser's Styles and Computed panels. Chapter 37, topic 5, example 7.
Example 8: Content-stress test
Fill the data table with very long words, URLs, translated text, images, and nested controls. Adjust Style Queries without hiding meaningful content. Chapter 37, topic 5, example 8.
Example 9: Refactoring test
Rewrite the media player so Style Queries uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 37, topic 5, example 9.
Example 10: Production review
Review Style Queries in the notification for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 37, topic 5, example 10.
CSS/HTML coding example
<!-- HTML -->
<div class="demo style-queries">CSS topic: Style Queries</div>
<style>
.style-queries {
padding: 1rem;
border: 1px solid #94a3b8;
}
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate Style Queries.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The selector targets the demonstration for Style Queries, and the declaration changes a visible part of its presentation.
- 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 Style Queries 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 37, topic 5.
Practice exercise
Build a fresh example for Style Queries from Chapter 37. 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 37 review — 10 questions and answers
1. What should you inspect first when container-type does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for container-type. Then reduce the example until the winning declaration is clear.
2. How should container-type be checked before publishing?
Answer: Test container-type 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 container-name does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for container-name. Then reduce the example until the winning declaration is clear.
4. How should container-name be checked before publishing?
Answer: Test container-name 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 @container Size Queries does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for @container Size Queries. Then reduce the example until the winning declaration is clear.
6. How should @container Size Queries be checked before publishing?
Answer: Test @container Size Queries 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 Container Query Units does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for Container Query Units. Then reduce the example until the winning declaration is clear.
8. How should Container Query Units be checked before publishing?
Answer: Test Container Query Units 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 Style Queries does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for Style Queries. Then reduce the example until the winning declaration is clear.
10. How should Style Queries be checked before publishing?
Answer: Test Style Queries 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.