Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk2 min

How to Make a DIV Editable Like a Textarea

Make a DIV editable in place with contenteditable, and choose between rich-text editing, plaintext-only paste behavior, or a conventional textarea.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To edit content directly inside a DIV, add contenteditable="true". It lets users change the content in place and keep formatted content visible while they edit. For text-only editing, use contenteditable="plaintext-only"; for a conventional multiline plain-text form field, use a <textarea>.

Make the DIV editable in place

Set the contenteditable global attribute on the element:

As an Amazon Associate I earn from qualifying purchases.

<div contenteditable="true" aria-label="Editable text">
  Edit this text
</div>

The browser makes the DIV editable, so users can place a caret, select text, and edit the content where it appears. With contenteditable="true", pasted formatting can be retained. This enables an editable region; it does not by itself create a complete rich-text editor with a toolbar or save behavior. See the MDN contenteditable reference.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose between rich text, plain text, and a textarea

Approach Best for What to expect
contenteditable="true" Editing content in place while formatted content remains visible Browser editing; formatting in pasted content may be retained.
contenteditable="plaintext-only" Editing text in place without pasted formatting Text remains editable, and formatting is removed when content is pasted.
<textarea> Plain text in a conventional multiline form control Designed for text input, not rich-text formatting. See MDN’s textarea reference.
Show a textarea only while editing A display view that switches to a familiar form field for edits Use JavaScript to swap between the display DIV and textarea, then update the display on save. The textarea still edits plain text.

Use an inline editable region when users need to see formatting as they work. Choose a textarea when the value is plain text and standard form-control behavior matters more than in-place formatting.

Add a save action

Making a region editable does not save changes. Your application must decide what to collect and where to store it. For rendered text, read innerText:

<div id="editor" contenteditable="true" aria-label="Editable text">
  Edit this text
</div>
<button id="save" type="button">Save</button>
<script>
  const editor = document.querySelector("#editor");
  document.querySelector("#save").addEventListener("click", () => {
    const text = editor.innerText;
    // Send or store text according to your application's requirements.
  });
</script>

If the application needs to preserve formatting, it must handle HTML markup rather than plain text. Treat edited HTML as untrusted: validate or sanitize it before storing or rendering it. Reading or assigning innerHTML is not a safe substitute for that work. See the MDN innerHTML reference.

Provide keyboard and accessible interaction

Give the editable area an accessible label or clear instructions, and make the focus indicator visible so users can tell when it is active. Editable elements can receive focus and take part in sequential keyboard navigation. Nested editable regions do not join that sequence by default; add tabindex="0" to a nested editable region if keyboard users need to reach it with Tab. Consult MDN’s contenteditable documentation for the attribute’s keyboard behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What contenteditable does not provide

The attribute makes the element editable, but application-specific behavior remains your responsibility. If users need bold or other formatting controls, create and connect a toolbar. You also need to decide how save and cancel work, how changes persist, and which formatting your application accepts. A textarea swap can provide a distinct edit state, but it is not a rich-text editing solution.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.