Coding For Dummies
Book image
Explore Book Buy On Amazon

HTML files are structured in a specific way so browsers can correctly interpret the file’s information. Every HTML file has the same five elements: four whose opening and closing tags appear once and only once, and one that appears once and doesn’t need a closing tag. These are as follows:

  • !DOCTYPE html must appear first in your HTML file, and it appears only once. This tag lets browsers know which version of HTML you are using. In this case, it’s the latest version, HTML5. No closing tag is necessary for this element.

    For HTML4 websites, the first line in the HTML file would read

  • html represents the root or beginning of an HTML document. The tag is followed by first an opening and closing tag, and then an opening and closing tag.

  • head contains other elements, which specify general information about the page, including the title.

  • title defines the title in the browser’s title bar or page tab. Search engines like Google use title to rank websites in search results.

  • body contains the main content of an HTML document. Text, images, and other content listed between the opening and closing body tag is displayed by the browser.

Here is an example of a properly structured HTML file with these five tags:

image0.jpg
<!DOCTYPE html>
<html>
<head>
   <title>Favorite Movie Quotes</title>
</head>
<body>
   <h1>"I'm going to make him an offer he can't refuse"</h1>
   <h1>"Houston, we have a problem"</h1>
   <h1>"May the Force be with you"</h1>
   <h1>"You talking to me?"</h1>
</body>
</html>

Using spaces to indent and separate your tags is highly recommended. It helps you and others read and understand your code. These spaces are only for you and any other human that reads the code, however. Your browser won’t care. As far as your browser is concerned, you could run all your tags together on one line. (Don’t do this, though. The next person that reads your code will be most unhappy.) HTML does recognize and display the first whitespace character in text between opening and closing HTML tags.

The example had many h1 tags but only one opening and closing html, head, title, and body tag.

About This Article

This article is from the book:

About the book author:

Nikhil Abraham is the CFO of Udacity, an education company that teaches technology skills that help launch or advance a career. Prior to joining Udacity, Nik worked at Codecademy where he taught beginning coders across a variety of professions. He is also author of Coding For Dummies and Getting a Coding Job For Dummies.

This article can be found in the category: