Propiedades lógicas
Lección 25 de 37 · 4 min
margin-left dice dónde, pero no por qué. margin-inline-start dice «donde empieza la línea», y eso sigue siendo cierto en árabe, en hebreo o en japonés vertical.
Modo de escritura y dirección
Dos cosas definen cómo fluye el texto. writing-mode elige si las líneas son horizontales o verticales, y hacia dónde se apilan. La dirección elige de qué lado empieza cada línea: izquierda a derecha (ltr) o derecha a izquierda (rtl).
/* el valor inicial */.parrafo { writing-mode: horizontal-tb; }/* columnas que se apilan hacia la izquierda */.japones { writing-mode: vertical-rl; }/* columnas que se apilan hacia la derecha */.mongol { writing-mode: vertical-lr; }
La dirección va en el HTML, con el atributo dir, no en CSS. Es parte del contenido: un texto en árabe es de derecha a izquierda aunque no cargue la hoja de estilos. La propiedad direction existe, pero queda para casos raros. Para texto que escribe la gente (comentarios, nombres), dir="auto" deja que el navegador lo deduzca del primer carácter fuerte.
<html lang="ar" dir="rtl">…<p dir="auto">{comentario del usuario}</p></html>
Inline y block
Las propiedades lógicas no hablan de arriba ni de izquierda, sino de dos ejes. El eje inline es por donde corre una línea de texto. El eje block es hacia donde se apilan los párrafos. Cada eje tiene un comienzo (start) y un final (end).
- Español
ltrInline va de izquierda a derecha y block de arriba hacia abajo:inline-startes la izquierda. - Árabe
rtlInline va de derecha a izquierda:inline-startes la derecha. - Japonés vertical
vertical-rlInline va de arriba hacia abajo y block de derecha a izquierda:inline-startes arriba yblock-startes la derecha.
Abajo hay una cartela de museo escrita dos veces: con propiedades físicas y con lógicas. Pasá a físicas en árabe: el borde de color y el relleno quedan a la izquierda, del lado donde las líneas terminan, y el número de sala se pisa con el título. Con lógicas, todo cambia de lado solo. La franja naranja marca dónde cae el relleno.
Cartela de museo con propiedades lógicas. Las líneas empiezan a la derecha; el relleno de 20px y el borde de color quedan a la derecha.

الموجة العظيمة قبالة كاناغاوا
كاتسوشيكا هوكوساي، نحو ١٨٣١
طباعة بالقوالب الخشبية. موجة عملاقة وجبل فوجي في الخلفية.
/* <figure class="cartela" dir="rtl" lang="ar"> */.cartela {position: relative;inline-size: 13rem;padding-block: 16px;padding-inline-start: 20px;padding-inline-end: 16px;border-inline-start: 3px solid;border-start-end-radius: 12px;text-align: start;}.cartela-sala {position: absolute;inset-block-start: 12px;inset-inline-end: 12px;}.cartela-titulo {margin-inline-end: 56px;}.cartela-texto {margin-block-start: 12px;}
<figure lang="ar" dir="rtl" class="relative inline-52 py-4 ps-5 pe-4 border-s-3 rounded-se-xl text-start"><span class="absolute inset-bs-3 end-3">القاعة ٤</span><p class="me-14">الموجة العظيمة قبالة كاناغاوا</p><p>كاتسوشيكا هوكوساي، نحو ١٨٣١</p><p class="mbs-3">طباعة بالقوالب الخشبية. موجة عملاقة وجبل فوجي في الخلفية.</p></figure>
De físico a lógico
Cada propiedad física tiene su par lógico. En una página en español, horizontal y de izquierda a derecha, se comportan igual: cambiar una por la otra no mueve nada. La diferencia aparece cuando cambia el idioma.
| Física | Lógica |
|---|---|
| width · height | inline-size · block-size |
| margin-left | margin-inline-start |
| margin-top | margin-block-start |
| top · left | inset-block-start · inset-inline-start |
| border-top-left-radius | border-start-start-radius |
| text-align: left | text-align: start |
| float: left | float: inline-start |
Lo mismo con padding y border. Los atajos lógicos toman uno o dos valores, primero el comienzo y después el final. Ojo: los atajos de cuatro valores (margin, padding, inset) siguen siendo físicos.
.nota {margin-block: 24px; /* arriba y abajo en horizontal */padding-inline: 20px 16px; /* 20px al comienzo, 16px al final */border-inline-start: 3px solid;inset-inline: 0; /* left: 0 y right: 0 */}
Las propiedades lógicas son Baseline ampliamente disponible: Chrome 89, Firefox 66 y Safari 15 ya tienen todas, incluidos los radios como border-start-start-radius. Se pueden usar sin respaldo.
Layouts de derecha a izquierda
Con dir="rtl" en el <html>, flexbox y grid ya se dan vuelta: flex-direction: row empieza en el comienzo de la línea, que ahora es la derecha. Lo que no se da vuelta es lo físico: left, margin-right y las transformaciones (translate no tiene versión lógica).
Los íconos que señalan una dirección (una flecha de «siguiente», un chevrón) tienen que espejarse. El selector :dir(rtl) lee la dirección que hereda el elemento, sea cual sea el ancestro que la define. Es Baseline ampliamente disponible desde junio de 2026 (Chrome 120, Firefox 49, Safari 16.4).
.icono-siguiente:dir(rtl) {scale: -1 1; /* espejo horizontal */}/* en lugar de un margen fijo a la izquierda */.lista li { margin-inline-start: 1.5em; }
Texto vertical
En japonés o chino, vertical-rl es la forma normal de escribir. En un layout latino sirve para rótulos: el lomo de un libro, el encabezado de una columna angosta. Ahí las letras se acuestan; text-orientation: upright las para una debajo de otra, y text-combine-upright: all mete un número corto en un solo espacio.
.lomo {writing-mode: vertical-rl;inline-size: 12rem; /* ahora es el alto */padding-block: 8px; /* ahora son los costados */}.fecha-vertical { text-combine-upright: all; } /* «12» queda derecho */
Para un rótulo que se lea de abajo hacia arriba existe writing-mode: sideways-lr. Es Baseline recién disponible (desde marzo de 2025: Chrome 132, Firefox 43, Safari 18.4), así que en navegadores viejos el rótulo queda horizontal: ponelo solo si eso no rompe nada.
En Tailwind
En Tailwind v4 px-*, py-*, mx-* y my-* ya son lógicas: escriben padding-inline, padding-block, margin-inline y margin-block. Para un solo lado, las clases llevan s (start) y e (end). Esta lista es de Tailwind 4.3, la versión del curso.
| CSS | Tailwind |
|---|---|
| margin-inline-start | ms-4 |
| padding-inline-end | pe-4 |
| margin-block-start | mbs-4 |
| inset-inline-start: 0 | start-0 |
| inline-size · block-size | inline-52 · block-32 |
| border-inline-start | border-s-3 |
| border-start-end-radius | rounded-se-xl |
| text-align: start | text-start |
| writing-mode: vertical-rl | [writing-mode:vertical-rl] |
| :dir(rtl) · :dir(ltr) | rtl: · ltr: |
<aside dir="rtl"class="ms-4 border-s-3 ps-5 pe-4 py-4 rounded-se-xl text-start">…</aside><svg class="size-4 rtl:-scale-x-100">…</svg>
Logical properties
Lesson 25 of 37 · 4 min
margin-left says where, not why. margin-inline-start says "where the line begins", and that stays true in Arabic, Hebrew or vertical Japanese.
Writing mode and direction
Two things decide how text flows. writing-mode picks horizontal or vertical lines, and which way they stack. The direction picks which side each line starts on: left to right (ltr) or right to left (rtl).
/* the initial value */.paragraph { writing-mode: horizontal-tb; }/* columns stack towards the left */.japanese { writing-mode: vertical-rl; }/* columns stack towards the right */.mongolian { writing-mode: vertical-lr; }
Direction belongs in the HTML, in the dir attribute, not in CSS. It's part of the content: Arabic text runs right to left even if the stylesheet never loads. The direction property exists, but it's for edge cases. For text people type (comments, names), dir="auto" lets the browser work it out from the first strong character.
<html lang="ar" dir="rtl">…<p dir="auto">{user comment}</p></html>
Inline and block
Logical properties don't talk about top or left; they talk about two axes. The inline axis is the way a line of text runs. The block axis is the way paragraphs stack. Each has a start and an end.
- English
ltrInline runs left to right and block top to bottom:inline-startis the left. - Arabic
rtlInline runs right to left:inline-startis the right. - Vertical Japanese
vertical-rlInline runs top to bottom and block right to left:inline-startis the top andblock-startis the right.
Below is a museum wall label written twice, with physical and with logical properties. Switch to physical in Arabic: the accent border and the padding stay on the left, where the lines end, and the room number collides with the title. With logical properties everything changes sides by itself. The orange band shows where the padding lands.
Museum wall label with logical properties. Lines start on the right; the 20px padding and the accent border sit on the right.

الموجة العظيمة قبالة كاناغاوا
كاتسوشيكا هوكوساي، نحو ١٨٣١
طباعة بالقوالب الخشبية. موجة عملاقة وجبل فوجي في الخلفية.
/* <figure class="label" dir="rtl" lang="ar"> */.label {position: relative;inline-size: 13rem;padding-block: 16px;padding-inline-start: 20px;padding-inline-end: 16px;border-inline-start: 3px solid;border-start-end-radius: 12px;text-align: start;}.label-room {position: absolute;inset-block-start: 12px;inset-inline-end: 12px;}.label-title {margin-inline-end: 56px;}.label-text {margin-block-start: 12px;}
<figure lang="ar" dir="rtl" class="relative inline-52 py-4 ps-5 pe-4 border-s-3 rounded-se-xl text-start"><span class="absolute inset-bs-3 end-3">القاعة ٤</span><p class="me-14">الموجة العظيمة قبالة كاناغاوا</p><p>كاتسوشيكا هوكوساي، نحو ١٨٣١</p><p class="mbs-3">طباعة بالقوالب الخشبية. موجة عملاقة وجبل فوجي في الخلفية.</p></figure>
From physical to logical
Every physical property has a logical twin. On an English page, horizontal and left to right, both behave the same: swapping one for the other moves nothing. The difference shows up when the language changes.
| Physical | Logical |
|---|---|
| width · height | inline-size · block-size |
| margin-left | margin-inline-start |
| margin-top | margin-block-start |
| top · left | inset-block-start · inset-inline-start |
| border-top-left-radius | border-start-start-radius |
| text-align: left | text-align: start |
| float: left | float: inline-start |
Same for padding and border. The logical shorthands take one or two values, start first and end second. Careful: the four-value shorthands (margin, padding, inset) are still physical.
.note {margin-block: 24px; /* top and bottom when horizontal */padding-inline: 20px 16px; /* 20px at the start, 16px at the end */border-inline-start: 3px solid;inset-inline: 0; /* left: 0 and right: 0 */}
Logical properties are Baseline widely available: Chrome 89, Firefox 66 and Safari 15 support all of them, corner radii like border-start-start-radius included. No fallback needed.
Right-to-left layouts
With dir="rtl" on <html>, flexbox and grid flip on their own: flex-direction: row begins at the start of the line, which is now the right. What doesn't flip is anything physical: left, margin-right and transforms (translate has no logical version).
Icons that point somewhere (a "next" arrow, a chevron) need mirroring. The :dir(rtl) selector reads the direction the element inherits, wherever an ancestor sets it. It has been Baseline widely available since June 2026 (Chrome 120, Firefox 49, Safari 16.4).
.next-icon:dir(rtl) {scale: -1 1; /* horizontal mirror */}/* instead of a fixed left margin */.list li { margin-inline-start: 1.5em; }
Vertical text
In Japanese or Chinese, vertical-rl is simply how text is written. In a Latin layout it's for labels: a book spine, the header of a narrow column. There the letters lie on their side; text-orientation: upright stands them one under the other, and text-combine-upright: all squeezes a short number into one slot.
.spine {writing-mode: vertical-rl;inline-size: 12rem; /* now the height */padding-block: 8px; /* now the sides */}.vertical-date { text-combine-upright: all; } /* "12" stays upright */
For a label that reads bottom to top there's writing-mode: sideways-lr. It's Baseline newly available (since March 2025: Chrome 132, Firefox 43, Safari 18.4), so older browsers lay the label out horizontally: use it only where that doesn't break anything.
In Tailwind
In Tailwind v4, px-*, py-*, mx-* and my-* are already logical: they write padding-inline, padding-block, margin-inline and margin-block. For a single side, classes use s (start) and e (end). This list is from Tailwind 4.3, the version the course uses.
| CSS | Tailwind |
|---|---|
| margin-inline-start | ms-4 |
| padding-inline-end | pe-4 |
| margin-block-start | mbs-4 |
| inset-inline-start: 0 | start-0 |
| inline-size · block-size | inline-52 · block-32 |
| border-inline-start | border-s-3 |
| border-start-end-radius | rounded-se-xl |
| text-align: start | text-start |
| writing-mode: vertical-rl | [writing-mode:vertical-rl] |
| :dir(rtl) · :dir(ltr) | rtl: · ltr: |
<aside dir="rtl"class="ms-4 border-s-3 ps-5 pe-4 py-4 rounded-se-xl text-start">…</aside><svg class="size-4 rtl:-scale-x-100">…</svg>