Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
The HTMLInputElement.setRangeText() method replaces a range of text in an <input> or <textarea> element with a new string.
The string to insert.
start OptionalThe 0-based index of the first character to replace. Defaults to the current selectionStart value (the start of the user's current selection).
end OptionalThe 0-based index of the character after the last character to replace. Defaults to the current selectionEnd value (the end of the user's current selection).
selectMode OptionalA string defining how the selection should be set after the text has been replaced. Possible values:
None (undefined).
Click the button in this example to replace part of the text in the text box. The newly inserted text will be highlighted (selected) afterwards.
| HTML # dom-textarea/input-setrangetext-dev |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jun 23, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.