International component project
Definition and purpose
Build one message component that works in both LTR and RTL without duplicating its CSS. Semantic direction belongs in HTML, while logical CSS controls layout and spacing.
RTL message with leading accent
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; } #a, #b { background: lightblue; } #p { display: flex; width: 240px; gap: 10px; border-inline-start: 4px solid navy; } #a,#b { box-sizing: border-box; width: 60px; } #b { margin-inline-start: auto; } </style> </head> <body> <div id="p" lang="fa" dir="rtl"> <span id="a">پیام جدید</span> <button id="b">باز کردن</button> </div> </body></html>The message starts on the right, and the action moves to the left.
Syntax and mental model
Combine display: flex, a gap, margin-inline-start: auto on the final action, padding-inline and a leading logical border. Flex rows follow the inline direction. Keep the message before its action in the DOM for both languages and allow wrapping when content grows.
Same CSS in LTR
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; } #a, #b { background: lightblue; } #p { display: flex; width: 240px; gap: 10px; border-inline-start: 4px solid navy; } #a,#b { box-sizing: border-box; width: 60px; } #b { margin-inline-start: auto; } </style> </head> <body> <div id="p" lang="en" dir="ltr"> <span id="a">Message</span> <button id="b">Open</button> </div> </body></html>Only the HTML direction and language change; the logical rules mirror the component.
Common mistakes
Do not solve RTL by reversing the DOM or forcing physical offsets. Avoid fixed text widths for real translations; the fixed sizes here only make the geometry exercise predictable.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Bidirectional text and Persian UI. Next lesson: Native inputs and buttons.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
International component project — knowledge check
Five questions on international component project.
Where should semantic language direction be declared?
Which margin pushes a final flex action toward inline-end?
Should DOM order change when switching language?
Which border adapts to leading direction?
How should long translated labels be accommodated?