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
MediumGive 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>
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Responsive UI Patterns
1Page Shells
Growing Page ShellsFlexible Content RailsBounded Scroll RegionsFull-Bleed RegionsRecap: Page Shells4Form Layouts
Responsive Field GroupsFocused Field GroupsSelectable Form OptionsNative Validation CuesRecap: Form Layouts7Intrinsic Layouts
Auto-Fitting CollectionsResilient Label RowsMulti-Line PreviewsReadable Long TokensRecap: Intrinsic Layouts10Accessible Details
Direction-Aware SpacingComfortable Control TargetsVisible Keyboard FocusUnavailable Action StatesRecap: Accessible Details2Navigation Patterns
Wrapping NavigationCurrent Page CuesNative Menu DisclosuresKeyboard Skip LinksRecap: Navigation5Data Tables
Scrollable Data TablesPredictable Table ColumnsRow State PresentationSticky Table HeadersRecap: Data Tables8Interactive Panels
Expanded Control CuesChoice Card StatesFocus-Aware Help PanelsContent-Aware Empty StatesRecap: Interactive Panels11Project: Event Portal
Portal ShellSession Browser