🎓 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 19 • Foundations to Production

CSS Units

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

19.1 Pixels

Pixels is part of the CSS system covered in Chapter 19. 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 Pixels in Chapter 19, 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 Pixels, 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 19, topic 1.

Concept in plain language

Pixels is part of the CSS system covered in Chapter 19. 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 navigation bar for Pixels. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 19, topic 1, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the article example for Pixels. Predict the visual difference before reloading the page. Chapter 19, topic 1, example 2.

  3. Example 3: Narrow-screen test

    Test Pixels in the profile panel at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 19, topic 1, example 3.

  4. Example 4: Translated-text test

    Translate the search form into a language with longer labels while using Pixels. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 19, topic 1, example 4.

  5. 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 19, topic 1, example 5.

  6. Example 6: Accessibility test

    Check Pixels in the photo gallery with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 19, topic 1, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the pricing table and determine why the declaration for Pixels wins or loses using the browser's Styles and Computed panels. Chapter 19, topic 1, example 7.

  8. Example 8: Content-stress test

    Fill the lesson sidebar with very long words, URLs, translated text, images, and nested controls. Adjust Pixels without hiding meaningful content. Chapter 19, topic 1, example 8.

  9. Example 9: Refactoring test

    Rewrite the contact form so Pixels uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 19, topic 1, example 9.

  10. Example 10: Production review

    Review Pixels in the button group for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 19, topic 1, example 10.

CSS/HTML coding example

<!-- HTML -->
<div class="demo pixels">CSS topic: Pixels</div>

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

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate Pixels.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. The selector targets the demonstration for Pixels, 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 Pixels 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 19, topic 1.

Practice exercise

Build a fresh example for Pixels from Chapter 19. 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.

19.2 Percentages

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

Concept in plain language

Percentages is part of the CSS system covered in Chapter 19. 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 search form for Percentages. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 19, topic 2, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the dashboard example for Percentages. Predict the visual difference before reloading the page. Chapter 19, topic 2, example 2.

  3. Example 3: Narrow-screen test

    Test Percentages in the photo gallery at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 19, topic 2, example 3.

  4. Example 4: Translated-text test

    Translate the pricing table into a language with longer labels while using Percentages. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 19, topic 2, example 4.

  5. 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 19, topic 2, example 5.

  6. Example 6: Accessibility test

    Check Percentages in the contact form with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 19, topic 2, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the button group and determine why the declaration for Percentages wins or loses using the browser's Styles and Computed panels. Chapter 19, topic 2, example 7.

  8. Example 8: Content-stress test

    Fill the data table with very long words, URLs, translated text, images, and nested controls. Adjust Percentages without hiding meaningful content. Chapter 19, topic 2, example 8.

  9. Example 9: Refactoring test

    Rewrite the media player so Percentages uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 19, topic 2, example 9.

  10. Example 10: Production review

    Review Percentages in the notification for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 19, topic 2, example 10.

CSS/HTML coding example

<!-- HTML -->
<div class="demo percentages">CSS topic: Percentages</div>

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

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate Percentages.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. The selector targets the demonstration for Percentages, 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 Percentages 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 19, topic 2.

Practice exercise

Build a fresh example for Percentages from Chapter 19. 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.

19.3 em and rem

em and rem is part of the CSS system covered in Chapter 19. 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 em and rem in Chapter 19, 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 em and rem, 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 19, topic 3.

Concept in plain language

em and rem is part of the CSS system covered in Chapter 19. 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 pricing table for em and rem. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 19, topic 3, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the lesson sidebar example for em and rem. Predict the visual difference before reloading the page. Chapter 19, topic 3, example 2.

  3. Example 3: Narrow-screen test

    Test em and rem in the contact form at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 19, topic 3, example 3.

  4. Example 4: Translated-text test

    Translate the button group into a language with longer labels while using em and rem. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 19, topic 3, example 4.

  5. 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 19, topic 3, example 5.

  6. Example 6: Accessibility test

    Check em and rem in the media player with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 19, topic 3, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the notification and determine why the declaration for em and rem wins or loses using the browser's Styles and Computed panels. Chapter 19, topic 3, example 7.

  8. Example 8: Content-stress test

    Fill the language selector with very long words, URLs, translated text, images, and nested controls. Adjust em and rem without hiding meaningful content. Chapter 19, topic 3, example 8.

  9. Example 9: Refactoring test

    Rewrite the course card so em and rem uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 19, topic 3, example 9.

  10. Example 10: Production review

    Review em and rem in the navigation bar for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 19, topic 3, example 10.

CSS/HTML coding example

<!-- HTML -->
<div class="demo em-and-rem">CSS topic: em and rem</div>

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

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate em and rem.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. The selector targets the demonstration for em and rem, 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 em and rem 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 19, topic 3.

Practice exercise

Build a fresh example for em and rem from Chapter 19. 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.

19.4 Viewport Units

Viewport Units is part of the CSS system covered in Chapter 19. 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 Viewport Units in Chapter 19, 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 Viewport 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 19, topic 4.

Concept in plain language

Viewport Units is part of the CSS system covered in Chapter 19. 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 button group for Viewport Units. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 19, topic 4, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the data table example for Viewport Units. Predict the visual difference before reloading the page. Chapter 19, topic 4, example 2.

  3. Example 3: Narrow-screen test

    Test Viewport Units in the media player at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 19, topic 4, example 3.

  4. Example 4: Translated-text test

    Translate the notification into a language with longer labels while using Viewport Units. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 19, topic 4, example 4.

  5. 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 19, topic 4, example 5.

  6. Example 6: Accessibility test

    Check Viewport Units in the course card with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 19, topic 4, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the navigation bar and determine why the declaration for Viewport Units wins or loses using the browser's Styles and Computed panels. Chapter 19, topic 4, example 7.

  8. Example 8: Content-stress test

    Fill the article with very long words, URLs, translated text, images, and nested controls. Adjust Viewport Units without hiding meaningful content. Chapter 19, topic 4, example 8.

  9. Example 9: Refactoring test

    Rewrite the profile panel so Viewport Units uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 19, topic 4, example 9.

  10. Example 10: Production review

    Review Viewport Units in the search form for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 19, topic 4, example 10.

CSS/HTML coding example

<!-- HTML -->
<div class="demo viewport-units">CSS topic: Viewport Units</div>

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

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate Viewport Units.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. The selector targets the demonstration for Viewport Units, 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 Viewport 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 19, topic 4.

Practice exercise

Build a fresh example for Viewport Units from Chapter 19. 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.

19.5 Dynamic Viewport Units

Dynamic Viewport Units is part of the CSS system covered in Chapter 19. 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 Dynamic Viewport Units in Chapter 19, 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 Dynamic Viewport 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 19, topic 5.

Concept in plain language

Dynamic Viewport Units is part of the CSS system covered in Chapter 19. 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 notification for Dynamic Viewport Units. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 19, topic 5, example 1.

  2. Example 2: Change one value

    Change one important CSS value in the language selector example for Dynamic Viewport Units. Predict the visual difference before reloading the page. Chapter 19, topic 5, example 2.

  3. Example 3: Narrow-screen test

    Test Dynamic Viewport Units in the course card at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 19, topic 5, example 3.

  4. Example 4: Translated-text test

    Translate the navigation bar into a language with longer labels while using Dynamic Viewport Units. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 19, topic 5, example 4.

  5. 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 19, topic 5, example 5.

  6. Example 6: Accessibility test

    Check Dynamic Viewport Units in the profile panel with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 19, topic 5, example 6.

  7. Example 7: Cascade test

    Add a competing rule to the search form and determine why the declaration for Dynamic Viewport Units wins or loses using the browser's Styles and Computed panels. Chapter 19, topic 5, example 7.

  8. Example 8: Content-stress test

    Fill the dashboard with very long words, URLs, translated text, images, and nested controls. Adjust Dynamic Viewport Units without hiding meaningful content. Chapter 19, topic 5, example 8.

  9. Example 9: Refactoring test

    Rewrite the photo gallery so Dynamic Viewport Units uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 19, topic 5, example 9.

  10. Example 10: Production review

    Review Dynamic Viewport Units in the pricing table for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 19, topic 5, example 10.

CSS/HTML coding example

<!-- HTML -->
<div class="demo dynamic-viewport-units">CSS topic: Dynamic Viewport Units</div>

<style>
.dynamic-viewport-units {
  padding: 1rem;
  border: 1px solid #94a3b8;
}
</style>

Step-by-step code explanation

  1. Identify the selector and declaration that demonstrate Dynamic Viewport Units.
  2. Read the HTML structure first so you know which box or relationship the CSS is styling.
  3. The selector targets the demonstration for Dynamic Viewport Units, 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 Dynamic Viewport 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 19, topic 5.

Practice exercise

Build a fresh example for Dynamic Viewport Units from Chapter 19. 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 19 review — 10 questions and answers

1. What should you inspect first when Pixels does not work as expected?

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

2. How should Pixels be checked before publishing?

Answer: Test Pixels 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 Percentages does not work as expected?

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

4. How should Percentages be checked before publishing?

Answer: Test Percentages 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 em and rem does not work as expected?

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

6. How should em and rem be checked before publishing?

Answer: Test em and rem 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 Viewport Units does not work as expected?

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

8. How should Viewport Units be checked before publishing?

Answer: Test Viewport 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 Dynamic Viewport Units does not work as expected?

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

10. How should Dynamic Viewport Units be checked before publishing?

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