Sub topic 15
Testing with dir=rtl and vertical writing modes
This chapter assumes you know the box model, the lang and dir attributes, and the logical properties from earlier chapters: inline-size, margin-inline, padding-block, inset-inline-end, and the start and end values.
Why test by flipping
A stylesheet that uses logical properties should adapt when the writing mode or direction changes. You can't know that until you try it. Leftover physical properties, hard-coded left values, and icons that point the wrong way only show up when the layout flips.
You don't need translated content to test. Changing two attributes or one property is enough.
Test right-to-left
Set dir="rtl" on the <html> element. The dir attribute changes the inline direction. In a horizontal writing mode, that moves inline-start from the left edge to the right edge.
<!doctype html>
<html lang="ar" dir="rtl">
<head>
<meta charset="utf-8">
<title>RTL test</title>
<style>
.note {
padding-inline-start: 2rem;
border-inline-start: 3px solid tomato;
text-align: start;
}
</style>
</head>
<body>
<p class="note">Test paragraph</p>
</body>
</html>The border and padding now appear on the right. To compare both directions on one page, put two elements side by side, one with dir="ltr" and one with dir="rtl", and apply the same class to both.
You can also toggle the direction from the browser's developer tools by editing the dir attribute on <html>. This is the fastest check.
Test vertical writing modes
Add writing-mode to the element or to <html>. The value vertical-rl makes lines run top to bottom, with new lines stacking from right to left.
.vertical {
writing-mode: vertical-rl;
inline-size: 20rem;
block-size: 10rem;
}Here inline-size sets the height (20rem) and block-size sets the width (10rem). A physical width or height would not follow the text.
What to look for
| Symptom | Likely cause |
|---|---|
| Spacing or a border stays on the left in RTL | `margin-left`, `padding-left` or `border-left` |
| Text stays left-aligned in RTL | `text-align: left` instead of `start` |
| A floated image keeps its side | `float: left` instead of `inline-start` |
| A badge stays in the top right | `top` and `right` instead of `inset-block-start` and `inset-inline-end` |
| Content is clipped in vertical mode | `height` or `width` fixed with physical properties |
Check what should not flip
Some things stay the same by design. Images, logos, and a map that must face north keep their physical orientation. Directional icons such as arrows usually should flip, so check each one. A flipped icon is not a bug if the meaning follows the reading direction.
Exercise
You set dir="rtl" on the html element. A card still has its accent border on the left. Which property is probably responsible, and what replaces it?
Show answer
The card likely uses border-left. Replace it with border-inline-start, which moves to the right side in RTL text.
Exercise
In a block with writing-mode: vertical-rl, you set inline-size: 20rem and block-size: 10rem. What are the box's visible width and height?
Show answer
The width is 10rem and the height is 20rem. In vertical writing modes, the inline axis runs top to bottom, so inline-size sets the height and block-size sets the width.