Results 1 to 3 of 3

Thread: Optional Closing Tags in HTML

  1. #1
    Join Date
    Aug 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Optional Closing Tags in HTML

    For as long as I've been validating web pages, I never realized that the closing </head> tag was optional in HTML. I feel as if I've missed the boat at times.

    While I'm all for trimming excess code, I just cannot for the life of me strip out closing tags because they are optional in HTML. I'd be concerned that something, somewhere would not parse the document correctly if I removed the closing </head> element.

    Are my concerns unfounded?
    Last edited by Twey; 08-15-2007 at 03:12 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Amazing! I didn't know either. It would never hurt to keep it in though. There couldn't be any question really, in an otherwise valid document, where the head ends.

    I only just tested this in the w3c validator. Without seeing it in the standards, I'm not certain whether it is a glitch in the validator or an actual part of the standards. I did find an archived (1995) reference to its being optional, but would rather see it specifically for a given DOCTYPE to be certain. Browsers will error correct that sort of thing.

    According to the archived reference, there is a lot that is optional. And, this in fact passes strict validation:

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <div>Hi</div>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It is valid. I don't know how browsers might parse it, though; it could be that they'd resort to error-correction (after all, NET is valid in HTML too, but browsers just error-correct it out). It would also lower potential forwards-compatibility with XHTML, in which these tags are not optional. This is also valid Strict:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <title//<p>
    This thread was actually spam, but since it contained an interesting point I'll just remove the signature.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •