🎓 EASYTUTORGUIDE

Practical tutorials, tools, courses, digital skills, and business promotion.

★ Free Learning
Translate this lesson:
Arabic and Persian use RTL layout. CSS and HTML code remain LTR. Long translated text wraps on all device sizes.

CSS • Chapter 36 • Foundations to Production

Media Queries

Every topic includes a CSS/HTML coding example, ten focused teaching examples, code explanation, expected result, practice, and responsive/translated-layout checks.

5 topics5 coding examples50 teaching examples10 Q&A
Estimated reading time0% read

36.1 @media Basics

@media Basics is part of the CSS system covered in Chapter 36. 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 @media Basics in Chapter 36, 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 @media Basics, 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 36, topic 1.

Concept in plain language

@media Basics is part of the CSS system covered in Chapter 36. 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

  1. Example 1: Smallest useful case

    Build a minimal course card for @media Basics. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 36, topic 1, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the navigation bar example for @media Basics. Predict the visual difference before reloading the page. Chapter 36, topic 1, example 2.

  3. Example 3: Narrow-screen test

    Test @media Basics in the article at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 36, topic 1, example 3.

  4. Example 4: Translated-text test

    Translate the profile panel into a language with longer labels while using @media Basics. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 36, topic 1, example 4.

  5. Example 5: Arabic/Persian test

    Switch the search form to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 36, topic 1, example 5.

  6. Example 6: Accessibility test

    Check @media Basics in the dashboard with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 36, topic 1, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the photo gallery and determine why the declaration for @media Basics wins or loses using the browser's Styles and Computed panels. Chapter 36, topic 1, example 7.

  8. Example 8: Content-stress test

    Fill the pricing table with very long words, URLs, translated text, images, and nested controls. Adjust @media Basics without hiding meaningful content. Chapter 36, topic 1, example 8.

  9. Example 9: Refactoring test

    Rewrite the lesson sidebar so @media Basics uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 36, topic 1, example 9.

  10. Example 10: Production review

    Review @media Basics in the contact form for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 36, topic 1, example 10.

CSS/HTML coding example

<!-- HTML -->
<div class="layout">Responsive layout</div>

<style>
@media (max-width: 48rem) { .layout { grid-template-columns:1fr; } }
</style>

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate @media Basics.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. The media query changes styles when the viewport condition matches.
  4. 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.
  5. 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 @media Basics 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 36, topic 1.

Practice exercise

Build a fresh example for @media Basics from Chapter 36. 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.

36.2 Width Queries

Width Queries is part of the CSS system covered in Chapter 36. 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 Width Queries in Chapter 36, 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 Width 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 36, topic 2.

Concept in plain language

Width Queries is part of the CSS system covered in Chapter 36. 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

  1. Example 1: Smallest useful case

    Build a minimal profile panel for Width Queries. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 36, topic 2, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the search form example for Width Queries. Predict the visual difference before reloading the page. Chapter 36, topic 2, example 2.

  3. Example 3: Narrow-screen test

    Test Width Queries in the dashboard at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 36, topic 2, example 3.

  4. Example 4: Translated-text test

    Translate the photo gallery into a language with longer labels while using Width Queries. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 36, topic 2, example 4.

  5. Example 5: Arabic/Persian test

    Switch the pricing table to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 36, topic 2, example 5.

  6. Example 6: Accessibility test

    Check Width Queries in the lesson sidebar with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 36, topic 2, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the contact form and determine why the declaration for Width Queries wins or loses using the browser's Styles and Computed panels. Chapter 36, topic 2, example 7.

  8. Example 8: Content-stress test

    Fill the button group with very long words, URLs, translated text, images, and nested controls. Adjust Width Queries without hiding meaningful content. Chapter 36, topic 2, example 8.

  9. Example 9: Refactoring test

    Rewrite the data table so Width Queries uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 36, topic 2, example 9.

  10. Example 10: Production review

    Review Width Queries in the media player for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 36, topic 2, example 10.

CSS/HTML coding example

<!-- HTML -->
<div class="demo width-queries">CSS topic: Width Queries</div>

<style>
.width-queries {
  padding: 1rem;
  border: 1px solid #94a3b8;
}
</style>

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate Width Queries.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. The selector targets the demonstration for Width Queries, and the declaration changes a visible part of its presentation.
  4. 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.
  5. 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 Width 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 36, topic 2.

Practice exercise

Build a fresh example for Width Queries from Chapter 36. 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.

36.3 Orientation Queries

Orientation Queries is part of the CSS system covered in Chapter 36. 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 Orientation Queries in Chapter 36, 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 Orientation 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 36, topic 3.

Concept in plain language

Orientation Queries is part of the CSS system covered in Chapter 36. 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

  1. Example 1: Smallest useful case

    Build a minimal photo gallery for Orientation Queries. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 36, topic 3, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the pricing table example for Orientation Queries. Predict the visual difference before reloading the page. Chapter 36, topic 3, example 2.

  3. Example 3: Narrow-screen test

    Test Orientation Queries in the lesson sidebar at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 36, topic 3, example 3.

  4. Example 4: Translated-text test

    Translate the contact form into a language with longer labels while using Orientation Queries. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 36, topic 3, example 4.

  5. Example 5: Arabic/Persian test

    Switch the button group to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 36, topic 3, example 5.

  6. Example 6: Accessibility test

    Check Orientation Queries in the data table with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 36, topic 3, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the media player and determine why the declaration for Orientation Queries wins or loses using the browser's Styles and Computed panels. Chapter 36, topic 3, example 7.

  8. Example 8: Content-stress test

    Fill the notification with very long words, URLs, translated text, images, and nested controls. Adjust Orientation Queries without hiding meaningful content. Chapter 36, topic 3, example 8.

  9. Example 9: Refactoring test

    Rewrite the language selector so Orientation Queries uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 36, topic 3, example 9.

  10. Example 10: Production review

    Review Orientation Queries in the course card for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 36, topic 3, example 10.

CSS/HTML coding example

<!-- HTML -->
<div class="gallery">Landscape gallery</div>

<style>
@media (orientation: landscape) { .gallery { grid-template-columns:repeat(4,1fr); } }
</style>

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate Orientation Queries.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. Orientation queries respond to viewport orientation.
  4. 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.
  5. 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 Orientation 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 36, topic 3.

Practice exercise

Build a fresh example for Orientation Queries from Chapter 36. 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.

36.4 Range Syntax

Range Syntax is part of the CSS system covered in Chapter 36. 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 Range Syntax in Chapter 36, 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 Range Syntax, 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 36, topic 4.

Concept in plain language

Range Syntax is part of the CSS system covered in Chapter 36. 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

  1. Example 1: Smallest useful case

    Build a minimal contact form for Range Syntax. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 36, topic 4, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the button group example for Range Syntax. Predict the visual difference before reloading the page. Chapter 36, topic 4, example 2.

  3. Example 3: Narrow-screen test

    Test Range Syntax in the data table at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 36, topic 4, example 3.

  4. Example 4: Translated-text test

    Translate the media player into a language with longer labels while using Range Syntax. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 36, topic 4, example 4.

  5. Example 5: Arabic/Persian test

    Switch the notification to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 36, topic 4, example 5.

  6. Example 6: Accessibility test

    Check Range Syntax in the language selector with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 36, topic 4, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the course card and determine why the declaration for Range Syntax wins or loses using the browser's Styles and Computed panels. Chapter 36, topic 4, example 7.

  8. Example 8: Content-stress test

    Fill the navigation bar with very long words, URLs, translated text, images, and nested controls. Adjust Range Syntax without hiding meaningful content. Chapter 36, topic 4, example 8.

  9. Example 9: Refactoring test

    Rewrite the article so Range Syntax uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 36, topic 4, example 9.

  10. Example 10: Production review

    Review Range Syntax in the profile panel for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 36, topic 4, example 10.

CSS/HTML coding example

<!-- HTML -->
<article class="card">Range syntax</article>

<style>
@media (30rem <= width <= 70rem) { .card { padding:1.5rem; } }
</style>

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate Range Syntax.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. Media query range syntax can express minimum and maximum widths clearly.
  4. 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.
  5. 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 Range Syntax 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 36, topic 4.

Practice exercise

Build a fresh example for Range Syntax from Chapter 36. 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.

36.5 Combining Media Conditions

Combining Media Conditions is part of the CSS system covered in Chapter 36. 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 Combining Media Conditions in Chapter 36, 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 Combining Media Conditions, 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 36, topic 5.

Concept in plain language

Combining Media Conditions is part of the CSS system covered in Chapter 36. 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

  1. Example 1: Smallest useful case

    Build a minimal media player for Combining Media Conditions. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 36, topic 5, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the notification example for Combining Media Conditions. Predict the visual difference before reloading the page. Chapter 36, topic 5, example 2.

  3. Example 3: Narrow-screen test

    Test Combining Media Conditions in the language selector at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 36, topic 5, example 3.

  4. Example 4: Translated-text test

    Translate the course card into a language with longer labels while using Combining Media Conditions. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 36, topic 5, example 4.

  5. Example 5: Arabic/Persian test

    Switch the navigation bar to Arabic or Persian. Verify logical spacing, start/end alignment, sidebar direction, and LTR code islands. Chapter 36, topic 5, example 5.

  6. Example 6: Accessibility test

    Check Combining Media Conditions in the article with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 36, topic 5, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the profile panel and determine why the declaration for Combining Media Conditions wins or loses using the browser's Styles and Computed panels. Chapter 36, topic 5, example 7.

  8. Example 8: Content-stress test

    Fill the search form with very long words, URLs, translated text, images, and nested controls. Adjust Combining Media Conditions without hiding meaningful content. Chapter 36, topic 5, example 8.

  9. Example 9: Refactoring test

    Rewrite the dashboard so Combining Media Conditions uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 36, topic 5, example 9.

  10. Example 10: Production review

    Review Combining Media Conditions in the photo gallery for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 36, topic 5, example 10.

CSS/HTML coding example

<!-- HTML -->
<div class="demo combining-media-conditions">CSS topic: Combining Media Conditions</div>

<style>
.combining-media-conditions {
  padding: 1rem;
  border: 1px solid #94a3b8;
}
</style>

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate Combining Media Conditions.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. The selector targets the demonstration for Combining Media Conditions, and the declaration changes a visible part of its presentation.
  4. 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.
  5. 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 Combining Media Conditions 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 36, topic 5.

Practice exercise

Build a fresh example for Combining Media Conditions from Chapter 36. 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 36 review — 10 questions and answers

1. What should you inspect first when @media Basics does not work as expected?

Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for @media Basics. Then reduce the example until the winning declaration is clear.

2. How should @media Basics be checked before publishing?

Answer: Test @media Basics 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 Width Queries does not work as expected?

Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for Width Queries. Then reduce the example until the winning declaration is clear.

4. How should Width Queries be checked before publishing?

Answer: Test Width 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.

5. What should you inspect first when Orientation Queries does not work as expected?

Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for Orientation Queries. Then reduce the example until the winning declaration is clear.

6. How should Orientation Queries be checked before publishing?

Answer: Test Orientation 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 Range Syntax does not work as expected?

Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for Range Syntax. Then reduce the example until the winning declaration is clear.

8. How should Range Syntax be checked before publishing?

Answer: Test Range Syntax 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 Combining Media Conditions does not work as expected?

Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for Combining Media Conditions. Then reduce the example until the winning declaration is clear.

10. How should Combining Media Conditions be checked before publishing?

Answer: Test Combining Media Conditions 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.