Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between HTML <head> and <body> tags?

What's the difference between HEAD tags and BODY tags?

most HTML books only 'briefly' mentions <head> and <body> tags...but they just go away really fast.

Do they affect how browsers render web pages?

Also, do they affect the order in which javascripts are run?

(I mean, if I have a javascript inside a <head> tag, would it run BEFORE another javascript inside <body> tag? Even when <body> came BEFORE <head>?)

This is too confusing--I haven't ever used a head/body tags, but i never had any trouble with it. But while reading Jquery tutorial, I saw people recommending putting some codes inside <head> and the others inside <body> tags.

Thank you!!!

like image 951
user531820 Avatar asked Jun 10 '11 07:06

user531820


People also ask

What are head and body tags?

The <body> tag defines the document's body. The <body> element contains all the contents of an HTML document, such as text, hyperlinks, images, tables, lists, etc. The <head> element is a container for all the head elements.

What goes in head and body HTML?

An HTML 4 document is composed of three parts: a line containing HTML version information, a declarative header section (delimited by the HEAD element), a body, which contains the document's actual content.

What is the significance of head and body tag in HTML?

This tag contains the metadata about the webpage and the tags which are enclosed by head tag like <link>, <meta>, <style>, <script>, etc. are not displayed on the web page. Also, there can be only 1 <head> tag in the entire Html document and will always be before the <body> tag.

What is the head in HTML?

<head>: The Document Metadata (Header) element The <head> HTML element contains machine-readable information (metadata) about the document, like its title, scripts, and style sheets.


2 Answers

  • Things in the head tag are things that shouldn't be rendered: information about the page and how to process it.
  • Things in the body tag are the things that should be displayed: the actual content.
  • Javascript in the body is executed as it is read and as the page is rendered.
  • Javascript in the head is interpreted before anything is rendered.
like image 93
trutheality Avatar answered Oct 04 '22 03:10

trutheality


Generally javascript code will function in the head before code in the body. The head section is usually used to contain information about the page that you dont neccessarily see like the meta keywords meta description or title of a page. You would also link to any external files like .css .js files in the head section as they need to load before the page is displayed.

Anything in the body section is what you would expect to be see on screen.

like image 27
azzy81 Avatar answered Oct 04 '22 03:10

azzy81