Skip to main content
Direction provides a context provider and hook for managing text direction throughout your application. This is essential for supporting right-to-left (RTL) languages like Arabic, Hebrew, and Persian.

Installation

Components

DirectionProvider

A context provider that sets the text direction for all descendants.

Hooks

useDirection

Returns the current text direction from context, with optional local override.

Usage

Basic Setup

Using the Hook

Local Direction Override

Conditional Styling Based on Direction

Multi-language Support

Keyboard Navigation

Nested Direction Contexts

Type Definitions

Default Behavior

  • If no DirectionProvider is present, useDirection() returns 'ltr' by default
  • A local dir prop passed to useDirection(dir) takes precedence over context
  • Direction context can be nested, with inner providers overriding outer ones

Notes

Remember to also set the dir attribute on your HTML elements when using this provider. The provider manages the logical direction in JavaScript, but CSS and HTML need the dir attribute for proper text rendering.
Many Radix UI primitives automatically respect the direction context for keyboard navigation and layout positioning. Check individual component documentation for direction-aware features.
For proper RTL support, you should also use CSS logical properties (like padding-inline-start instead of padding-left) where possible.