If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Beginner question - why use <body> and <html> tags?

Even though I've been working with IT for many years now, I'm relatively new at HTML scripting. So please bear with if this is a stupid question.

Why do I need the <html> and <body> tags when writing a html script?

I understand their uses to the extend that <body> is the "body"-part of the page, and usually comes right after <head> - and <html> is just a tag to specify which kind of language I'm using. But what happens if I leave them out? What difference do they make?

The state of the web is such that browser software, search engine robots, and other "user agents" tend to be reasonably tolerant of errors because they encounter so many of them. That said, it doesn't pay to be intentionally sloppy with your coding. It can make it more difficult to maintain your site, diagnose rendering problems, and can potentially impair your site's performance in the search engines.

Proper coding not only gives you the best chance of having your web pages seen and interpreted as you intend them to be, it can help overcome issues caused by improper coding at the server level. In the end, you'll save yourself a lot of frustration by following the nitpicking little rules that come with web design.

Well, personally, you are totally free to code as you heart's desire dictates,
but if you were employed to work for a company then it would be necessary
for you to strictly follow coding conventions so that all team members were
'singing from the same song sheet'.

I just like to add, while most browsers will call most errors they DON'T catch them all. I remember one time my website didn't look right, so I spent hours trying to figure it out. Then it dawn on me to check my html with w3c validator and load & behold I forgot to close a tag </a>, as a side not I felt stupid spending all the hours when it only took a few seconds to check my code. Moral of the story while you might get away it most of the time, it will eventually come around and bite you.

Hi lleroy
<html> is the element that begins and ends each and every web page. Its sole purpose is to hold each web element nicely in position and serves the role of book cover; all other HTML elements are encapsulated within the <html> element. and
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.
that's why <html> and <body> tags are important for writing a html script.