HTML5-Syntax


What Is The Basic Syntax Of HTML?

First of all you have to declare which version of HTML it is.To do so you should have the <!doctype>declaration at the first line of every document. <!doctype> tells the version of HTML to the browser which is very important. If you don't do so then the browser may render the content incorrectly.

In HTML 4.01, the declaration refers to a DTD(Document Type Declaration).There are three ways you can declare that the doctype is html 4.

  • HTML 4 Strict
  • HTML 4 Transitional
  • HTML 4 Frameset

HTML 4 Strict:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">

HTML 4 Transitional:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">

HTML 4 Frameset:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
        "http://www.w3.org/TR/html4/frameset.dtd">

HTML 5 declaration:

In HTML5 <!doctype> declaration is so simple it is because HTML5 does not depend on SGML(Standard Generalized Markup Language) so it doesn't refer to DTD.It is so simple and just one line of code.

<!DOCTYPE html>

After telling the browser which version of HTML it is(by declaring the doctype) you'll start writing HTML elements.

In the next lesson we'll discuss more about html elements.

The Root Element:

There are lots of elements in HTML and <html> is the root element of the document.Every elements should be inside of the root element except <!DOCTYPE html> declaration.

<!DOCTYPE html>
<html>

</html>

The <head> Element:

<head> element is the first child of <html> element.<head> element contains metadata. metadata is a set of data that describes and gives information about the document.For example: it contains document's title,links of stylesheet,script etc.

All the elements inside <head> element don't display in the body part on the web browser.

<!DOCTYPE html>
<html>
<head>
  <title>My First Web Page!</title>
</head>
</html>

The <body> Element:

<body> element is the second child element of the root element.It contains all the contents of the webpage what you want to show to web visitors.For example: headers,paragraphs,photos,musics,videos and more. You can't have more than one body element in a document.

So now you can write a basic or minimum required html document.

Basic Syntax of HTML 5

<!DOCTYPE html>
<html>
  <head>
    <title>My First Web Page!</title>
  </head>
  <body>
    <h1>Hello World!</h1>
  </body>
</html>

As a begginer you may have a lot of questions.But don't worry we'll go slowly in every details.Go to the next lesson to learn what is a element.