Skip to article content
FrontendXLesson 21 / 30

Logical properties and writing modes

Build semantic, accessible and responsive interfaces from a blank page, and explain why each layout and styling decision works.

advanced · about 35 minutes · 1 exercises

  • Implement

What you will be able to do

#
  • Replace physical properties with logical equivalents.
  • Reason about inline and block axes under different writing modes.

Overview

#

Physical properties such as margin-left and padding-top assume text flows left to right and top to bottom. Logical properties describe the same spacing in terms of the writing mode: the inline axis is the direction text flows, and the block axis is the direction lines stack. margin-inline-start is the margin at the start of the text direction, which is the left in English and the right in Arabic or Hebrew.

snippet.css
.card {
  margin-inline: auto;
  padding-block: 1rem;
  padding-inline: 1.5rem;
  border-inline-start: 4px solid #0072f5;
  text-align: start;
}

Using logical properties means a component that supports right-to-left languages or vertical writing modes needs no per-direction overrides. The mapping is direct: margin-inline-start replaces margin-left in left-to-right mode, padding-block-end replaces padding-bottom, and inset-inline-start replaces left.

snippet.css
/* physical */
.tooltip { left: 0; padding-left: 8px; }

/* logical, direction-aware */
.tooltip { inset-inline-start: 0; padding-inline-start: 8px; }

Shorthand properties also have logical forms. margin-inline sets both inline margins, margin-block sets both block margins, and inset sets all four offsets. text-align: start and end replace left and right. Adopting logical properties early avoids a painful migration later when internationalization arrives, and it costs nothing in browsers that support them, which is now effectively all of them.

Exercises

#

Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.

  1. Exercise 1Implement

    Rewrite this physical CSS using logical properties: margin-left: auto; margin-right: auto; padding-left: 1rem; border-left: 2px solid.

    starter.css
    .card { margin-left: auto; margin-right: auto; padding-left: 1rem; border-left: 2px solid; }

    Reveal the reference answer
    reference.css
    .card { margin-inline: auto; padding-inline-start: 1rem; border-inline-start: 2px solid; }

    Authored expected output: The same visual result expressed with inline-axis logical properties.

    margin-inline sets both inline margins, and padding-inline-start and border-inline-start follow the text direction.

Common misconceptions

#
  • Logical properties are only for vertical writing modes.
  • margin-inline-start always means margin-left.

Follow-up practice

#
  • html-css-22-viewport-mobile-first

Related resources

#

Your progress

#

Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.

Verification: authored. Answers and outputs on this page are authored reference material, not executed results.

© 2026 FrontendX. All rights reserved.