👀 Live Preview
Click inside the box and edit the text:
This content is editable. Try typing here!

The contenteditable attribute is a powerful feature in HTML that allows developers to make elements editable by users. This attribute provides a straightforward way to turn elements like <div>, <span>, or even sections of a page into a user-editable area. It is particularly useful for creating rich-text editors and interactive content.
Edit on or off.
div, p, span.
Type in browser.
JS property.
Rich vs plain.
Labels, sanitize.
contenteditableThe primary purpose of the contenteditable attribute is to make an element editable, enabling users to modify the content directly in the browser. This can be advantageous for creating dynamic and interactive web pages where users can engage with the content in real time.
contentThe content attribute sets metadata on <meta> tags. contenteditable controls whether users can edit visible page content.
Add contenteditable to any supported element:
<div contenteditable="true">Edit me</div>
<p contenteditable="false">Read only</p>
<span contenteditable>Empty value = true</span>true, false, or empty (empty means editable).inherit follows the parent’s editable state when explicitly set.element.contentEditable (capital E).The contenteditable attribute accepts different values to define the editing behavior of the element:
<div contenteditable="true">
<p contenteditable="inherit">Inherits from parent</p>
<p contenteditable="false">Locked paragraph</p>
</div>| Value | Markup | Behavior |
|---|---|---|
| Editable | contenteditable="true" | User can type and edit |
| Editable (shorthand) | contenteditable | Same as true |
| Not editable | contenteditable="false" | Read-only region |
| Inherit | contenteditable="inherit" | Follow parent |
| JavaScript | el.contentEditable = "true" | Toggle at runtime |
| Read edited HTML | el.innerHTML | Save or process content |
| Element | Supported? | Notes |
|---|---|---|
<div>, <p>, <span> | Yes | Common editable containers |
<h1> – <h6>, <li> | Yes | Headings and list items |
<textarea>, <input> | Already editable | Use native form controls for forms |
<button> | Discouraged | Conflicts with button behavior |
<meta> | No practical use | Not for metadata values |
| Feature | contenteditable | textarea |
|---|---|---|
| Rich formatting | Yes (bold, lists via browser) | Plain text only |
| Form submission | Not automatic | Native form field |
| Best for | Inline editors, notes UI | Comments, messages |
| Accessibility | Needs extra ARIA/labels | Built-in form semantics |
Editable div with contenteditable and a JavaScript toggle button.
Click inside the box and edit the text:
This content is editable. Try typing here!
Let’s look at a simple example of how to use the contenteditable attribute in an HTML document:
<div contenteditable="true">
<p>This content is editable. Try typing here!</p>
</div>In this example, the contenteditable attribute is set to true for a <div> element, allowing users to edit the contained paragraph.
You can dynamically toggle the contenteditable attribute using JavaScript to create interactive experiences. Here’s an example:
<button type="button" onclick="toggleEditable()">Toggle Editable</button>
<div id="editableElement">
<p>This content can be dynamically edited.</p>
</div>
<script>
function toggleEditable() {
var element = document.getElementById("editableElement");
element.contentEditable = (element.contentEditable === "true") ? "false" : "true";
}
</script>In this script, a button click toggles the contenteditable state of a <div> element with the id editableElement. This showcases how you can use JavaScript to provide dynamic control over the editing behavior.
aria-label so users know an area is editable.<input> or <textarea>.Set contenteditable to true on a container element.
Click or Tab into the element to start editing.
Typed text and formatting changes live in innerHTML.
Save with JavaScript or use a library for production rich-text editors.
The contenteditable attribute is supported in all modern browsers. Formatting behavior may vary slightly between engines.
All major browsers honor contenteditable on supported elements.
Bottom line: Use contenteditable confidently; test rich formatting if your app depends on it.
content attributecontenteditable attribute thoughtfully, considering the user experience and the nature of the content.The contenteditable attribute is a versatile tool for creating interactive and editable content on the web. By understanding its usage and incorporating it judiciously into your projects, you can enhance user engagement and create dynamic user interfaces.
For production rich-text editing, many teams combine contenteditable with JavaScript libraries or sanitize and save content explicitly. For simple forms, native inputs remain the best choice.
contenteditableBookmark these before building an editable UI.
div, p, span.
ScopeEdit control.
ValuesJS toggle.
ScriptRead edits.
SaveLabel regions.
UXcontent is for meta tag values. contenteditable controls user editing of visible elements.element.innerHTML or textContent with JavaScript and send it to your server. Sanitize HTML before storing.element.contentEditable = "true" or "false". The property name uses a capital E.Practice the contenteditable attribute with live editing and JavaScript toggle examples in the Try It editor.
2 people found this page helpful