CSS Logical Properties and Writing Modes
1. Logical vs Physical Properties (margin-inline vs margin-left)
| Physical Property | Logical Equivalent | Description | Writing Mode Impact |
|---|---|---|---|
| width | inline-size |
Dimension along inline axis | Width in LTR/RTL, height in vertical |
| height | block-size |
Dimension along block axis | Height in LTR/RTL, width in vertical |
| min-width | min-inline-size |
Minimum inline dimension | Adapts to writing mode |
| max-width | max-inline-size |
Maximum inline dimension | Adapts to writing mode |
| min-height | min-block-size |
Minimum block dimension | Adapts to writing mode |
| max-height | max-block-size |
Maximum block dimension | Adapts to writing mode |
| margin-top | margin-block-start |
Block start margin | Top in LTR, right in vertical-rl |
| margin-bottom | margin-block-end |
Block end margin | Bottom in LTR, left in vertical-rl |
| margin-left | margin-inline-start |
Inline start margin | Left in LTR, right in RTL |
| margin-right | margin-inline-end |
Inline end margin | Right in LTR, left in RTL |
| padding-top | padding-block-start |
Block start padding | Writing mode aware |
| padding-bottom | padding-block-end |
Block end padding | Writing mode aware |
| padding-left | padding-inline-start |
Inline start padding | Writing mode aware |
| padding-right | padding-inline-end |
Inline end padding | Writing mode aware |
| border-top | border-block-start |
Block start border | Writing mode aware |
| border-bottom | border-block-end |
Block end border | Writing mode aware |
| border-left | border-inline-start |
Inline start border | Writing mode aware |
| border-right | border-inline-end |
Inline end border | Writing mode aware |
| top | inset-block-start |
Block start position offset | Writing mode aware positioning |
| bottom | inset-block-end |
Block end position offset | Writing mode aware positioning |
| left | inset-inline-start |
Inline start position offset | Writing mode aware positioning |
| right | inset-inline-end |
Inline end position offset | Writing mode aware positioning |
Example: Physical vs logical properties comparison
/* Physical properties (fixed to screen directions) */
.physical {
width: 300px;
height: 200px;
margin-top: 20px;
margin-right: 10px;
margin-bottom: 20px;
margin-left: 10px;
padding-left: 15px;
border-right: 2px solid blue;
}
/* Logical properties (adapt to writing mode) */
.logical {
inline-size: 300px; /* Width in horizontal, height in vertical */
block-size: 200px; /* Height in horizontal, width in vertical */
margin-block-start: 20px; /* Top in horizontal */
margin-inline-end: 10px; /* Right in LTR, left in RTL */
margin-block-end: 20px; /* Bottom in horizontal */
margin-inline-start: 10px; /* Left in LTR, right in RTL */
padding-inline-start: 15px; /* Left padding in LTR */
border-inline-end: 2px solid blue; /* Right border in LTR */
}
/* Shorthand logical properties */
.logical-shorthand {
margin-block: 20px; /* margin-block-start and margin-block-end */
margin-inline: 10px; /* margin-inline-start and margin-inline-end */
padding-block: 15px 10px; /* start end */
padding-inline: 20px 15px; /* start end */
border-block: 2px solid red; /* Both block borders */
border-inline: 1px solid blue; /* Both inline borders */
}
/* Benefits: Works automatically with RTL/vertical */
[dir="rtl"] .logical {
/* No changes needed! margin-inline-start automatically becomes right */
}
.vertical {
writing-mode: vertical-rl;
/* Logical properties automatically adapt */
}
Example: Migration from physical to logical
/* Old: Physical properties */
.card-old {
width: 100%;
max-width: 600px;
margin-left: auto;
margin-right: auto;
padding-left: 20px;
padding-right: 20px;
border-left: 4px solid blue;
text-align: left;
}
/* New: Logical properties */
.card-new {
inline-size: 100%;
max-inline-size: 600px;
margin-inline: auto; /* Centers in both LTR and RTL */
padding-inline: 20px; /* Horizontal padding */
border-inline-start: 4px solid blue; /* Left in LTR, right in RTL */
text-align: start; /* Left in LTR, right in RTL */
}
/* Positioning with logical properties */
.positioned-old {
position: absolute;
top: 0;
right: 0;
}
.positioned-new {
position: absolute;
inset-block-start: 0; /* Top */
inset-inline-end: 0; /* Right in LTR, left in RTL */
}
/* Shorthand inset */
.overlay {
position: fixed;
inset: 0; /* All four sides (works with any writing mode) */
}
/* Specific inset values */
.positioned-complex {
inset-block: 20px 10px; /* top bottom */
inset-inline: 30px 15px; /* left right (in LTR) */
}
Note: Logical properties are essential for internationalization.
They automatically adapt to different writing modes and text directions. Use logical properties by default for
new projects. Browser support: all modern browsers (Chrome 87+, Firefox 66+, Safari 12.1+).
2. Block and Inline Directions (block-start, inline-end)
| Axis | Description | Horizontal LTR/RTL | Vertical RL/LR |
|---|---|---|---|
| Block Axis | Direction that blocks stack (paragraphs, divs) | Top to bottom (vertical) | Right to left or left to right (horizontal) |
| Inline Axis | Direction text flows within a line | Left to right or right to left (horizontal) | Top to bottom (vertical) |
| Block Start | Beginning of block axis | Top edge | Right edge (vertical-rl) or left edge (vertical-lr) |
| Block End | End of block axis | Bottom edge | Left edge (vertical-rl) or right edge (vertical-lr) |
| Inline Start | Beginning of inline axis | Left (LTR) or right (RTL) | Top edge |
| Inline End | End of inline axis | Right (LTR) or left (RTL) | Bottom edge |
Example: Understanding block and inline axes
/* Horizontal writing mode (default) */
.horizontal {
writing-mode: horizontal-tb;
/* Block axis: top → bottom (paragraphs stack vertically)
Inline axis: left → right (text flows horizontally) */
}
.horizontal-element {
margin-block: 20px; /* Top and bottom margins */
margin-inline: 10px; /* Left and right margins (in LTR) */
padding-block: 15px; /* Top and bottom padding */
padding-inline: 20px; /* Left and right padding (in LTR) */
}
/* Vertical writing mode */
.vertical-rl {
writing-mode: vertical-rl;
/* Block axis: right → left (paragraphs stack from right)
Inline axis: top → bottom (text flows downward) */
}
.vertical-element {
margin-block: 20px; /* Right and left margins (stacking direction) */
margin-inline: 10px; /* Top and bottom margins (text flow) */
inline-size: 200px; /* Height (inline = vertical) */
block-size: 300px; /* Width (block = horizontal) */
}
/* RTL (Right-to-Left) */
.rtl {
direction: rtl;
/* Block axis: still top → bottom
Inline axis: right → left (text flows from right) */
}
.rtl-element {
margin-inline-start: 20px; /* Right margin in RTL */
margin-inline-end: 10px; /* Left margin in RTL */
text-align: start; /* Aligns right in RTL */
}
/* Practical example: Sidebar layout */
.sidebar {
inline-size: 250px; /* Width (adapts to writing mode) */
padding-inline-start: 20px; /* Left padding in LTR */
border-inline-end: 1px solid #ccc; /* Right border in LTR */
}
/* This automatically works in RTL */
[dir="rtl"] .sidebar {
/* No changes needed! Properties flip automatically */
/* padding-inline-start becomes right padding */
/* border-inline-end becomes left border */
}
Example: Flexbox and Grid with logical properties
/* Flexbox with logical directions */
.flex-container {
display: flex;
flex-direction: row; /* Inline direction */
gap: 1rem;
padding-inline: 2rem; /* Horizontal padding */
padding-block: 1rem; /* Vertical padding */
}
.flex-item {
margin-inline-end: 1rem; /* Space after each item */
padding-block: 0.5rem;
}
/* Grid with logical alignment */
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 2rem;
align-items: start; /* Block-start alignment */
justify-items: start; /* Inline-start alignment */
}
.grid-item {
inline-size: 100%;
margin-block-end: 1rem;
}
/* Text alignment with logical values */
.text-content {
text-align: start; /* Left in LTR, right in RTL */
margin-inline: auto; /* Center horizontally */
max-inline-size: 65ch; /* Max width for reading */
}
.text-end {
text-align: end; /* Right in LTR, left in RTL */
}
/* Float with logical properties */
.float-start {
float: inline-start; /* float: left in LTR, right in RTL */
margin-inline-end: 1rem; /* Space after floated element */
margin-block-end: 0.5rem;
}
.float-end {
float: inline-end; /* float: right in LTR, left in RTL */
margin-inline-start: 1rem; /* Space before floated element */
}
/* Clear with logical values */
.clear-both {
clear: both; /* Still works */
}
.clear-inline-start {
clear: inline-start; /* Clear left in LTR */
}
Note: Block axis = direction elements stack (usually vertical).
Inline axis = direction text flows (usually horizontal). In vertical writing
modes, these axes rotate. Logical properties use start/end instead of left/right/top/bottom.
3. Writing Modes (writing-mode) and Text Direction (direction)
| Property | Values | Description | Use Case |
|---|---|---|---|
| writing-mode | horizontal-tb |
Horizontal top-to-bottom (default) | Most Latin scripts |
| writing-mode | vertical-rl |
Vertical right-to-left | Traditional Chinese, Japanese |
| writing-mode | vertical-lr |
Vertical left-to-right | Mongolian, some design layouts |
| direction | ltr |
Left-to-right text direction | English, most European languages |
| direction | rtl |
Right-to-left text direction | Arabic, Hebrew, Persian |
| text-orientation | mixed |
Default orientation for vertical | Mixed characters in vertical text |
| text-orientation | upright |
All characters upright | Keeping Latin text upright in vertical |
| text-orientation | sideways |
Rotate text 90° clockwise | Sideways Latin text in vertical mode |
| unicode-bidi | normal | embed | isolate |
Control bidirectional text algorithm | Mixed LTR/RTL text handling |
| text-combine-upright | none | all | digits |
Combine characters in vertical text | Horizontal numbers in vertical Japanese |
Example: Writing modes for different scripts
/* Horizontal (default - Latin scripts) */
.horizontal {
writing-mode: horizontal-tb;
direction: ltr;
}
/* Horizontal RTL (Arabic, Hebrew) */
.rtl {
writing-mode: horizontal-tb;
direction: rtl;
}
/* Vertical right-to-left (Traditional Chinese, Japanese) */
.vertical-traditional {
writing-mode: vertical-rl;
text-orientation: mixed; /* Default */
}
/* Vertical left-to-right (Mongolian) */
.vertical-mongolian {
writing-mode: vertical-lr;
}
/* Mixed content in vertical */
.vertical-mixed {
writing-mode: vertical-rl;
}
.vertical-mixed .english {
text-orientation: upright; /* Keep Latin upright */
}
/* Sideways text */
.vertical-sideways {
writing-mode: vertical-rl;
text-orientation: sideways; /* Rotate 90° */
}
/* Combining characters in vertical text */
.tate-chu-yoko {
writing-mode: vertical-rl;
}
.tate-chu-yoko .year {
text-combine-upright: all; /* 2024 displays horizontally */
}
/* Bidirectional text isolation */
.mixed-direction {
unicode-bidi: isolate;
}
/* Example: English page with Arabic section */
body {
direction: ltr;
}
.arabic-section {
direction: rtl;
unicode-bidi: isolate;
text-align: start; /* Aligns right in RTL context */
}
Example: Practical writing mode layouts
/* Vertical sidebar with horizontal main content */
.page {
display: flex;
}
.sidebar-vertical {
writing-mode: vertical-rl;
inline-size: 3rem; /* Width becomes height control */
padding-block: 1rem;
background: #f0f0f0;
}
.main-content {
flex: 1;
padding: 2rem;
}
/* Book-style vertical layout (Japanese) */
.book-page {
writing-mode: vertical-rl;
inline-size: 100%;
block-size: 100vh;
padding-block: 2rem;
padding-inline: 3rem;
column-count: 2;
column-gap: 3rem;
}
/* Decorative vertical text */
.vertical-label {
writing-mode: vertical-rl;
text-orientation: upright;
font-weight: bold;
padding-inline: 0.5rem;
background: linear-gradient(to bottom, blue, purple);
color: white;
}
/* Mixed RTL and LTR content */
.bilingual-content {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 2rem;
}
.english-column {
direction: ltr;
text-align: left;
}
.arabic-column {
direction: rtl;
text-align: right;
font-family: 'Arabic Font', sans-serif;
}
/* Responsive writing mode */
@media (max-width: 768px) {
.vertical-on-desktop {
writing-mode: horizontal-tb; /* Switch to horizontal on mobile */
}
}
/* Date formatting in vertical text */
.vertical-date {
writing-mode: vertical-rl;
}
.vertical-date .date-number {
text-combine-upright: all; /* "12" displays horizontally */
font-weight: bold;
}
Warning:
direction: rtl should usually be set via HTML dir attribute,
not CSS, for better semantics and accessibility. Use unicode-bidi: isolate for embedding
opposite-direction text. text-orientation: sideways has limited browser support.
4. International Layout Support
| Feature | Technique | Description | Example |
|---|---|---|---|
| HTML dir attribute | <html dir="rtl"> |
Set document text direction | Better than CSS direction for semantics |
| Logical properties | Use start/end instead of left/right | Automatic adaptation to text direction | margin-inline-start vs margin-left |
| CSS :dir() pseudo-class | :dir(rtl) or :dir(ltr) |
Target elements by text direction | More semantic than [dir="rtl"] |
| lang attribute | <html lang="ar"> |
Specify content language | CSS can target: :lang(ar) |
| Font selection | Language-specific fonts | Different fonts for different scripts | Arabic, CJK, Latin fonts |
| Line breaking | word-break, line-break |
Language-appropriate line breaks | Different rules for CJK vs Latin |
| Text spacing | letter-spacing, word-spacing |
Avoid in Arabic (ligatures) | Can break connected scripts |
| Quotation marks | quotes property |
Language-specific quote characters | Different for each language |
Example: Multi-language support with logical properties
<!-- HTML structure for multi-language -->
<!-- <html lang="en" dir="ltr"> -->
<!-- <html lang="ar" dir="rtl"> -->
/* Base styles with logical properties */
body {
margin: 0;
padding-inline: 2rem;
padding-block: 1rem;
}
.container {
max-inline-size: 1200px;
margin-inline: auto;
}
/* Navigation that works in any direction */
.nav {
display: flex;
gap: 1rem;
padding-inline: 2rem;
}
.nav-link {
padding-inline: 1rem;
padding-block: 0.5rem;
border-inline-start: 3px solid transparent;
}
.nav-link:hover {
border-inline-start-color: blue;
}
/* Cards with logical spacing */
.card {
padding-block: 1.5rem;
padding-inline: 2rem;
border-inline-start: 4px solid blue;
margin-block-end: 2rem;
}
.card-title {
margin-block-end: 0.5rem;
}
/* Sidebar positioning */
.layout {
display: grid;
grid-template-columns: 250px 1fr;
gap: 2rem;
}
/* Automatically flips in RTL */
.sidebar {
padding-inline-end: 2rem;
border-inline-end: 1px solid #ccc;
}
/* Text alignment */
.text-content {
text-align: start; /* Left in LTR, right in RTL */
}
.text-end-align {
text-align: end; /* Right in LTR, left in RTL */
}
/* Form inputs */
.form-field {
margin-block-end: 1rem;
}
.form-label {
display: block;
margin-block-end: 0.25rem;
text-align: start;
}
.form-input {
inline-size: 100%;
padding-block: 0.5rem;
padding-inline: 0.75rem;
border: 1px solid #ccc;
text-align: start;
}
Example: Language-specific styling
/* Using :dir() pseudo-class (modern browsers) */
:dir(ltr) .arrow {
transform: rotate(0deg); /* → */
}
:dir(rtl) .arrow {
transform: rotate(180deg); /* ← */
}
/* Using :lang() for language-specific styles */
:lang(ar) {
font-family: 'Arabic Font', sans-serif;
font-size: 1.1em; /* Arabic often needs larger size */
line-height: 1.8; /* More line height for Arabic */
}
:lang(zh) {
font-family: 'Noto Sans SC', sans-serif; /* Simplified Chinese */
word-break: break-all; /* CJK line breaking */
}
:lang(ja) {
font-family: 'Noto Sans JP', sans-serif;
line-break: strict; /* Japanese line breaking rules */
}
:lang(en) {
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
hyphens: auto; /* English hyphenation */
}
/* Quotation marks by language */
:lang(en) {
quotes: '"' '"' ''' '''; /* "English" 'quotes' */
}
:lang(fr) {
quotes: '«\00a0' '\00a0»' '"' '"'; /* « French » "quotes" */
}
:lang(de) {
quotes: '„' '"' '‚' '''; /* „German" ‚quotes' */
}
/* Blockquote with auto quotes */
blockquote::before {
content: open-quote;
}
blockquote::after {
content: close-quote;
}
/* Font stack for multi-script support */
body {
font-family:
-apple-system, /* System font (Latin) */
'Noto Sans Arabic', /* Arabic */
'Noto Sans SC', /* Simplified Chinese */
'Noto Sans JP', /* Japanese */
'Noto Sans KR', /* Korean */
sans-serif;
}
/* Avoid letter-spacing in connected scripts */
.text {
letter-spacing: 0.02em;
}
:lang(ar) .text,
:lang(fa) .text,
:lang(ur) .text {
letter-spacing: normal; /* Preserve ligatures */
}
/* Number formatting */
.number {
font-variant-numeric: tabular-nums;
}
:lang(ar) .number {
/* Arabic numerals */
font-feature-settings: 'anum' 1;
}
Example: Complete RTL/LTR adaptive layout
/* Container that works in any direction */
.page-wrapper {
inline-size: 100%;
max-inline-size: 1400px;
margin-inline: auto;
padding-inline: clamp(1rem, 5vw, 4rem);
padding-block: 2rem;
}
/* Header with logo and navigation */
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding-block: 1rem;
border-block-end: 1px solid #ccc;
}
.logo {
margin-inline-end: 2rem;
}
/* Navigation automatically flips */
.nav {
display: flex;
gap: 2rem;
}
/* Main layout with sidebar */
.main-layout {
display: grid;
grid-template-columns: 250px 1fr;
gap: 3rem;
margin-block-start: 2rem;
}
/* Sidebar starts on inline-start (left in LTR, right in RTL) */
.sidebar {
border-inline-end: 1px solid #ddd;
padding-inline-end: 2rem;
}
/* Article content */
.article {
max-inline-size: 65ch;
}
.article h2 {
margin-block: 2rem 1rem;
border-inline-start: 4px solid blue;
padding-inline-start: 1rem;
}
.article p {
margin-block-end: 1rem;
text-align: start;
}
/* Image with caption */
.figure {
margin-block: 2rem;
}
.figure img {
inline-size: 100%;
block-size: auto;
}
.caption {
margin-block-start: 0.5rem;
padding-inline-start: 1rem;
border-inline-start: 2px solid #999;
font-size: 0.9em;
color: #666;
}
/* Footer */
.footer {
margin-block-start: 4rem;
padding-block-start: 2rem;
border-block-start: 1px solid #ccc;
text-align: center;
}
/* Responsive */
@media (max-width: 768px) {
.main-layout {
grid-template-columns: 1fr;
}
.sidebar {
border-inline-end: none;
border-block-end: 1px solid #ddd;
padding-inline-end: 0;
padding-block-end: 2rem;
}
}
Note: Use
dir attribute in HTML: <html dir="rtl">. Combine with
lang attribute: <html lang="ar" dir="rtl">. Test with actual native speakers.
Use logical properties exclusively for international support.
5. Logical Sizing and Spacing Properties
| Logical Property | Physical Equivalent | Shorthand | Use Case |
|---|---|---|---|
| inline-size | width |
N/A | Element inline dimension |
| block-size | height |
N/A | Element block dimension |
| min/max-inline-size | min/max-width |
N/A | Inline dimension constraints |
| min/max-block-size | min/max-height |
N/A | Block dimension constraints |
| margin-block-start/end | margin-top/bottom |
margin-block |
Block axis margins |
| margin-inline-start/end | margin-left/right |
margin-inline |
Inline axis margins |
| padding-block-start/end | padding-top/bottom |
padding-block |
Block axis padding |
| padding-inline-start/end | padding-left/right |
padding-inline |
Inline axis padding |
| border-block-start/end | border-top/bottom |
border-block |
Block axis borders |
| border-inline-start/end | border-left/right |
border-inline |
Inline axis borders |
| inset-block-start/end | top/bottom |
inset-block |
Block axis positioning |
| inset-inline-start/end | left/right |
inset-inline |
Inline axis positioning |
Example: Logical sizing for responsive components
/* Card with logical sizing */
.card {
inline-size: 100%;
max-inline-size: 400px;
min-block-size: 200px;
margin-block-end: 2rem;
padding-block: 1.5rem;
padding-inline: 2rem;
border: 1px solid #ddd;
border-inline-start-width: 4px;
border-inline-start-color: blue;
}
/* Sidebar with logical dimensions */
.sidebar {
inline-size: 250px;
min-block-size: 100vh;
padding-block: 2rem;
padding-inline: 1.5rem;
border-inline-end: 1px solid #ccc;
}
/* Container with logical spacing */
.container {
inline-size: 100%;
max-inline-size: 1200px;
margin-inline: auto;
padding-inline: clamp(1rem, 5vw, 3rem);
padding-block: 2rem;
}
/* Grid items with logical spacing */
.grid-item {
padding-block: 1rem;
padding-inline: 1.5rem;
margin-block-end: 1rem;
border-block-end: 1px solid #eee;
}
/* Button with logical padding */
.button {
padding-block: 0.75rem;
padding-inline: 2rem;
border: none;
border-radius: 0.25rem;
min-inline-size: 120px;
}
/* Input fields */
.input {
inline-size: 100%;
max-inline-size: 400px;
padding-block: 0.5rem;
padding-inline: 1rem;
border: 1px solid #ccc;
margin-block-end: 1rem;
}
Example: Logical shorthand properties
/* Margin shorthands */
.element {
/* Two values: block inline */
margin-block: 2rem; /* margin-block-start and end */
margin-inline: 1rem; /* margin-inline-start and end */
/* Individual values */
margin-block: 2rem 1rem; /* start end */
margin-inline: 1.5rem 1rem; /* start end */
}
/* Padding shorthands */
.box {
padding-block: 1.5rem; /* Same start and end */
padding-inline: 2rem; /* Same start and end */
padding-block: 2rem 1rem; /* Different start and end */
padding-inline: 2.5rem 1.5rem;
}
/* Border shorthands */
.bordered {
/* All border properties */
border-block: 2px solid blue; /* Both block borders */
border-inline: 1px solid gray; /* Both inline borders */
/* Individual sides */
border-block-start: 3px solid red;
border-inline-end: 2px dashed green;
/* Width only */
border-block-width: 2px;
border-inline-width: 1px 3px; /* start end */
/* Color only */
border-block-color: blue;
border-inline-color: red green; /* start end */
/* Style only */
border-block-style: solid;
border-inline-style: dashed;
}
/* Inset shorthands (positioning) */
.positioned {
position: absolute;
/* Two values: block inline */
inset-block: 0; /* top and bottom = 0 */
inset-inline: 20px; /* left and right = 20px (in LTR) */
/* Different values */
inset-block: 10px 20px; /* start=10px, end=20px */
inset-inline: 0 auto; /* start=0, end=auto */
/* All four sides */
inset: 0; /* All sides = 0 */
inset: 10px 20px; /* block inline */
inset: 10px 20px 30px 40px; /* top right bottom left */
}
/* Border-radius with logical properties */
.rounded {
/* Logical corner properties */
border-start-start-radius: 8px; /* Top-left in LTR */
border-start-end-radius: 8px; /* Top-right in LTR */
border-end-start-radius: 0; /* Bottom-left in LTR */
border-end-end-radius: 0; /* Bottom-right in LTR */
}
/* Scroll padding (logical) */
.scroll-container {
scroll-padding-block: 2rem;
scroll-padding-inline: 1rem;
scroll-padding-block-start: 100px;
scroll-padding-inline-end: 50px;
}
Example: Complete layout with logical properties
/* Page layout system */
.page {
min-block-size: 100vh;
display: flex;
flex-direction: column;
}
/* Header */
.header {
inline-size: 100%;
padding-block: 1rem;
padding-inline: 2rem;
border-block-end: 1px solid #ddd;
display: flex;
justify-content: space-between;
}
.logo {
inline-size: 150px;
block-size: 40px;
}
/* Main content area */
.main {
flex: 1;
display: grid;
grid-template-columns: 250px 1fr 300px;
gap: 2rem;
padding-inline: 2rem;
padding-block: 2rem;
}
/* Sidebar start (left in LTR, right in RTL) */
.sidebar-start {
padding-inline-end: 2rem;
border-inline-end: 1px solid #eee;
}
.sidebar-start nav {
position: sticky;
inset-block-start: 2rem;
}
.sidebar-start a {
display: block;
padding-block: 0.5rem;
padding-inline-start: 1rem;
margin-block-end: 0.25rem;
border-inline-start: 3px solid transparent;
}
.sidebar-start a:hover {
border-inline-start-color: blue;
background: #f5f5f5;
}
/* Content area */
.content {
max-inline-size: 800px;
}
.content h1 {
margin-block-end: 1.5rem;
padding-block-end: 0.5rem;
border-block-end: 2px solid #333;
}
.content p {
margin-block-end: 1rem;
line-height: 1.6;
}
.content blockquote {
margin-block: 2rem;
margin-inline-start: 2rem;
padding-inline-start: 1.5rem;
border-inline-start: 4px solid #0066cc;
font-style: italic;
}
/* Sidebar end (right in LTR, left in RTL) */
.sidebar-end {
padding-inline-start: 2rem;
border-inline-start: 1px solid #eee;
}
.widget {
margin-block-end: 2rem;
padding-block: 1rem;
padding-inline: 1.5rem;
background: #f9f9f9;
border-inline-start: 3px solid #0066cc;
}
/* Footer */
.footer {
inline-size: 100%;
margin-block-start: auto;
padding-block: 2rem;
padding-inline: 2rem;
border-block-start: 1px solid #ddd;
text-align: center;
}
/* Responsive */
@media (max-width: 1024px) {
.main {
grid-template-columns: 1fr;
}
.sidebar-start,
.sidebar-end {
border: none;
padding: 0;
margin-block-end: 2rem;
}
}
Logical Properties Best Practices
- Use logical properties by default for all new projects
- Replace physical properties during refactoring for i18n support
inline-size= width (horizontal),block-size= height (horizontal)start= left (LTR), right (RTL);end= right (LTR), left (RTL)- Use shorthands:
margin-block,padding-inline,border-block - Set
dirin HTML, not CSS:<html dir="rtl"> - Use
text-align: start/endinstead of left/right - Test with actual RTL languages (Arabic, Hebrew) and vertical writing modes
- Browser support is excellent: all modern browsers (IE11 requires fallbacks)
- Combine with container queries for fully adaptive components