|$ curl https://forge-ai.dev/api/markdown?path=docs/css/logical-properties
$cat docs/logical-properties-&-writing-modes.md
updated Today·22 min read·published

Logical Properties & Writing Modes

CSSLayouti18nIntermediate🎯Free Tools
Introduction

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

Browser support for logical properties is excellent. Start using margin-inline and padding-block by default.
Writing Modes Primer

The writing-mode, direction, and text-orientation properties define which axis is block vs inline.

ModeBlock axisInline axis
horizontal-tb (default LTR)top → bottomleft → right
horizontal-tb + RTLtop → bottomright → left
vertical-rlright → lefttop → bottom
vertical-lrleft → righttop → bottom
writing-mode.css
CSS
1html[lang="ar"] { direction: rtl; }
2.vertical-demo { writing-mode: vertical-rl; }
Physical → Logical Map
PhysicalLogicalNotes
widthinline-sizeHorizontal in horizontal-tb
heightblock-sizeVertical in horizontal-tb
margin-left/rightmargin-inline-start/endFlips in RTL
margin-top/bottommargin-block-start/endFollows block flow
padding-left/rightpadding-inline-start/endSame pattern
top/bottominset-block-start/endPositioning
left/rightinset-inline-start/endPrefer over left/right
border-left-*border-inline-start-*Borders too
text-align: lefttext-align: startFlow-relative alignment
logical-mapping.css
CSS
1/* Physical */
2margin-top: 8px;
3padding-right: 12px;
4border-left: 2px solid;
5width: 100%;
6
7/* Logical */
8margin-block-start: 8px;
9padding-inline-end: 12px;
10border-inline-start: 2px solid;
11inline-size: 100%;
12
13margin-block: 8px;
14margin-inline: 12px;
15padding-block: 4px 8px;
16inset: 0;
17inset-inline-end: 0;
preview
Logical Shorthands

Two-value logical shorthands set start/end on one axis. They are often clearer than four-value physical shorthands.

shorthands.css
CSS
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

Prefer margin-inline: auto for horizontal centering — it works in RTL without changes.
Positioning & Text Alignment
logical-position.css
CSS
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

Mixing physical left with logical margin-inline on the same component causes RTL bugs that are hard to spot.
Migration Strategy
  1. Enable RTL preview in Storybook/Playground for every layout PR
  2. Replace new code with logical properties first (no big-bang rewrite)
  3. Codemod high-traffic components: margin/padding/inset/border
  4. Keep physical properties only when the design is truly physical (e.g. drop shadows biased to light source — rare)
lint-hint.css
CSS
1/* Example stylelint mental rule:
2 disallow left/right/top/bottom in app components
3 allow in third-party overrides with a comment */
Mastery Checklist

Use this checklist as a definition of done. Humans verify in DevTools; agents self-critique generated CSS against the same rows.

CheckPass criteriaFail if
RTL flip testSpacing/borders mirror correctlyOnly text flips; boxes stay physical
Centeringmargin-inline: automargin-left/right auto only
Absolute UIinset-inline-end etc.right: 0 hard-coded
Sizesinline-size/block-size where flow mattersAlways width/height without thought

best practice

Treat each critical fail as blocking — do not mark the topic complete until those rows pass.
Common Pitfalls

These failure modes appear in human PRs and AI-generated stylesheets. Add them to your review rubric.

PitfallWhy it hurtsFix
Mixing physical + logicalAsymmetric RTL bugsPick logical for flow UI
Forgetting dir/langHyphenation and alignment sufferSet lang and dir on html
Assuming vertical = rotateWriting-mode is not transformUse writing-mode properly
Logical on truly physical artOver-abstracting illustrationsPhysical OK for fixed art direction

warning

If you repeat a pitfall, write a one-line constraint card and reuse it on the next change.
Practice

Exercise — Media object

Build an image+text media object that mirrors in RTL using only logical spacing and borders.

media-object.css
CSS
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; }
preview
Deep Notes & Mental Models

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

SituationPreferAvoid
Ambiguous cascade winnerDevTools Computed + layer mapBlind !important
Reusable componentScoped styles + tokensGlobal element selectors
Motion UItransform/opacity + reduced-motionAnimating width/top
International layoutLogical propertiesHard-coded left/right
Agent generationFull markdown fetch + checklistTitles-only ingestion

Review Questions

  1. What is the primary problem this feature solves?
  2. What is the most common misuse you have seen?
  3. How does this interact with cascade layers or specificity?
  4. What accessibility or internationalization concern applies?
  5. What fallback exists when support is missing?

info

Continue with the Property Reference when you need defaults and inheritance for related properties.
📝

note

Install the CSS skill for agents: curl -s https://forgelearn.dev/skills/forgelearn-css/SKILL.md.

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.