General Synax of html5 is
1 2 3 4 5 6 7 8 9 | <!DOCTYPE html> <html lang="en"> <head> ... </head> <body> ....... </body> </html> |
<!DOCTYPE html> specifies that this document is html 5 document and you can use all html5 tags here.
<html> is root tag of html document it contains two child tags <head> and <body>
<head> specifies that this portion contains heading information of page we can use many other tags here like <title> which is used to specify the title of page and may other.
<body> we put the contents which you would like to display on browser.
Inside body tag we use many different html tags to proper formatting the data.
Example
1 2 3 4 5 6 7 8 9 | <!DOCTYPE html> <html lang="en"> <head> <title>My First Html Page</title> </head> <body> <h1>Welcome to my first html page</h1> </body> </html> |
In above syntax start and end tags are optional.
if you dont want to use any attribute with root tab ie <html lang=”en”> then you can omit this
So syntax with out root tag
1 2 3 4 5 6 7 | <!DOCTYPE html> <head> ... </head> <body> ....... </body> |
Exampe of html document
Example
1 2 3 4 5 6 7 | <!DOCTYPE html> <head> <title>My First Html Page</title> </head> <body> <h1>Welcome to my first html page. Removed root tag</h1> </body> |
In the XHTML syntax we have to specify the xmlns to declare that it is a HTML namespace.
We can use lang or xml:lang attribute to specify the language
Syntax with xmlns
1 2 3 4 5 6 7 | <html xmlns="http://www.w3.org/1999/xmlns" xml:lang="en"> <head> ... </head> <body> ....... </body> |
Example
1 2 3 4 5 6 7 8 | <html xmlns="http://www.w3.org/1999/xmlns" xml:lang="en"> <head> <title>My First Html Page</title> </head> <body> <h1>Welcome to my first html page. Removed root tag</h1> </body> </html> |
Example
1 2 3 4 5 6 7 8 9 10 11 | <!DOCTYPE html> <!DOCTYPE html> <html lang="en"> <head> <title>My First Html Page</title> </head> <body> <h1 style="background-color:cyan;font-size:20px">Welcome to my first html page</h1> <p>Keep learnig html5 its simple and easy </p> </body> </html> |