HTML : contenteditable

You can set the HTML5 contenteditable attribute with the value true (i.e. contentEditable=”true”) to make an element editable in HTML, such as <div> or <p> element.

<p contenteditable>This is an editable paragraph.</p>


This content originally appeared on DEV Community and was authored by Rajesh Kumar Yadav

You can set the HTML5 contenteditable attribute with the value true (i.e. contentEditable="true") to make an element editable in HTML, such as <div> or <p> element.

<p contenteditable>This is an editable paragraph.</p>

Upon clicking on the paragraph, the content of it can be edited similar to an input text field. When the contenteditable attribute is not set on an element, the element will inherit it from its parent. So all child text of a content editable element will also be editable, but you can turn it off for specific text, like so:

<p contenteditable>
 This is an editable paragraph.
 <span contenteditable="false">But not this.</span>
</p>

Note that an uneditable text element inside an editable element will still have a text cursor as inherited from its
parent as well.

Example

<!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">You Favorite Movie</div>
    <p contentEditable="true">Your Comment</p>
    <p><strong>Note:</strong> Click on the elements and type some text.</p>
</body>
</html>

Buy Me A Coffee

With all that being said, I highly recommend you keep learning!

Thank you for reading this article. Please feel free to connect with me on LinkedIn and Twitter.


This content originally appeared on DEV Community and was authored by Rajesh Kumar Yadav


Print Share Comment Cite Upload Translate Updates
APA

Rajesh Kumar Yadav | Sciencx (2021-05-13T05:11:31+00:00) HTML : contenteditable. Retrieved from https://www.scien.cx/2021/05/13/html-contenteditable/

MLA
" » HTML : contenteditable." Rajesh Kumar Yadav | Sciencx - Thursday May 13, 2021, https://www.scien.cx/2021/05/13/html-contenteditable/
HARVARD
Rajesh Kumar Yadav | Sciencx Thursday May 13, 2021 » HTML : contenteditable., viewed ,<https://www.scien.cx/2021/05/13/html-contenteditable/>
VANCOUVER
Rajesh Kumar Yadav | Sciencx - » HTML : contenteditable. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/13/html-contenteditable/
CHICAGO
" » HTML : contenteditable." Rajesh Kumar Yadav | Sciencx - Accessed . https://www.scien.cx/2021/05/13/html-contenteditable/
IEEE
" » HTML : contenteditable." Rajesh Kumar Yadav | Sciencx [Online]. Available: https://www.scien.cx/2021/05/13/html-contenteditable/. [Accessed: ]
rf:citation
» HTML : contenteditable | Rajesh Kumar Yadav | Sciencx | https://www.scien.cx/2021/05/13/html-contenteditable/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.