Sub topic 3
Logical Values and Flow-Aware Layout
Assume you know CSS selectors, the box model, writing-mode, and the difference between block and inline axes. Logical values let alignment and layout follow those axes instead of the screen's physical edges.
Logical values for alignment and flow
Use start and end with text-align. Use inline-start and inline-end with float and clear.
<p dir="rtl" class="article">
نص عربي مع صورة عائمة.
</p>
<style>
.article {
text-align: start;
}
.article::before {
content: "";
float: inline-start;
inline-size: 5rem;
block-size: 5rem;
margin-inline-end: 1rem;
background: steelblue;
}
.next {
clear: inline-start;
}
</style>In left-to-right text, start usually means left. In right-to-left text, it usually means right. In a vertical writing mode, the inline direction can run vertically.
Logical corners
Logical corner names describe the intersection of block and inline sides:
border-start-start-radiusborder-start-end-radiusborder-end-start-radiusborder-end-end-radius
For example, border-start-end-radius rounds the block-start and inline-end corner. Its physical location changes with writing mode and direction.
Layout modules follow the flow
Flexbox and grid already use the writing mode as their reference. In a horizontal writing mode, flex-direction: row follows the inline axis and column follows the block axis. Prefer gap, align-items, and justify-content over physical offsets when they express the design.
Logical units
vi is one percent of the viewport's inline size. vb is one percent of its block size. Container units work similarly: cqi uses a container's inline size, and cqb uses its block size.
.panel {
inline-size: min(90vi, 60rem);
padding-block: 4vb;
font-size: clamp(1rem, 2cqi, 1.5rem);
}Physical values and testing
Keep physical values when the design truly refers to the screen, such as a fixed map control in the top-right corner. Otherwise, prefer logical properties.
Test with both dir="rtl" and writing-mode: vertical-rl.
Support and migration
For older browsers, provide a physical fallback first, then override it inside @supports. Migrate one component at a time. Replace sizing, spacing, borders, and positioning before checking each component in multiple directions.
Exercise
In right-to-left text, where does padding-inline-start appear?
Show answer
It appears on the right side, because the inline start side is the right edge.