---
title: "setTextSelection command"
description: "Use the setTextSelection command to control and set text selection to a specified range or position. Learn more in our docs!"
canonical_url: "https://tiptap.dev/docs/editor/api/commands/selection/set-text-selection"
---

# setTextSelection command

Use the setTextSelection command to control and set text selection to a specified range or position. Learn more in our docs!

If you think of selection in the context of an editor, you’ll probably think of a text selection. With `setTextSelection` you can control that text selection and set it to a specified range or position.

See also: [focus](https://tiptap.dev/docs/editor/api/commands/selection/focus.md), [setNodeSelection](https://tiptap.dev/docs/editor/api/commands/selection/set-node-selection.md), [deleteSelection](https://tiptap.dev/docs/editor/api/commands/selection/delete-selection.md), [selectAll](https://tiptap.dev/docs/editor/api/commands/selection/select-all.md)

## Parameters

`position: number | Range`

Pass a number, or a Range, for example `{ from: 5, to: 10 }`.

## Use the setTextSelection command

```js
// Set the cursor to the specified position
editor.commands.setTextSelection(10)

// Set the text selection to the specified range
editor.commands.setTextSelection({ from: 5, to: 10 })
```
