Can we have two body tags on a .html page?

 Posted by Ddd on 2/19/2011 | Category: HTML 5 Interview questions | Views: 69026 | Points: 40
Answer:

Yes, we can have 2 body tags on a .html page
example:
<html>

<body bgColor="lightblue">
<h1>First</h1>
</body>
<body bgColor="lightgreen">
<h1>second</h1>
</body>
</html>



//output: the backcolor of the body will be lightblue,
//but the headers of both the body tags will be visible in the output.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Mkiran on: 7/6/2011 | Points: 10
What is the use of this. In .html page we can re use any tag. If you place any tag more than one time, it does not show any error. So from my opinion, answer for this question is No.
Posted by: Akiii on: 7/11/2011 | Points: 10
There may be any number of body tags in a html file but only the first and the last one is considered.

<body bgcolor="lightblue">

<h1>First</h1>
<h1>second</h1>
</body>


Try using the firebug and see the difference..
Let me know if there is any problem you face...

Nice question though...
Thanks and Regards
Akiii

Login to post response