InterviewSolution
| 1. |
Explain the structure of the HTML webpage. |
|
Answer» There are no rules for HTML structure and web-page will not throw an error if we don’t follow structure. But then also there are a set of rules which are the de-facto standard to create a webpage.
The first tag to be used in a web-page is the doctype tag. It is used for historical reasons and its PURPOSE is to prevent the browser to switch to quirks mode. In the old DAYS of the web pages were written for two BROWSERS of the time - Netscape Navigator and Internet Explorer. When web-standards were made by W3C, the <doctype> tag was used to tell the browser to run the following web-page in full mode, instead of quirks mode for Netscape Navigator and Internet Explorer. The latest way described in HTML5 is to use <!DOCTYPE html> at the top of your web-page.
After the <!DOCTYPE html> we wrap our entire code inside a pair of <html>…</html> tags.
The head tag is mainly meant for the browser and not directly rendered. It contains <title> tag, which is the title of the web-page. It also contains <meta> tags, which contains various information for the web-page. Also contains <script> tag to link external javascript files and can also contain <link> tag to link external stylesheets.
It contains the main body for our page. The code inside it is what we see in our web-page. In the body tag, we can contain all our elements normally or can organize it in a better way using semantic tags. And below is an example for- <!DOCTYPE html> <html> <head> <meta CHARSET="utf-8" /> <meta http-equiv="X-UA-Compatible" CONTENT="IE=edge"> <title>Our Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" media="screen" href="main.css" /> <script src="main.js"></script> </head> <body> <h1>Our header</h1> <p>Lorem ipsum dolor sit.</p> <h2>First Section</h2> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Deserunt, culpa?</p> <h2>Second Section</h2> <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Aut, ratione?</p> </body> </html>Save the above code as demo.html and open in any browser. |
|