As I go through the HTML5 spec, I find some use­ful new fea­ture just about every­where, and the new con­tente­d­itable attribute is cer­tainly one of those. It’s sup­ported by most ele­ments and pro­vides a sim­ple and yet effec­tive way for you to allow the users to edit user con­tents (blog posts for instance) inline as opposed to hav­ing to open up a sep­a­rate form.

It couldn’t be sim­pler to use it, just set the con­tente­d­itable attribute of your ele­ment to true:

<article id="editable" contenteditable="true">
    <p>This area is an article, its border will light up when you click anywhere inside.</p>
    …
</article>

And now when the user can edit the con­tent of the ele­ment themselves:

image image

Here is a quick demo I’ve put together which uses two but­tons to save and clear changes to/from the local stor­age, though you can just eas­ily save the changes auto­mat­i­cally when the ele­ment loses the focus.

Share

One Response to “Having fun with HTML5 — contenteditable attribute”

  1. Richard says:

    Nice post-thanks
    (Bor­der does not light up when I click in demo-any idea why not?)

Leave a Reply