Sub topic 14
When to Keep Physical Values
This chapter assumes you know the box model, the writing-mode and direction properties, and the block and inline axes. It also assumes you can read the logical shorthands from earlier chapters. Here you learn the other half of the decision: some design requirements are tied to the screen, not to the text flow, and physical values are the correct choice for them.
The rule of thumb
Ask one question about each declaration: "If the text direction changed, should this move with the text or stay where it is?"
- If it should move with the text, use a logical property.
- If it must stay fixed relative to the screen, the viewport, or a physical object, use a physical one.
Logical properties are not a replacement for every physical property. They express a relationship to the content flow. Some designs have no such relationship.
Cases where physical values are correct
Layout that mirrors something physical
A drop shadow simulates a light source. If the light comes from the top left, the shadow falls to the bottom right in every language. Mirroring the shadow in right-to-left text would make the light source jump.
.panel {
box-shadow: 4px 4px 8px rgb(0 0 0 / 0.25);
}box-shadow offsets are always physical. There is no logical form, so you do not have a choice here. Be aware of this when you mirror a whole interface, because shadows will not mirror on their own.
Media and diagrams with a fixed orientation
Some content has a direction that does not depend on language:
- A line chart usually runs time from left to right, even on an Arabic page. Many designers keep it that way, because the axis is a convention of the chart.
- A map has north at the top. Its controls, such as a compass or a scale bar, may need fixed positions.
- A photo with a caption "at the left of the person" is describing the image, not the page flow.
- Playback controls on a video player often keep a fixed left-to-right order, because the timeline itself is drawn left to right.
Decide per component. Some products mirror charts for right-to-left users, and that is a design decision for your team, not something CSS decides for you.
Icons that point in a physical direction
An arrow that means "next" should point toward the end of the flow. That arrow needs to flip in right-to-left text. An icon of a physical object does not flip. A clock, a magnifying glass, or a phone handset keeps its drawing in every language. Text-direction logic therefore belongs to the meaning of the icon, not to the image file.
You can flip a "next" icon with the :dir() pseudo-class:
.icon-next:dir(rtl) {
transform: scaleX(-1);
}Here scaleX(-1) is a physical transform and it is the right tool. There is no logical transform function, so the :dir() selector supplies the flow awareness.
Transforms, gradients and background positions
These features use physical coordinates:
| Feature | Physical form | Logical equivalent |
|---|---|---|
| `transform: translateX()` | x is always screen-left to right | None |
| `linear-gradient(to right, ...)` | Physical direction keyword | None |
| `background-position: left top` | Physical keywords | None |
| `object-position` | Physical keywords | None |
| `box-shadow` offsets | Physical | None |
A gradient written to right always points to the right. If a progress bar fill should start at the inline start, a gradient is not the right tool, or you must change the direction with a :dir(rtl) rule.
.progress {
background: linear-gradient(to right, seagreen, lightgreen);
}
.progress:dir(rtl) {
background: linear-gradient(to left, seagreen, lightgreen);
}Positioning relative to the viewport or a physical anchor
A floating "chat" button fixed to the bottom right of the screen is a common pattern. Its placement may be a brand or usability decision that does not depend on language. Many sites keep it in the same corner everywhere. Others place it at the inline end, so it moves to the left in Arabic. Both are valid, but you must choose on purpose.
.chat-fab {
position: fixed;
bottom: 1rem;
right: 1rem;
}If you want it to follow the flow instead, write it logically:
.chat-fab {
position: fixed;
inset-block-end: 1rem;
inset-inline-end: 1rem;
}Scrolling and physical coordinates
Scroll offsets, such as scrollLeft in JavaScript, and properties like scroll-margin-left are physical. Logical versions exist for CSS (scroll-margin-inline-start, scroll-padding-inline), and you should use them for scroll snapping that follows the flow. But script APIs that read pixel positions remain physical. In right-to-left containers, scrollLeft is zero at the start and goes negative as you scroll toward the end in current browsers. Test any code that reads it.
Third-party and legacy constraints
You may keep physical values when:
- A vendor widget exposes only physical classes or variables.
- A design system token is named
--space-leftand renaming it would break many consumers. - The component is genuinely only ever shown in one language and orientation, and migrating gives no benefit.
In these cases, add a note in the code explaining why it is physical, so a later reader does not "fix" it.
Mixing physical and logical safely
Physical and logical properties that affect the same side share one cascade. A later declaration wins. They do not combine into a separate layer. This means the order matters:
.box {
margin-inline-start: 2rem;
margin-left: 0.5rem;
}In a left-to-right context, both rules target the left margin, so margin-left wins because it comes later. In right-to-left text, margin-inline-start applies to the right and margin-left applies to the left, so both take effect. The result differs by direction, which is the kind of bug that appears only in review of translated pages. Avoid mixing the two on the same axis in one rule. Pick one per property and side.
Deciding with a checklist
Use these questions in code review:
- Does the value describe spacing, size, alignment, or position of content relative to text? Use logical.
- Does it describe a light source, a physical object, a map, a chart axis, or a brand placement? Use physical.
- Does it flip in right-to-left text but should not? Use physical, or add a
:dir()override. - Does it stay in place but should flip? Use logical, or add a
:dir()override. - Is the property one that has no logical form, such as
box-shadow,transform, or gradient keywords? Use physical with:dir()rules where the flow matters.
A worked example
A video card has a title, a thumbnail, a progress bar, and a "next" button. The text and the button follow the language. The thumbnail overlay, shadow, and progress direction do not.
<article class="video-card" dir="rtl" lang="ar">
<img class="thumb" src="thumb.jpg" alt="">
<h2 class="title">...</h2>
<div class="progress"><span class="fill"></span></div>
<button class="next" type="button">
<svg class="icon-next" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true">
<path d="M9 5l7 7-7 7" fill="none" stroke="currentColor" stroke-width="2"/>
</svg>
</button>
</article>
<style>
.video-card {
padding-inline: 1rem;
border-inline-start: 4px solid steelblue;
box-shadow: 2px 2px 6px rgb(0 0 0 / 0.2);
}
.progress {
inline-size: 100%;
block-size: 6px;
background: #ddd;
}
.fill {
display: block;
block-size: 100%;
inline-size: 40%;
background: seagreen;
}
.icon-next:dir(rtl) {
transform: scaleX(-1);
}
</style>The card's padding and accent border follow the flow, so they sit on the right in Arabic. The shadow stays bottom right as a lighting choice. The progress fill uses inline-size, and because it is a block with no gradient, it grows from the inline start without any extra rule. The arrow icon flips because "next" points toward the end of the text.
Notice that the progress bar uses a solid background and a sized child instead of a to right gradient. When you can express a physical effect through a logical size, you avoid the extra :dir() rule.
Common mistakes
- Converting every physical property mechanically. A search and replace of
leftwithinline-startbreaks shadows, transforms, and gradients that have no flow meaning. - Forgetting that
topandbottommap to the block axis only in horizontal writing modes. Logical block sides follow the writing mode, soinset-block-startis the right edge invertical-rl. - Flipping everything in right-to-left. Mirror what carries direction (arrows, progress, navigation order) and leave physical objects alone.
- Leaving no comment on a deliberate physical value. Future maintainers will treat it as an unfinished migration.
Exercise
A site has a fixed "scroll to top" button written as position: fixed; bottom: 1rem; right: 1rem;. In Arabic (right-to-left) pages it covers the scroll bar region and the team wants it to move to the left. Which property names should you change it to, and what should you tell a teammate who asks whether box-shadow: 2px 2px 4px on the same button should change too?
Show answer
Change it to inset-block-end: 1rem; inset-inline-end: 1rem;, so the button sits at the inline end, which is the left in right-to-left text. The box-shadow should stay as it is, because it has no logical form and models a fixed light source. Mirroring the shadow would make the light seem to come from a different side in Arabic pages. If the design needs a mirrored shadow, add a :dir(rtl) rule with a negated x offset.
Exercise
A rule has margin-inline-start: 2rem; margin-left: 0.5rem;. What margins does the element get in a left-to-right page and in a right-to-left page?
Show answer
In a left-to-right page both declarations target the left margin, so the later one wins and the left margin is 0.5rem. In a right-to-left page margin-inline-start sets the right margin to 2rem and margin-left sets the left margin to 0.5rem, so both apply to different sides. Fix it by using only the logical property, or only the physical one.