A useful interface does not need to be complicated. Start with native HTML, then add JavaScript only when you need it.
What You Need to Know
Contenteditable lets visitors edit an element's text in place. It does not automatically save changes, validate them, or turn the element into a full text editor.
In this example: make a draft text area editable.
Try the Example
Take a look at the example. We’ll explain the important lines right below it.
<h2>Edit your note</h2>
<p contenteditable="true" aria-label="Editable practice note">Click here and type a sentence.</p>
<p>Editing this text does not save it to a server.</p>
Let’s Read the Code
- <h2>: A heading divides the page into understandable parts.
- aria-label: Aria-label supplies an accessible name when a visible one is not available.
Read the named elements and attributes together. They explain how the browser connects this feature to the rest of the page.
What Happens in the Browser?
When this example includes JavaScript, it supplies behavior that ordinary HTML does not automatically provide. Always think about a fallback.
Start with native behavior. Details, dialog, and popover each solve a different interface problem. Choose the simplest control that actually matches what a visitor wants to do, then test focus and dismissal as well as appearance.
Your Turn
Run this on a local development server if it loads modules or resources. Change the visible text or trigger and check what still works with scripts disabled.
Common Beginner Mistakes
- Assuming new HTML syntax works in every browser without testing.
- HTML supplies structure; JavaScript is necessary for the scripted behavior in this example. Check keyboard access and focus movement too.
Key Takeaways
- Contenteditable lets visitors edit an element's text in place.
- <h2>: A heading divides the page into understandable parts.
- Test the behavior you expect rather than trusting how the snippet looks in your editor.