Thread: html header and html body

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    27

    html header and html body

    If a page does not have header and body element, in the RFC standard, we should treat the information as header or as body?

    - I tested with IE and IE treats as body;
    - I read from Http 1.1 RFC, but found not covering this topic.

    Any insights?

    I give a sample here.

    Code:
    <html>
    Hello, the information here should be belong to header or body?
    </html>

  2. #2
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    ... Why even use that o.O? It ain't hard to type <body></body> or <head></head> :P
    Currently research OpenGL

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Because if somebody is writing a browser (for fun or otherwise) its good to handle cases like those.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    HTML has no sense of being "well formed", so browsers have to deal with all sorts of crappy broken pages in a variety of ways.

    Try stuff in Opera / Firefox / IE and take the majority.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The HTML5 spec-in-progress has detailed error recovery specifications that are based on current browser behavior. It's probably your best source of information.

    http://www.whatwg.org/specs/web-apps...ork/multipage/
    Specifically:
    http://www.whatwg.org/specs/web-apps...g.html#parsing
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Aug 2008
    Posts
    27

    Talking

    It is Tech Board. We can discuss anything weird.

    Quote Originally Posted by Akkernight View Post
    ... Why even use that o.O? It ain't hard to type <body></body> or <head></head> :P

  7. #7
    Registered User
    Join Date
    Aug 2008
    Posts
    27
    CB and others, I have tried in browser, I have 3 browsers, IE8, Firefox 3 and the Google Chrome. I also have powershell at hand if you call it is a browser which could retrive web content.

    My question does not matter about how browser treats it, I just want to know what is the Http standard defines for the things if not in header and body explicitly, what should they be, belongs to header? body? or anything else?

    You can think I am weird, and I like collecting weird pages and post to blog.

    Quote Originally Posted by CornedBee View Post
    The HTML5 spec-in-progress has detailed error recovery specifications that are based on current browser behavior. It's probably your best source of information.

    http://www.whatwg.org/specs/web-apps...ork/multipage/
    Specifically:
    http://www.whatwg.org/specs/web-apps...g.html#parsing

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The HTTP standard doesn't define anything, of course.

    The HTML standard says that if you don't have explicit html, head or body elements, the rules are:
    1) A html element is automatically wrapped around everything.
    2) An empty head element is automatically created.
    3) Everything not contained in an explicit body or head is wrapped in a body element.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Registered User
    Join Date
    Aug 2008
    Posts
    27

    Question

    CB, the only thing I read is RFC2616, Http standard. What do you mean HTML standard??

    Quote Originally Posted by CornedBee View Post
    The HTTP standard doesn't define anything, of course.

    The HTML standard says that if you don't have explicit html, head or body elements, the rules are:
    1) A html element is automatically wrapped around everything.
    2) An empty head element is automatically created.
    3) Everything not contained in an explicit body or head is wrapped in a body element.

  10. #10
    Registered User
    Join Date
    Aug 2008
    Posts
    27

    Question

    I did some search, do you mean here?

    http://www.w3.org/TR/REC-html40/

    But where is your 3 conclusions comes from? I read related Http header/body part, but no such 3 rules below.

    http://www.w3.org/TR/REC-html40/struct/global.html

    Quote Originally Posted by CornedBee View Post
    The HTTP standard doesn't define anything, of course.

    The HTML standard says that if you don't have explicit html, head or body elements, the rules are:
    1) A html element is automatically wrapped around everything.
    2) An empty head element is automatically created.
    3) Everything not contained in an explicit body or head is wrapped in a body element.

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The rules are subtle. If you look at the specification of the HTML, HEAD and BODY elements, you'll find that they specify both start and end tags as optional. This means that the tags can be omitted completely. It's up to the parser to determine how the additional content is nested.
    Luckily, the only elements that may appear in both head and body are OBJECT and SCRIPT, so it's generally pretty easy to sort out.

    (So my 2nd and 3rd rule are inaccurate. TITLE, META, STYLE, LINK and BASE are put into HEAD automatically.)

    But this is all theoretical. No actual browser implements SGML. Use HTML5's rules instead.
    Last edited by CornedBee; 11-11-2008 at 07:12 AM.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  12. #12
    Registered User
    Join Date
    Aug 2008
    Posts
    27

    Wink

    Thanks CB. I did read Html 5 Spec today.

    http://www.w3.org/html/wg/html5/#the-header-element

    I can not find out where you mentioned both header and body tags are optional. Could you let me know which section do you mean please?

    Quote Originally Posted by CornedBee View Post
    The rules are subtle. If you look at the specification of the HTML, HEAD and BODY elements, you'll find that they specify both start and end tags as optional. This means that the tags can be omitted completely. It's up to the parser to determine how the additional content is nested.
    Luckily, the only elements that may appear in both head and body are OBJECT and SCRIPT, so it's generally pretty easy to sort out.

    (So my 2nd and 3rd rule are inaccurate. TITLE, META, STYLE, LINK and BASE are put into HEAD automatically.)

    But this is all theoretical. No actual browser implements SGML. Use HTML5's rules instead.

  13. #13
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The very section you mentioned above:
    http://www.w3.org/TR/REC-html40/struct/global.html
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  14. #14
    Registered User
    Join Date
    Aug 2008
    Posts
    27
    Hi CB, do you mean section "4.4.7 The header element"?

    http://www.w3.org/html/wg/html5/#the-header-element

    I read it a couple of times but can not find the logics you mentioned,

    1. header and body are both optional tags of Html;
    2. if content is neither in header nor in body, it is treated as in body?

    Quote Originally Posted by CornedBee View Post
    The very section you mentioned above:
    http://www.w3.org/TR/REC-html40/struct/global.html

  15. #15
    chococoder
    Join Date
    Nov 2004
    Posts
    515
    Quote Originally Posted by Checker1977 View Post
    CB, the only thing I read is RFC2616, Http standard. What do you mean HTML standard??
    You do realise that http and html are two completely different things?
    The http RFCs don't deal with html, nor do the html specifications deal with network transport protocols.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. html encoding issue
    By Checker1977 in forum Tech Board
    Replies: 8
    Last Post: 12-18-2008, 05:18 PM
  2. kickn' html generator
    By jverkoey in forum C++ Programming
    Replies: 0
    Last Post: 03-12-2003, 09:03 PM
  3. Html anchor tag question.
    By adrianxw in forum Tech Board
    Replies: 1
    Last Post: 03-07-2003, 06:52 AM
  4. IDEA: HTML Escaper
    By ygfperson in forum Contests Board
    Replies: 0
    Last Post: 08-12-2002, 11:29 PM
  5. Using fstream to edit a html file
    By mimoman in forum Game Programming
    Replies: 1
    Last Post: 02-21-2002, 11:46 AM