I'm working on a text editor based on a contenteditable
DIV. I'd like to produce valid HTML5, but ran into problems with nesting lists.
The following two formatting examples seem to be impossible to create using valid HTML5 because they would require nesting a <ul>
element as a direct child of the parent <ul>
:
Scenario 1: Empty parent item
●
○ nested item with empty parent
Scenario 2: Nested item without parent list item
○ nested item without parent
I read https://mcmap.net/q/63795/-proper-way-to-make-html-nested-list and according to the HTML spec, the <ol>
and <ul>
elements must only contain <li>
elements, but not other <ol>
and <ul>
elements.
However, it is possible to create such a formatting inside a contenteditable
DIV (see jsbin below). So how do browsers do it?
They do nest <ul|ol>
inside the parent <ul>
list! HTML produced like this results in a validation error.
Now if browser vendors resort to this workaround, I conclude that there really is no way to produce this formatting with valid HTML5 and hence it will be ok for me to use the same workaround of including <ul>
as direct children of other <ul>
elements.
Feel free to try it ourself here: