skip to Main Content

I’m working on a project where I find it convenient to include elements other than <li> inside a <ul>. Is this semantically correct and acceptable in HTML or should I make the elements start with <li>?

I have below one list inside another one. The element I am trying to put has the tag <textarea>.

Example:

    <ul class="list">
        <li class="category">what + how + who</li>
            <ul class="subcategories">
                <li>WHAT do we do?</li>
                <textarea class="input"></textarea>
                <li>HOW do we do it?</li>
                <li>WHO do we serve?</li>
            </ul>
    </ul>

2

Answers


  1. Yes, you can write <ul> tag inside <li> tag.

    I have used this pattern when building a multilevel navbar, where I want to open a navbar on hover of a parent navbar item.

    For using <textarea> you should wrap it into <li> tag cuz, you can’t use <textarea> directly under the <ul> tag.

    After fixes :

    <ul class="list">
        <li class="category">
            <span>what + how + who</span>
            <ul class="subcategories">
                <li>WHAT do we do?</li>
                <li><textarea class="input"></textarea></li>
                <li>HOW do we do it?</li>
                <li>WHO do we serve?</li>
            </ul>
        </li>
    </ul>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search