---
title: "TextAlign extension"
description: "Left, right, center, whatever! Align the text however you like with the Text Align extension. More in the docs!"
---

> This page is for Tiptap 2.x. [See the latest version of this page.](https://tiptap.dev/docs/editor/extensions/functionality/textalign.md)

# TextAlign extension

Left, right, center, whatever! Align the text however you like with the Text Align extension. More in the docs!

This extension adds a text align attribute to a specified list of nodes. The attribute is used to align the text.

> **Firefox bug**
>
> `text-align: justify` doesn’t work together with `white-space: pre-wrap` in Firefox, [that’s a
> known issue](https://bugzilla.mozilla.org/show_bug.cgi?id=1253840).

> **Interactive demo:** [TextAlign](https://v2--tiptap-embed.netlify.app/preview/Extensions/TextAlign)

## Install

```bash
npm install @tiptap/extension-text-align
```

## Settings

### types

A list of nodes where the text align attribute should be applied to. Usually something like `['heading', 'paragraph']`.

Default: `[]`

```js
TextAlign.configure({
  types: ['heading', 'paragraph'],
})
```

### alignments

A list of available options for the text align attribute.

Default: `['left', 'center', 'right', 'justify']`

```js
TextAlign.configure({
  alignments: ['left', 'right'],
})
```

### defaultAlignment

The default text align.

Default: `null`

```js
TextAlign.configure({
  defaultAlignment: 'right',
})
```

## Commands

### setTextAlign()

Set the text align to the specified value.

```js
editor.commands.setTextAlign('right')
```

### unsetTextAlign()

Remove the text align value.

```js
editor.commands.unsetTextAlign()
```

### toggleTextAlign()

Toggles the text align value. If the current value is the same as the specified value, it will be removed.

```js
editor.commands.toggleTextAlign('right')
```

## Keyboard shortcuts

| Command               | Windows/Linux                                     | macOS                                            |
| --------------------- | ------------------------------------------------- | ------------------------------------------------ |
| setTextAlign(left)    | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>L</kbd> | <kbd>Cmd</kbd> + <kbd>Shift</kbd> + <kbd>L</kbd> |
| setTextAlign(center)  | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>E</kbd> | <kbd>Cmd</kbd> + <kbd>Shift</kbd> + <kbd>E</kbd> |
| setTextAlign(right)   | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>R</kbd> | <kbd>Cmd</kbd> + <kbd>Shift</kbd> + <kbd>R</kbd> |
| setTextAlign(justify) | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>J</kbd> | <kbd>Cmd</kbd> + <kbd>Shift</kbd> + <kbd>J</kbd> |

## Source code

[packages/extension-text-align/](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-text-align/)
