HTML Document Structure
1. Document Type Declaration (DOCTYPE)
The DOCTYPE declaration is the first line of an HTML document. It informs the web browser about the version of HTML being used. For HTML5, the declaration is <!DOCTYPE html>
. This ensures that the browser renders the document in standards mode, adhering to modern web standards.
Example:
<!DOCTYPE html>
2. HTML Element
The <html>
element is the root element of an HTML document. It encapsulates all other HTML elements. The lang
attribute is used to specify the language of the content, which is important for accessibility and SEO. For example, lang="en"
indicates that the content is in English.
Example:
<html lang="en"> </html>
3. Head Element
The <head>
element contains meta-information about the document, such as the title, character set, and linked stylesheets. It does not display content directly on the webpage but provides essential information for the browser and search engines.
Example:
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Page Title</title> </head>
4. Body Element
The <body>
element contains the content that is displayed on the webpage. This includes text, images, links, and other media. All visible content of the webpage is placed within the <body>
element.
Example:
<body> <h1>Welcome to My Website</h1> <p>This is the main content of the webpage.</p> </body>
5. Meta Elements
Meta elements within the <head>
provide additional information about the document. The <meta charset="UTF-8">
element specifies the character encoding, ensuring that the browser correctly interprets the text. The <meta name="viewport">
element is crucial for responsive design, allowing the webpage to adapt to different screen sizes.
Example:
<meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
6. Title Element
The <title>
element defines the title of the webpage, which appears in the browser's title bar or tab. It is essential for SEO and accessibility, as it helps users and search engines understand the content of the page.
Example:
<title>Page Title</title>
Understanding the structure of an HTML document is fundamental for creating well-organized and accessible web pages. By mastering these key elements, you can ensure that your webpages are correctly interpreted by browsers and optimized for both users and search engines.