HTML Real-Time Tutorial
1.11 Creating Editable Content
HTML5 allows you to create editable content using the contentEditable
attribute. By setting this attribute to "true," elements such as <div>
or <p>
become editable directly within the web page, allowing users to type and modify content dynamically. This feature is widely supported in all major browsers.
Using the contentEditable Attribute
The contenteditable
attribute takes two values:
true
- Indicates that the element is editable.false
- Indicates that the element is not editable.
By default, most elements are not editable unless the contenteditable
attribute is set to "true".
Example: Making Text Editable
<h1 contenteditable="true">This is an editable heading</h1> <div contenteditable="true">This is editable content in a <div>.</div>
In this example, both the heading and the div are editable by clicking on them and changing their content.
Example: Editable Elements
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>HTML5 Editable Elements</title> </head> <body> <h1 contentEditable="true">Your Name</h1> <div contentEditable="true">Your Favorite Movie</div> <p contentEditable="true">Your Comment</p> <p><strong>Note:</strong> Click on the elements and type some text.</p> </body> </html>
Note: This example shows how you can easily turn elements into editable areas. You can click on the headers, divs, or paragraphs and edit their content right within the page.
Live Example:
Editable Heading:
Click to edit this heading!
Editable Div:
Browser Support
The contenteditable
attribute is supported in all major browsers, including Chrome, Firefox, Safari, Edge, and Opera.