RTL tables: column order and alignment
Build RTL tables with the intended column order, readable text and numbers, correctly pinned columns and accessible horizontal scrolling.
By Omran Khleifat, Founder of Ritla
Guide13 min read
A table can put its first column on the right and still be awkward to read in Arabic. Its notes remain left-aligned, numbers sit against inconsistent edges, and the identifying column sticks to the left when the rest of the table scrolls away.
Separate three decisions: the table's column progression, each cell's alignment, and the reading direction of values inside it. Reversing the column array to repair an alignment problem changes the data presentation without fixing the underlying CSS. Forcing the whole table LTR to protect a code repairs one value at the expense of every Arabic column.
The example here is a municipal lighting inspection table. Location identifies each row, followed by a cabinet code, measured power and inspection notes. An Arabic reader should encounter location at the right, then progress leftward through that record. The code's internal character order and the power reading remain unchanged.
Let table direction place the first column#
In a normal HTML table inheriting dir="rtl", the first cell in each source row occupies the rightmost column. The same source order begins on the left under LTR. This layout behavior was measured in Chromium 151; verify the finished table in your supported browsers too.
MDN's direction reference describes its effect on table columns and recommends HTML direction where possible. Set dir on the Arabic document or table boundary rather than relying on a stylesheet declaration that conceals the intended content direction.
Keep column definitions in semantic order: location, cabinet code, power and notes. Headers and body cells must come from that same model. Applying reverse() to both arrays can double-reverse a table already following RTL; reversing only one makes readings appear under the wrong headers.
Do not use a transform to mirror the table. It mirrors the painted text and controls too. Likewise, converting each row into a reversed flex layout discards the native table layout mechanism without supplying an equivalent header model.
Some tables have an external ordering convention, such as a scientific matrix or a document reproduced from another system. Preserve that convention when it is part of the meaning, and scope any LTR exception to the table that requires it. Arabic labels can still have their own text direction. A mixed-language cell is not, by itself, a reason to make the entire table an exception.
Keep header relationships in the markup#
Use native table elements for tabular readings. A caption identifies this particular inspection set, column headers identify fields, and row headers identify locations. Direction changes visual placement without changing those relationships.
<div class="lighting-frame" dir="rtl" lang="ar" role="region" tabindex="0" aria-labelledby="lighting-caption"> <table class="lighting-table"> <caption id="lighting-caption">قراءات إنارة الممرات</caption> <thead> <tr> <th scope="col">الموقع</th> <th scope="col">رمز الخزانة</th> <th scope="col" class="lighting-number">القدرة المقاسة (واط)</th> <th scope="col">ملاحظات الفحص</th> </tr> </thead> <tbody> <tr> <th scope="row">الممر الشرقي</th> <td><bdi dir="ltr">STL-P8-469</bdi></td> <td class="lighting-number"><bdi dir="ltr">23.80</bdi></td> <td>الغطاء مثبت، وتحتاج العدسة إلى تنظيف.</td> </tr> <tr> <th scope="row">مدخل المشتل</th> <td><bdi dir="ltr">STL-N2-753</bdi></td> <td class="lighting-number"><bdi dir="ltr">108.45</bdi></td> <td>أُزيلت الأغصان التي كانت تحجب الضوء.</td> </tr> </tbody> </table></div>W3C's tables with two headers guidance explains scope="col" and scope="row", as well as the caption's purpose. The first body cell is a header because it names the row, not merely because it will be visually pinned.
The wrapper is a named, focusable scrolling region for the wide-table implementation below. It does not replace the table's semantics. Do not add role="grid" simply because the table has a sort button or a row action. An interactive grid has an additional keyboard model, described in the WAI-ARIA grid pattern.
For grouped measurements, preserve group membership when changing visual direction. A group header's colspan counts its source columns; it does not need a reversed number. More involved spanning headers can need explicit associations rather than a simple scope on every cell. Follow W3C's irregular table headers guidance and test which headers are announced for each reading.
Align Arabic text without changing its data#
An English stylesheet can leave this rule behind:
.lighting-table th,.lighting-table td { text-align: left; }The columns follow RTL, but every location and note remains attached to the left edge of its cell. The table is not waiting for its cells to be reversed. Its text has an explicit physical alignment.
Replace that baseline with start alignment, and use logical padding:
.lighting-table th,.lighting-table td { text-align: start; vertical-align: top; padding-block: 0.75rem; padding-inline: 1rem; border-block-end: 1px solid #d1d9de;}.lighting-table caption { text-align: start; padding-block: 0.875rem;}For these RTL cells, start is the right edge. In English, it remains the left edge, preserving the original layout. MDN's text-align reference distinguishes logical start and end from physical left and right.
Header text and body text should share a deliberate alignment policy. A centered browser-default header over a start-aligned Arabic column can weaken the visual relationship even when its semantic association is correct. Set the header alignment explicitly.
Keep alignment separate from direction. text-align: start does not establish RTL, and dir="rtl" does not cancel an explicit left alignment. Inspect the computed rules on a failing cell before changing the markup around its value.
Do not expect a CSS direction rule on a col element to act like a parent rule for that column's cells. Cells belong to rows in the DOM, so CSS inheritance does not pass from the column element into them. The direction reference calls out this table-specific distinction. Apply cell classes through the column model when individual fields need alignment or token rules, rather than assuming a styled column supplies those inherited properties.
Choose a numeric alignment policy and preserve it#
Numbers need comparable edges, not an automatic copy of the prose rule. For this table, measured power is aligned to inline end, while location and notes remain at inline start:
.lighting-table .lighting-number { text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums;}This puts the numeric column's content against its left edge in Arabic and its right edge in English. Apply the same class to the numeric header so its label identifies the aligned column. That is one valid product policy; it is not a rule that every number in every Arabic table must sit on the left.
Some products retain physical right alignment for numeric comparisons in both locales. If that is the chosen convention, state it and implement it as an explicit exception. Do not alternate between physical alignment and logical alignment accidentally as individual cells acquire different direction attributes.
There is a subtle trap in setting dir="ltr" on each numeric cell: text-align: end then resolves using that cell's LTR direction, so the value moves to the right. In the example, the cell keeps the table's RTL direction while the nested bdi contains the LTR numeric token. Its alignment and its token direction remain independent.
Keep units in the column heading when every reading has the same unit. Mixing differently sized suffixes into every value makes visual comparison harder. Use consistent precision appropriate to the measurement, and distinguish a missing reading from zero rather than coercing both into the same display.
Tabular numerals request equal-width digits where the font supports them. They do not automatically align decimal separators, supply missing precision or change the number format. Test the loaded Arabic font and fallback font rather than assuming the declaration creates a feature the font lacks.
Format numbers consistently and isolate codes locally#
Choose a digit system for the measurement context and use it consistently in headers that contain values, body rows, summaries and exported previews. Arabic interfaces can use Western digits or Arabic-Indic digits according to product requirements. Switching the table to RTL is not a digit-conversion operation.
For a product that specifies Western digits and two fractional places, this formatter makes that choice explicit:
const lightingPowerFormat = new Intl.NumberFormat('ar', { numberingSystem: 'latn', minimumFractionDigits: 2, maximumFractionDigits: 2}); function formatLightingPower(watts) { return Number.isFinite(watts) ? lightingPowerFormat.format(watts) : 'غير متاح';}The renderer supplies a numeric watts value from the inspection record and places the resulting text in the cell. Keep the raw number for calculations. Intl.NumberFormat applies locale formatting; do not parse its output back into a number to sort the table.
The cabinet codes are a different category of value. They are fixed identifiers, not quantities to localize. Their Latin-leading shape is not a demonstration of a reversal bug; the bdi makes their boundary explicit so surrounding punctuation and future label changes remain scoped to the token.
If a code or note can arrive in either language, choose its local direction from the content where appropriate. Avoid dir="auto" on an entire row: one field should not determine the layout policy for all other fields. A dynamic value inside a row header should also not change the header element's direction if that element uses logical sticky positioning.
Keep deeper mixed-text handling local to the value. See bidi isolation in HTML for identifier boundaries and numbers inside RTL text for signs, grouped values and punctuation.
Scroll the table, not the document#
A comparison table may need more horizontal space than a phone provides. Give it a bounded scrolling wrapper rather than shrinking the Arabic text or hiding entire fields without an alternative.
.lighting-frame { min-inline-size: 0; max-inline-size: 100%; max-block-size: 28rem; overflow: auto;}.lighting-frame:focus-visible { outline: 2px solid #225c75; outline-offset: 3px;}.lighting-table { inline-size: 100%; min-inline-size: 58rem; border-collapse: separate; border-spacing: 0;}The minimum table width is a fixture choice to adjust to real columns. The wrapper stays within its available space while the table can be wider. If the wrapper is inside a flex or grid item whose minimum size prevents shrinking, fix that ancestor too; adding overflow to a child cannot reliably repair an already oversized page layout.
W3C's Reflow explanation recognizes content that requires a two-dimensional layout. That does not exempt the entire inspection page from fitting the viewport. Filters, instructions, pagination and row-detail text still need their own responsive layout.
The exception also does not give every individual cell unlimited horizontal space. An inspection note remains prose, so let it reflow within a usable column width. A cell containing a genuinely two-dimensional item needs its own assessment. Test enlarged text inside the table, not just whether the outer wrapper produces a scrollbar.
Test the wrapper with keyboard scrolling, touch and a trackpad. Its focus outline should remain visible, and Tab should leave it normally. MDN's overflow accessibility guidance explains the focusable, named region used here. If the design hides scrollbars, supply another understandable indication that more columns exist; a wide empty margin is not an instruction.
Keep the wrapper's direction consistent with the table unless there is a documented reason otherwise. For an RTL scroller whose content extends leftward, scrollLeft starts at zero on the right and becomes negative toward the far end. MDN documents that coordinate behavior. A positive offset copied from an English implementation cannot mean “show later columns” in both directions.
Prefer native scrolling when it meets the requirement. If adding previous/next column controls, target columns by their identity or measured position rather than reversing the data to make an offset convenient. Verify both endpoints and focused content after every movement.
Pin the identifying column to inline start#
The location column should stay visible while the reading and notes move. In English, inline start is left; in Arabic, it is right. A physical left: 0 sticky rule preserves the English edge instead of that intent.
For the existing table and wrapper, use:
.lighting-table thead th { position: sticky; inset-block-start: 0; z-index: 3; background: #edf2f5;}.lighting-table tbody th[scope="row"] { position: sticky; inset-inline-start: 0; z-index: 2; background: #fff;}.lighting-table thead th:first-child { inset-inline-start: 0; z-index: 4;}The corner header is pinned on both axes and sits above the other sticky cells. Opaque backgrounds stop scrolled readings showing through the pinned text. If rows are striped or selected, give the pinned cell the same row background instead of leaving an unrelated white rectangle.
MDN's position reference explains how sticky positioning uses its scrolling ancestor. In this example, the bounded wrapper is the scroller for both axes. Inspect ancestor overflow if a header sticks within a small nested box rather than where the design expects.
Pinning several columns requires accumulated offsets based on their actual rendered widths. A long Arabic location, a resized column or a late-loading font can make an old fixed offset overlap the next pinned column. Measure or constrain those widths deliberately, and update the offsets when the widths change. Do not hide the overlap with a larger stacking number.
On a narrow screen, a pinned location can consume nearly all the visible width. Let it wrap within an appropriate maximum, offer a compact identifying label, or disable pinning at that width. Test whether any useful portion of the moving columns remains visible.
Keep header and body geometry in agreement#
The example uses one native table, so its header and body participate in the same column layout. Some data-table libraries render a separate header table, virtualize body rows or duplicate pinned columns. Those implementations need explicit width and scroll coordination.
Test a long Arabic note after the header has already rendered. If the body expands a column while the header retains a cached English width, a reading can appear beneath the wrong label even though both tables use RTL. Recalculate shared widths after column resizing, font loading and visibility changes. Reversing header order does not repair a width mismatch.
If pinned content is duplicated, ensure only the intended representation contributes interactive controls and header associations. Two copies of the same checkbox or sorting button can create duplicate focus stops and IDs. A visual clone used for scrolling must not become another independent version of the record.
For virtualized rows, preserve row identity as records enter and leave the rendered window. Reusing a row's DOM position as its identity can attach a selection or open action to another inspection after sorting. Verify the library's accessibility behavior with its actual virtualization settings; native semantics cannot be assumed simply because its output looks like a table.
Sort values without reversing columns or meanings#
Ascending power means lower readings before higher readings in either language. RTL changes the horizontal layout, not the meaning of ascending. Sort raw data and retain the same column model.
This comparison helper takes records with numeric watts values. Missing readings remain last in both directions:
function compareLightingPower(a, b, descending = false) { const aKnown = Number.isFinite(a.watts); const bKnown = Number.isFinite(b.watts); if (!aKnown || !bKnown) { return aKnown ? -1 : bKnown ? 1 : 0; } return descending ? b.watts - a.watts : a.watts - b.watts;}The host table controller applies the comparator to its inspection records, updates the rendered rows and preserves the selected record by identity. Comparing formatted strings can put the longer reading in the wrong place, while parsing localized punctuation can produce invalid values. Neither problem needs an RTL-specific reverse operation.
Use a real button inside a sortable header and set aria-sort on the currently sorted header. W3C's sortable table example demonstrates that relationship. Its upward and downward sort indicators describe ordering along rows; they do not need horizontal mirroring.
For a server-rendered sort or filter update, preserve a useful focus destination and announce the new state according to the product's update pattern. Do not scroll the whole document sideways to reveal a regenerated header. Test missing readings, equal readings and a changed digit system independently of the visual column direction.
Keep responsive layouts and exports tied to column identity#
Automatic table layout can expand to accommodate long notes or unbroken identifiers. Fixed layout can constrain columns, but it can also clip content unless widths and overflow behavior are defined. MDN's table-layout reference explains the difference. Do not use fixed layout as a substitute for deciding which fields need room.
Let Arabic notes wrap. Keep white-space: nowrap limited to values that must remain a single token, not every table cell. If a code is too long for its allocated column, decide between scrolling, a wider column and a discoverable full-value view. Applying aggressive breaks to a copied identifier can make verification harder.
If mobile rows become cards, render real field labels with their values and preserve the record's identity. Do not rely only on CSS-generated copies of header text to establish relationships. Test the resulting reading structure with assistive technology instead of assuming a visual card conversion preserves native table navigation.
Use stable field IDs for column hiding, pinning, resizing and export. A cabinet code is the cabinet-code field whether it is physically second from the right or second from the left. Code that finds “the leftmost cell” can export a location under the wrong heading after a locale change.
Define export order explicitly. A CSV file has fields and rows, not the browser's visual RTL table layout. Keep its headers paired with the same field values, and test a round trip into the spreadsheet application your users actually use. Copying the visible table also needs a separate check from inspecting its on-screen order.
Verify relationships, alignment and scroll together#
Use the two inspection rows as a starting fixture, then add a long location, a long note, a missing reading and a long cabinet identifier. Check the Arabic and English routes at a narrow width and at increased text size.
| Check | What should remain consistent |
|---|---|
| Column progression | Location is first in the semantic model and appears at inline start |
| Header associations | Each reading retains its location and power header |
| Numeric comparison | Values share the chosen edge and precision |
| Digit formatting | One measurement context uses its chosen numbering system |
| Horizontal scrolling | The table moves inside its wrapper while the document still fits |
| Sticky intersection | The corner header remains readable over moving cells |
| Sorting | Raw readings determine order; missing-value policy stays explicit |
| Locale switch | Selection, field identities and sort state survive the layout change |
Inspect a sticky row header and its nested value separately. The header should retain the table's placement direction; the inner token can use another direction. Check a cell's computed text-align after any local dir change rather than assuming the same class resolves to the same physical edge.
For a column-order diagnosis, run this at the wrapper's initial scroll position:
const inspectionTable = document.querySelector('.lighting-table');console.table([...inspectionTable.tHead.rows[0].cells].map((cell, index) => ({ sourceIndex: index, label: cell.textContent.trim(), left: Math.round(cell.getBoundingClientRect().left)})));The source indices stay unchanged between locales. In this RTL fixture, location should occupy the rightmost header position, followed by the other fields toward the left. If that geometry is correct but a reading has the wrong header, inspect the renderer's field mapping next. This separates a direction failure from a data-binding failure that another CSS override would only conceal.
Use screen-reader table navigation to verify header relationships, and visual inspection to verify placement and clipping. A successful copy operation cannot establish that a token displayed correctly: copied text follows its source order. Similarly, correct header announcements do not prove the sticky cell is visible or that the whole page avoids overflow.
A free Ritla scan can check for text-align: left explicitly set on majority-Arabic text, , and Arabic-Indic and Western digits mixed in the same context, . If the table pushes the page sideways, continue with fixing horizontal overflow in RTL; for cell values that reorder, see numbers inside RTL text.