SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: putting tags inside <li> tags

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    putting tags inside <li> tags

    In xhtml/html am I allowed to put <p>, <h2> etc. tags inside <li></li> tags? I know this won't actually break the page, but is it semantically acceptable.

    The answer may seem like an obvious "yes it's ok" but recently I was surprised to find out that putting text within a <blockquote> without also putting it in <p> tags is not allowed, so there are some pretty strict nesting rules around.

    Cheers for any advice

    Rhys

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, quoting the dtd for xhtml strict:

    <!ENTITY % block
    "p | %heading; | div | %lists; | %blocktext; | fieldset | table">

    <!ENTITY % Block "(%block; | form | %misc;)*">

    <!-- %Flow; mixes block and inline and is used for list items etc. -->
    <!ENTITY % Flow "(#PCDATA | %block; | form | %inline; | %misc;)*">
    So yes you could do so, and as %block; expands to %blocktext%, you could technically shove <hr>'s in there too (not sure why, seems kind of weird).

    As for whether or not it's semantically correct is a different story. For li's to be li's, they need to be a list of something (hence why you might see a lot of menus done as li's and css'ed to look pretty, because menus are a list of links).
    Last edited by chris_fuel; Mar 6, 2008 at 11:46. Reason: forgot smilies off...

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's perfectly all right to use those elements within a list item.

    If you start mixing inline-level and block-level elements, then it's semantically doubtful, though. That applies both within a single list item and within the list as a whole.

    In other words, if you have a block-level element as a child of an li element, then all children of that li – and all sibling li elements – should be block-level.
    Birnam wood is come to Dunsinane

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •