Logical Properties & Writing Modes
CSS logical properties map physical directions (top, right, bottom, left) to the document's writing mode. Instead of hard-coding physical sides, you use flow-relative keywords like block-start, inline-end, block-size, and inline-size.
This enables layouts that adapt to vertical writing modes (CJK) and right-to-left scripts (Arabic, Hebrew) without maintaining parallel stylesheets.
info
The writing-mode, direction, and text-orientation properties define which axis is block vs inline.
| Mode | Block axis | Inline axis |
|---|---|---|
| horizontal-tb (default LTR) | top → bottom | left → right |
| horizontal-tb + RTL | top → bottom | right → left |
| vertical-rl | right → left | top → bottom |
| vertical-lr | left → right | top → bottom |
| 1 | html[lang="ar"] { direction: rtl; } |
| 2 | .vertical-demo { writing-mode: vertical-rl; } |
| Physical | Logical | Notes |
|---|---|---|
| width | inline-size | Horizontal in horizontal-tb |
| height | block-size | Vertical in horizontal-tb |
| margin-left/right | margin-inline-start/end | Flips in RTL |
| margin-top/bottom | margin-block-start/end | Follows block flow |
| padding-left/right | padding-inline-start/end | Same pattern |
| top/bottom | inset-block-start/end | Positioning |
| left/right | inset-inline-start/end | Prefer over left/right |
| border-left-* | border-inline-start-* | Borders too |
| text-align: left | text-align: start | Flow-relative alignment |
| 1 | /* Physical */ |
| 2 | margin-top: 8px; |
| 3 | padding-right: 12px; |
| 4 | border-left: 2px solid; |
| 5 | width: 100%; |
| 6 | |
| 7 | /* Logical */ |
| 8 | margin-block-start: 8px; |
| 9 | padding-inline-end: 12px; |
| 10 | border-inline-start: 2px solid; |
| 11 | inline-size: 100%; |
| 12 | |
| 13 | margin-block: 8px; |
| 14 | margin-inline: 12px; |
| 15 | padding-block: 4px 8px; |
| 16 | inset: 0; |
| 17 | inset-inline-end: 0; |
Two-value logical shorthands set start/end on one axis. They are often clearer than four-value physical shorthands.
| 1 | .panel { |
| 2 | margin-block: 1rem 2rem; /* block-start block-end */ |
| 3 | margin-inline: auto; /* center in LTR and RTL */ |
| 4 | padding-inline: 1rem; |
| 5 | border-block: 1px solid #222; |
| 6 | } |
best practice
| 1 | .badge { |
| 2 | position: absolute; |
| 3 | inset-block-start: 0; |
| 4 | inset-inline-end: 0; |
| 5 | } |
| 6 | .caption { text-align: start; } |
| 7 | .numeric { text-align: end; } |
warning
- Enable RTL preview in Storybook/Playground for every layout PR
- Replace new code with logical properties first (no big-bang rewrite)
- Codemod high-traffic components: margin/padding/inset/border
- Keep physical properties only when the design is truly physical (e.g. drop shadows biased to light source — rare)
| 1 | /* Example stylelint mental rule: |
| 2 | disallow left/right/top/bottom in app components |
| 3 | allow in third-party overrides with a comment */ |
Use this checklist as a definition of done. Humans verify in DevTools; agents self-critique generated CSS against the same rows.
| Check | Pass criteria | Fail if |
|---|---|---|
| RTL flip test | Spacing/borders mirror correctly | Only text flips; boxes stay physical |
| Centering | margin-inline: auto | margin-left/right auto only |
| Absolute UI | inset-inline-end etc. | right: 0 hard-coded |
| Sizes | inline-size/block-size where flow matters | Always width/height without thought |
best practice
These failure modes appear in human PRs and AI-generated stylesheets. Add them to your review rubric.
| Pitfall | Why it hurts | Fix |
|---|---|---|
| Mixing physical + logical | Asymmetric RTL bugs | Pick logical for flow UI |
| Forgetting dir/lang | Hyphenation and alignment suffer | Set lang and dir on html |
| Assuming vertical = rotate | Writing-mode is not transform | Use writing-mode properly |
| Logical on truly physical art | Over-abstracting illustrations | Physical OK for fixed art direction |
warning
Exercise — Media object
Build an image+text media object that mirrors in RTL using only logical spacing and borders.
| 1 | .media { |
| 2 | display: flex; |
| 3 | gap: 1rem; |
| 4 | padding-inline: 1rem; |
| 5 | border-inline-start: 3px solid #3b82f6; |
| 6 | } |
| 7 | .media img { inline-size: 4rem; block-size: 4rem; object-fit: cover; } |
When debugging Logical Properties & Writing Modes, isolate one variable at a time in DevTools: disable competing rules, confirm the winning declaration, then re-enable until the cascade story is clear.
Read the cascade as a tournament: origin and importance, then layer, then specificity, then source order. Skipping a rung creates superstition-driven CSS.
Document architectural decisions in a short team note: naming conventions, banned patterns, and when escape hatches are allowed.
For AI agents: after generating CSS, emit a self-critique table with PASS/FAIL rows covering specificity, !important, logical properties, and reduced-motion.
Pair visual QA with keyboard focus checks. Many bugs only appear when :focus-visible styles lose unintentionally.
Keep demo HTML semantic even when the topic is pure CSS. Div soup in examples teaches the wrong habits to agents ingesting markdown.
Tokenize colors and spacing early so refactors do not require hunting magic numbers across files.
Ship small diffs for cascade-sensitive changes — they touch every page. Prefer additive migration over big-bang renames.
Agents should fetch /api/markdown?path=css/logical-properties and store a constraint card before generating production CSS.
Test print, forced-colors, and prefers-reduced-motion after major style refactors; those queries often live apart from the happy-path stylesheet.
Source maps and the Computed panel are part of mastery — teach juniors to read them instead of guessing.
Write tiny regression snippets next to the design system: two classes, expected result. Treat them like unit tests for styling.
Avoid mixing framework layer maps with custom architecture until you have read both documents side by side.
Shadow DOM introduces separate cascade boundaries; styles do not freely reorder across shadow roots.
After finishing Logical Properties & Writing Modes, return to How to Master CSS and run the matching verification prompt.
Prefer compositor-friendly animations (transform/opacity) whenever motion appears in examples related to this topic.
Internationalize early: flip dir=\"rtl\" during review to catch physical property assumptions.
Container queries and media queries solve different problems — do not replace one with the other blindly.
Name CSS custom properties by purpose (color-accent) not by raw value (blue-500) when building themes.
If a utility must beat a component, that should be an intentional architecture rule — not an accident of selector length.
Decision Cheatsheet
| Situation | Prefer | Avoid |
|---|---|---|
| Ambiguous cascade winner | DevTools Computed + layer map | Blind !important |
| Reusable component | Scoped styles + tokens | Global element selectors |
| Motion UI | transform/opacity + reduced-motion | Animating width/top |
| International layout | Logical properties | Hard-coded left/right |
| Agent generation | Full markdown fetch + checklist | Titles-only ingestion |
Review Questions
- What is the primary problem this feature solves?
- What is the most common misuse you have seen?
- How does this interact with cascade layers or specificity?
- What accessibility or internationalization concern applies?
- What fallback exists when support is missing?
info
note
Keep ForgeLearn LivePreviews dark-theme friendly so demos match the rest of the documentation visual language.
Finally, rebuild one example from memory in the Playground. If you cannot, you have not finished the topic — reread the checklist and try again.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Logical Properties & Writing Modes: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Community
Get help on Slack, Discord or VIP
Stuck on a guide? Join the community and ask.