CSS • Chapter 27 • Foundations to Production
Text Layout
Every topic includes a CSS/HTML coding example, ten focused teaching examples, code explanation, expected result, practice, and responsive/translated-layout checks.
27.1 text-align
text-align is part of the CSS system covered in Chapter 27. 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 text-align in Chapter 27, 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 text-align, 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 27, topic 1.
Concept in plain language
text-align is part of the CSS system covered in Chapter 27. 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 media player for text-align. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 27, topic 1, example 1.
Example 2: Change one value
Change one important CSS value in the notification example for text-align. Predict the visual difference before reloading the page. Chapter 27, topic 1, example 2.
Example 3: Narrow-screen test
Test text-align in the language selector at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 27, topic 1, example 3.
Example 4: Translated-text test
Translate the course card into a language with longer labels while using text-align. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 27, topic 1, example 4.
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 27, topic 1, example 5.
Example 6: Accessibility test
Check text-align in the article with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 27, topic 1, example 6.
Example 7: Cascade test
Add a competing rule to the profile panel and determine why the declaration for text-align wins or loses using the browser's Styles and Computed panels. Chapter 27, topic 1, example 7.
Example 8: Content-stress test
Fill the search form with very long words, URLs, translated text, images, and nested controls. Adjust text-align without hiding meaningful content. Chapter 27, topic 1, example 8.
Example 9: Refactoring test
Rewrite the dashboard so text-align uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 27, topic 1, example 9.
Example 10: Production review
Review text-align in the photo gallery for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 27, topic 1, example 10.
CSS/HTML coding example
<!-- HTML -->
<p class="text" lang="en">A long paragraph demonstrates the typography rule in a real content block.</p>
<style>
.text{text-align:start}
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate text-align.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The declaration demonstrates text-align on paragraph text.
- 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 text-align 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 27, topic 1.
Practice exercise
Build a fresh example for text-align from Chapter 27. 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.
27.2 text-indent
text-indent is part of the CSS system covered in Chapter 27. 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 text-indent in Chapter 27, 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 text-indent, 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 27, topic 2.
Concept in plain language
text-indent is part of the CSS system covered in Chapter 27. 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 course card for text-indent. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 27, topic 2, example 1.
Example 2: Change one value
Change one important CSS value in the navigation bar example for text-indent. Predict the visual difference before reloading the page. Chapter 27, topic 2, example 2.
Example 3: Narrow-screen test
Test text-indent in the article at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 27, topic 2, example 3.
Example 4: Translated-text test
Translate the profile panel into a language with longer labels while using text-indent. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 27, topic 2, example 4.
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 27, topic 2, example 5.
Example 6: Accessibility test
Check text-indent in the dashboard with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 27, topic 2, example 6.
Example 7: Cascade test
Add a competing rule to the photo gallery and determine why the declaration for text-indent wins or loses using the browser's Styles and Computed panels. Chapter 27, topic 2, example 7.
Example 8: Content-stress test
Fill the pricing table with very long words, URLs, translated text, images, and nested controls. Adjust text-indent without hiding meaningful content. Chapter 27, topic 2, example 8.
Example 9: Refactoring test
Rewrite the lesson sidebar so text-indent uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 27, topic 2, example 9.
Example 10: Production review
Review text-indent in the contact form for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 27, topic 2, example 10.
CSS/HTML coding example
<!-- HTML -->
<p class="text" lang="en">A long paragraph demonstrates the typography rule in a real content block.</p>
<style>
.text{text-indent:2em}
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate text-indent.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The declaration demonstrates text-indent on paragraph text.
- 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 text-indent 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 27, topic 2.
Practice exercise
Build a fresh example for text-indent from Chapter 27. 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.
27.3 letter-spacing
letter-spacing is part of the CSS system covered in Chapter 27. 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 letter-spacing in Chapter 27, 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 letter-spacing, 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 27, topic 3.
Concept in plain language
letter-spacing is part of the CSS system covered in Chapter 27. 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 profile panel for letter-spacing. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 27, topic 3, example 1.
Example 2: Change one value
Change one important CSS value in the search form example for letter-spacing. Predict the visual difference before reloading the page. Chapter 27, topic 3, example 2.
Example 3: Narrow-screen test
Test letter-spacing in the dashboard at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 27, topic 3, example 3.
Example 4: Translated-text test
Translate the photo gallery into a language with longer labels while using letter-spacing. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 27, topic 3, example 4.
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 27, topic 3, example 5.
Example 6: Accessibility test
Check letter-spacing in the lesson sidebar with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 27, topic 3, example 6.
Example 7: Cascade test
Add a competing rule to the contact form and determine why the declaration for letter-spacing wins or loses using the browser's Styles and Computed panels. Chapter 27, topic 3, example 7.
Example 8: Content-stress test
Fill the button group with very long words, URLs, translated text, images, and nested controls. Adjust letter-spacing without hiding meaningful content. Chapter 27, topic 3, example 8.
Example 9: Refactoring test
Rewrite the data table so letter-spacing uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 27, topic 3, example 9.
Example 10: Production review
Review letter-spacing in the media player for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 27, topic 3, example 10.
CSS/HTML coding example
<!-- HTML -->
<p class="text" lang="en">A long paragraph demonstrates the typography rule in a real content block.</p>
<style>
.text{letter-spacing:.04em}
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate letter-spacing.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The declaration demonstrates letter-spacing on paragraph text.
- 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 letter-spacing 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 27, topic 3.
Practice exercise
Build a fresh example for letter-spacing from Chapter 27. 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.
27.4 word-spacing
word-spacing is part of the CSS system covered in Chapter 27. 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 word-spacing in Chapter 27, 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 word-spacing, 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 27, topic 4.
Concept in plain language
word-spacing is part of the CSS system covered in Chapter 27. 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 photo gallery for word-spacing. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 27, topic 4, example 1.
Example 2: Change one value
Change one important CSS value in the pricing table example for word-spacing. Predict the visual difference before reloading the page. Chapter 27, topic 4, example 2.
Example 3: Narrow-screen test
Test word-spacing in the lesson sidebar at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 27, topic 4, example 3.
Example 4: Translated-text test
Translate the contact form into a language with longer labels while using word-spacing. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 27, topic 4, example 4.
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 27, topic 4, example 5.
Example 6: Accessibility test
Check word-spacing in the data table with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 27, topic 4, example 6.
Example 7: Cascade test
Add a competing rule to the media player and determine why the declaration for word-spacing wins or loses using the browser's Styles and Computed panels. Chapter 27, topic 4, example 7.
Example 8: Content-stress test
Fill the notification with very long words, URLs, translated text, images, and nested controls. Adjust word-spacing without hiding meaningful content. Chapter 27, topic 4, example 8.
Example 9: Refactoring test
Rewrite the language selector so word-spacing uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 27, topic 4, example 9.
Example 10: Production review
Review word-spacing in the course card for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 27, topic 4, example 10.
CSS/HTML coding example
<!-- HTML -->
<p class="text" lang="en">A long paragraph demonstrates the typography rule in a real content block.</p>
<style>
.text{word-spacing:.2em}
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate word-spacing.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The declaration demonstrates word-spacing on paragraph text.
- 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 word-spacing 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 27, topic 4.
Practice exercise
Build a fresh example for word-spacing from Chapter 27. 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.
27.5 white-space
white-space is part of the CSS system covered in Chapter 27. 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 white-space in Chapter 27, 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 white-space, 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 27, topic 5.
Concept in plain language
white-space is part of the CSS system covered in Chapter 27. 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 contact form for white-space. Keep only the declarations needed to see the behavior clearly, then inspect the computed styles. Chapter 27, topic 5, example 1.
Example 2: Change one value
Change one important CSS value in the button group example for white-space. Predict the visual difference before reloading the page. Chapter 27, topic 5, example 2.
Example 3: Narrow-screen test
Test white-space in the data table at 320px, 375px, and tablet width. Watch for min-content sizing, unwrapped text, and elements that refuse to shrink. Chapter 27, topic 5, example 3.
Example 4: Translated-text test
Translate the media player into a language with longer labels while using white-space. Confirm buttons, headings, and navigation wrap without widening the page. Chapter 27, topic 5, example 4.
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 27, topic 5, example 5.
Example 6: Accessibility test
Check white-space in the language selector with keyboard focus, zoom, reduced motion, forced colors, and high text scaling where relevant. Chapter 27, topic 5, example 6.
Example 7: Cascade test
Add a competing rule to the course card and determine why the declaration for white-space wins or loses using the browser's Styles and Computed panels. Chapter 27, topic 5, example 7.
Example 8: Content-stress test
Fill the navigation bar with very long words, URLs, translated text, images, and nested controls. Adjust white-space without hiding meaningful content. Chapter 27, topic 5, example 8.
Example 9: Refactoring test
Rewrite the article so white-space uses reusable tokens, logical properties, or a component class while preserving the same behavior. Chapter 27, topic 5, example 9.
Example 10: Production review
Review white-space in the profile panel for browser support, fallback behavior, RTL, small screens, print, motion preferences, and maintainability. Chapter 27, topic 5, example 10.
CSS/HTML coding example
<!-- HTML -->
<p class="text" lang="en">A long paragraph demonstrates the typography rule in a real content block.</p>
<style>
.text{white-space:pre-wrap}
</style>Step-by-step code explanation
- Identify the selector and declaration that demonstrate white-space.
- Read the HTML structure first so you know which box or relationship the CSS is styling.
- The declaration demonstrates white-space on paragraph text.
- 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 white-space 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 27, topic 5.
Practice exercise
Build a fresh example for white-space from Chapter 27. 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 27 review — 10 questions and answers
1. What should you inspect first when text-align does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for text-align. Then reduce the example until the winning declaration is clear.
2. How should text-align be checked before publishing?
Answer: Test text-align 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 text-indent does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for text-indent. Then reduce the example until the winning declaration is clear.
4. How should text-indent be checked before publishing?
Answer: Test text-indent 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 letter-spacing does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for letter-spacing. Then reduce the example until the winning declaration is clear.
6. How should letter-spacing be checked before publishing?
Answer: Test letter-spacing 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 word-spacing does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for word-spacing. Then reduce the example until the winning declaration is clear.
8. How should word-spacing be checked before publishing?
Answer: Test word-spacing 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 white-space does not work as expected?
Answer: Inspect the matched rules, computed value, box size, layout context, and inherited values for white-space. Then reduce the example until the winning declaration is clear.
10. How should white-space be checked before publishing?
Answer: Test white-space 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.