Beginner question - why use <body> and <html> tags?
Hi!
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?
If I make a very simple index.html containing the following:
Code:
<title>Page title</title>
<h1>Headline of page</h1>
<p>Text on page</p>
...it works just fine. What difference would it do to to add <body> and <html> tags to the code?
There are probably a few edge cases where it matters, but by and large you're right, you can leave off those tags, plus the <head> tag as well, and not suffer any consequences.
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.
Why do I need the <html> and <body> tags when writing a html script?
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'.
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.
Though, in this case, it wouldn't be an error. The spec explicitly says the HTML, HEAD and BODY tags are optional.
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.
<HTML> tag is used to provide the information to the users how to display the things in browsers and <Body> tag used to defines all the content of the HTML document.
Bookmarks