Re: Pressing Enter in contenteditable: <p> or <br> or <div>?

On Fri, Jan 6, 2012 at 9:57 PM, Ojan Vafai <> wrote:
> I'm OK with this conclusion, but I still strongly prefer "div" to be the
> "default single-line container name".

Why?  I don't like using <div> as a line separator at all, because
it's also used as a block-level wrapper, while <p> is specifically
meant to wrap lines and <br> is specifically meant to separate them.
I wish that UAs never generated <div> to wrap lines to start with --
it means that authors can't insert <div>-wrapped editable content
without the risk that it will be interpreted as a line wrapper instead
of a block wrapper.

> Also, I'd really like the "default
> single-line container name" to be configurable in some way. Different apps
> have different needs and it's crappy for them to have to handle enter
> themselves just to get a different block type on enter.

What's a use-case for wanting div or br rather than p?

> Something like document.execCommand("DefaultBlock", false, tagName).

I really don't want more document-global flags.  If such a switch is
added, it should be per editing host.

> What
> values are valid for tagName are open to discussion. At a minimum, I'd want
> to see "div", "p" and "br". As one proof that this is valuable, the Closure
> editor supports these three with custom code and they are all used in
> different apps.

That's not proof that they're valuable, just that people will use them
if given the option.  What are examples of apps that use div and br?
Do you know why they use them?

> I'm tempted to say that any block type should be allowed,
> but I'd be OK with starting with the tree above. For example, I could see a
> use-case for "li" if you wanted an editable widget that only contained a
> single list.

As Simon says, making the list element itself contenteditable will
work for that use-case.  Then hitting Enter will make an <li> no
matter what.

On Tue, Jan 10, 2012 at 3:40 PM, Ryosuke Niwa <> wrote:
> Single br tag is shorter than pairs of div tags when serialized.

True, but only slightly, and the difference is even smaller if you use
<p> instead of <div>.  This isn't enough of a reason by itself to
justify the extra complexity of another mode.  Are there other

Received on Tuesday, 10 January 2012 20:46:59 UTC