---
title: "setTextDirection command"
description: "Set text direction for nodes with the setTextDirection command. Control LTR, RTL, and auto direction for proper bidirectional text rendering."
canonical_url: "https://tiptap.dev/docs/editor/api/commands/nodes-and-marks/set-text-direction"
---

# setTextDirection command

Set text direction for nodes with the setTextDirection command. Control LTR, RTL, and auto direction for proper bidirectional text rendering.

The `setTextDirection` command sets the text direction for nodes at the current selection or at a specified position. This is useful for controlling the direction of right-to-left (RTL) languages like Arabic and Hebrew, or for bidirectional text content.

See also: [unsetTextDirection](https://tiptap.dev/docs/editor/api/commands/nodes-and-marks/unset-text-direction.md)

## Parameters

### direction

The text direction to set. Can be `'ltr'` (left-to-right), `'rtl'` (right-to-left), or `'auto'` (automatically detect based on content).

### position

Optional. The position or range where the direction should be applied. If not provided, the command will use the current selection.

Can be:

- A number representing a specific position
- An object with `from` and `to` properties representing a range

## Examples

```js
// Set RTL direction on current selection
editor.commands.setTextDirection('rtl')

// Set LTR direction on current selection
editor.commands.setTextDirection('ltr')

// Set auto direction on current selection
editor.commands.setTextDirection('auto')

// Set direction on a specific position
editor.commands.setTextDirection('rtl', 5)

// Set direction on a specific range
editor.commands.setTextDirection('ltr', { from: 0, to: 10 })

// Chain with other commands
editor.chain().focus().setTextDirection('rtl').run()
```
