npm install @radix-ui/react-directionRight-to-Left (RTL) Support
Right-to-Left (RTL) is a text direction used by languages such as Arabic, Hebrew, Persian, and Urdu. The Blok design system provides automatic RTL support based on the user's browser language preference. When an RTL language is detected, the entire UI layout flips horizontally - sidebars move to the opposite side, text aligns to the right, and navigation elements flip direction. Code blocks always remain LTR for readability.
Supported RTL Languages
The following languages are automatically detected as RTL:
Note: Any language not in this list defaults to LTR (Left-to-Right).
Installation
Install the required dependency from your command line:
Direction Utilities
Create utility functions for detecting RTL languages and getting the browser language:
Direction Provider
The DirectionProvider wraps your app to provide global reading direction. It enables all Radix UI primitives to inherit the global reading direction.
API Reference
| Prop | Type | Default |
|---|---|---|
dir | "ltr" | "rtl" | No default value |
Implementation
To implement RTL support in your application, wrap your app with the DirectionProvider component:
The provider automatically detects the browser language and sets the appropriate direction. You can also use the useDirection() hook in your components to access the current direction:
How to Add RTL Support
- Install the dependency (see Installation section above)
- Create direction utilities (optional, for automatic detection):
Create a utility file to detect RTL languages and get browser language. See
src/lib/direction-utils.tsfor reference. - Wrap your app with DirectionProvider:
In your root layout, wrap your application with the DirectionProvider component (see Implementation section above).
- Use the useDirection hook:
In components that need to adapt to RTL, use the
useDirection()hook from@radix-ui/react-direction(see Examples section below).
Examples
Basic Usage
Using the Hook in Components
Keeping Code Blocks LTR
Code blocks should always remain LTR for readability: