Menu
CoddyTech

Direction-Aware Spacing

Part of the Responsive UI Patterns section of Coddy's Tailwind CSS journey. Lesson 46 of 55.

Interfaces can use either left-to-right or right-to-left text direction. Logical spacing utilities describe inline start and end rather than fixed physical edges. ps-4 means 16px padding at inline start, and pe-2 means 8px at inline end.

<section dir="rtl" class="ps-4 pe-2 ms-3">اتجاه الورشة</section>

In the example, start is the right edge because the panel has dir="rtl". The same classes would map start to the left in an LTR panel. Logical margins use ms-* and me-* in the same way.

Use different start and end values when testing so an accidental physical left/right implementation is visible. The spacing scale does not change with direction; the physical edge receiving each value changes.

challenge icon

Challenge

Medium

Give the panel 24px padding at inline start and 12px at inline end. The same utilities must follow its supplied direction switch: left/right in LTR, then right/left in RTL. Preserve the panel text and direction behavior.

Preserve the supplied content, semantic elements and IDs. Edit the requested utility classes. Press Run preview after edits, then Check/Run code to grade the result. Supplied JavaScript is read-only.

Try it yourself

<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Interface workshop</title><link rel="stylesheet" href="./styles.css"></head><body>
<div id="panel" dir="ltr" class="w-80 px-0">Workshop directions</div><button id="flip">Change direction</button>
<script src="./controls.js"></script>
</body></html>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Responsive UI Patterns