← Back to DevBytes

Mastering CSS Logical Properties: Tips and Best Practices

What Are CSS Logical Properties?

CSS Logical Properties are a set of CSS properties and values that describe layout, spacing, sizing, and borders in a flow-relative and writing-mode–aware way. Instead of thinking in terms of physical directions like top, right, bottom, and left, logical properties use block-start, inline-end, block-end, and inline-start.

In a typical Latin-based horizontal writing mode (left-to-right, top-to-bottom), these logical directions map to physical ones like this:

But the magic is that these mappings automatically adapt when the writing mode, direction, or text orientation changes. For example, in a right-to-left language like Arabic or Hebrew, inline-start becomes the right side, and inline-end becomes the left side. In vertical writing modes (used in some East Asian layouts), the block and inline axes rotate entirely.

Why Logical Properties Matter

🚀 Deploy your AI agent in 10 minutes

Managed Hermes hosting. Zero DevOps. 100M tokens/mo included.

Try it free →

Modern web projects are increasingly multilingual and internationalized. A design that assumes "left is always the start" will break for users of right-to-left scripts. Logical properties solve this at the CSS level, making your layouts truly direction-agnostic and reducing the need for manual overrides.

Key benefits include:

How to Use CSS Logical Properties

Basic Syntax and Mapping

Logical properties follow a predictable naming pattern. The physical property names like margin-left are replaced by margin-inline-start (for the start edge in the inline direction) or margin-block-end (for the end edge in the block direction).

Here’s a quick reference for common properties:

Inline and Block Dimensions

The two fundamental axes are:

When you set inline-size on an element, you are setting its dimension along the inline axis (width in horizontal-tb). block-size sets the dimension along the block axis (height in horizontal-tb). This becomes incredibly powerful in vertical writing modes.

Example of a box sized with logical properties:

.logical-box {
  inline-size: 300px;       /* width in horizontal-tb */
  block-size: 200px;        /* height in horizontal-tb */
  margin-block-start: 1em;  /* top margin in horizontal-tb */
  margin-inline-end: 2em;   /* right margin in horizontal-tb */
  padding-inline-start: 1rem; /* left padding in horizontal-tb */
  border-block-end: 2px solid #333; /* bottom border */
}

When the parent container switches to direction: rtl or writing-mode: vertical-rl, all these declarations automatically reorient themselves without any change to the CSS rules.

Logical Shorthand Properties

CSS also provides logical shorthand properties that mirror the physical shorthands. Instead of margin: top right bottom left, you can use:

margin-block: 1em 2em;       /* block-start block-end */
margin-inline: auto 0;        /* inline-start inline-end */

Or combine them into the all-inclusive logical shorthand margin itself? Actually, the physical margin shorthand still uses physical order (top, right, bottom, left) and does not adapt. To get full logical shorthand, use the two-axis shorthands or the newer margin-inline and margin-block.

Example using logical shorthands:

.card {
  /* Padding: block-start 2rem, block-end 2rem,
     inline-start 1.5rem, inline-end 1.5rem */
  padding-block: 2rem;
  padding-inline: 1.5rem;

  /* Borders: a thick start border in the inline direction */
  border-inline-start: 4px solid #007bff;

  /* Margin shorthand for block axis */
  margin-block: 1rem 2rem;
}

Handling Borders and Border Radii

Logical border properties include border-block-start, border-inline-end, and the corresponding -width, -style, -color longhands. You can even apply logical border-radius using the border-start-start-radius pattern.

For rounded corners, logical properties decompose the corner into start and end for each axis:

.pill-button {
  border-start-start-radius: 999px;
  border-start-end-radius: 999px;
  border-end-start-radius: 999px;
  border-end-end-radius: 999px;
  /* Alternatively, shorthand border-radius still works physically,
     but using logical ensures correct rounding for vertical scripts */
}

Overflow and Resizing

Overflow properties also get logical counterparts: overflow-inline (overflow along the inline axis) and overflow-block (overflow along the block axis). Similarly, resize can be inline, block, or the physical horizontal/vertical. Logical resize values are more predictable across writing modes.

.scroll-container {
  overflow-inline: auto;   /* horizontal scroll in LTR */
  overflow-block: hidden;  /* no vertical scroll */
  resize: block;           /* allow resizing only along block axis */
}

Positioning with Inset Properties

When absolutely positioning an element, the inset shorthand and its longhands inset-block-start, inset-inline-end, etc., replace top, right, bottom, left. This is extremely useful for components like tooltips or dropdowns that need to stay aligned with the flow start edge.

.tooltip {
  position: absolute;
  inset-block-start: 100%;      /* place below the parent in block flow */
  inset-inline-start: 0;        /* align with inline start edge */
  inline-size: max-content;
}

Best Practices for Adopting Logical Properties

1. Start with a Logical-Only Mindset in New Projects

When building a new design system or component library, default to logical properties. Use padding-inline-start instead of padding-left, border-block-end instead of border-bottom. This sets the foundation for effortless internationalization.

2. Incrementally Migrate Existing Code

You don’t have to convert an entire codebase at once. Begin by replacing physical properties in layout-critical areas: spacing, borders, and alignment on components that will be rendered in multiple languages. Use linting tools or a style guide to enforce the use of logical properties over time.

3. Combine Logical and Physical Where Necessary (But Be Deliberate)

Sometimes a physical property is genuinely intended—for example, a box shadow that must always appear at the physical bottom regardless of writing mode. In such cases, it’s fine to use physical properties. Just document why, so future developers understand it's an intentional choice, not an oversight.

4. Use the dir Attribute and :dir() Pseudo-Class Wisely

Even with logical properties, some designs may need minor adjustments for RTL or vertical layouts. The :dir(rtl) pseudo-class allows you to fine-tune without breaking the logical abstraction. For example:

.icon-button:dir(rtl) {
  /* Maybe mirror an icon or adjust spacing */
  transform: scaleX(-1);
}

5. Test Across Writing Modes and Directions

Always test your components with direction: rtl and writing-mode: vertical-rl applied to a wrapper. Use browser DevTools to simulate these modes. Logical properties handle the heavy lifting, but you'll catch edge cases like shadow offsets or transform origins that might still rely on physical assumptions.

6. Leverage CSS Custom Properties for Symmetric Spacing

For consistent spacing that works in both axes, define custom properties:

:root {
  --space-inline: 1rem;
  --space-block: 1.5rem;
}
.card {
  padding-inline: var(--space-inline);
  padding-block: var(--space-block);
}

This pattern keeps your design tokens direction-agnostic and easy to maintain.

7. Be Mindful of Logical vs. Physical Shorthands

Remember that the classic margin shorthand (margin: 1px 2px 3px 4px) is always physical and does not adapt. When you want logical shorthand, explicitly use margin-inline and margin-block. Similarly, border-radius is physical; use the logical longhands if you need flow-relative rounding.

8. Use Logical Sizing for Intrinsic and Responsive Designs

Logical sizing properties like inline-size and block-size work beautifully with fit-content, min-content, and max-content. For instance, inline-size: fit-content ensures the element sizes to its content along the inline axis, regardless of whether that axis is horizontal or vertical.

Conclusion

CSS Logical Properties represent a fundamental shift from rigid physical coordinates to flow-aware, internationalized styling. They make your CSS more expressive, reduce duplication for multilingual sites, and align perfectly with modern layout methods like Flexbox and Grid that already operate on flow-relative axes. By adopting logical properties, you’re not just future-proofing your code—you’re writing CSS that truly works for everyone, in every language and writing mode. Start small, test often, and let the browser handle the rest.

🚀 Need a reliable AI agent for your project?

Deploy Hermes Agent in 10 minutes. Managed hosting, zero DevOps.

Get Started — $23.99/mo
← Back to all articles