KodingKaro
CSS · Advanced · Advanced Responsive Design

Logical properties and writing modes

A robust responsive interface should work when content direction or writing mode changes, not only when the viewport becomes narrow.

✓ What you will learn in this topic

  • Explain the key idea: Use logical properties for direction-aware spacing and positioning.
  • Apply the concept: Spacing and the accent edge follow the page’s inline and block directions.
  • Avoid this common mistake:

Concept explanation

Physical properties such as margin-left always refer to the left edge. Logical properties such as margin-inline-start refer to the start of the inline direction. padding-block and inset-inline-end express meaning that can adapt to right-to-left or vertical writing modes.

Use logical properties for component spacing and positioning unless the design truly depends on a physical edge. Test translated copy because strings can be much longer than their source language.

Syntax

A CSS rule has a selector followed by declarations. Each declaration is a property and a value; the braces group the declarations that apply to matching elements.

.demo {
  padding-inline: 1rem;
  margin-block: 1.5rem;
  border-inline-start: 0.25rem solid #2563eb;
}

Example 1: a small page element

Use this HTML as the target and place the CSS in a stylesheet linked to the page, or inside a <style> element while experimenting.

<main class="demo card-grid course-grid dashboard-panel course-card-list dashboard-grid card-layout"><h2>Learning card</h2><p>Clear styles make this information easier to scan.</p><nav class="site-nav"><a href="/learn">Courses</a></nav><label class="form-field"><span>Email</span><input type="email" aria-invalid="true"></label><article class="card course-card dashboard-card theme-dark"><span class="badge status">New</span><div class="course-card__image"></div><h2 class="course-card__title card__title">Course update</h2><p class="status">New lessons are available this week.</p><a href="/learn" aria-current="page">Read the details</a><div class="actions course-card__actions dashboard-panel__actions"><button type="button">View lessons</button><button type="button" disabled>Unavailable</button></div></article></main>
.demo {
  padding-inline: 1rem;
  margin-block: 1.5rem;
  border-inline-start: 0.25rem solid #2563eb;
}

Expected result: Spacing and the accent edge follow the page’s inline and block directions.

Example 2: a practical interface card

The same idea can style a reusable card on a course page. The class selector keeps the rule attached to this component rather than changing every element of that type.

<section class="demo card-grid course-grid dashboard-panel course-card-list dashboard-grid card-layout"><h2>Learning card</h2><p>Clear styles make this information easier to scan.</p><nav class="site-nav"><a href="/learn">Courses</a></nav><label class="form-field"><span>Email</span><input type="email" aria-invalid="true"></label><article class="card course-card dashboard-card theme-dark"><span class="badge status">New</span><div class="course-card__image"></div><h2 class="course-card__title card__title">Course update</h2><p class="status">New lessons are available this week.</p><a href="/learn" aria-current="page">Read the details</a><div class="actions course-card__actions dashboard-panel__actions"><button type="button">View lessons</button><button type="button" disabled>Unavailable</button></div></article></section>
.card__icon {
  margin-inline-end: 1rem;
}
.card__badge {
  inset-block-start: 1rem;
  inset-inline-end: 1rem;
}

Expected result: The course update reads as a distinct interface card, and its content follows the spacing, color, and layout choices in the rule.

Common mistake

Treating responsive design as viewport width alone and ignoring motion, contrast, writing direction, and zoom.

Best practice

Test real content and user preferences, use logical properties, and avoid hiding information to fit a layout.

Practice exercise

Review a responsive page in a narrow viewport, at high zoom, with reduced motion, and with right-to-left text. Apply it to the example above and inspect the result at a narrow and a wide viewport.

Section summary

  • Use logical properties for direction-aware spacing and positioning.
  • Test real content and user preferences, use logical properties, and avoid hiding information to fit a layout.

Knowledge check

What is the advantage of margin-inline over margin-left?

Reveal the explanation

Logical properties express start/end and block/inline relationships.

Finish the module lessons, then take the server-scored module quiz to check your understanding.

Practical example

css
.demo {
  padding-inline: 1rem;
  margin-block: 1.5rem;
  border-inline-start: 0.25rem solid #2563eb;
}

Expected result:

Spacing and the accent edge follow the page’s inline and block directions.

Hands-on practice task

Review a responsive page in a narrow viewport, at high zoom, with reduced motion, and with right-to-left text.

In this section

Other lessons in Advanced Responsive Design

Broaden your knowledge

Related learning topics