2. HTML Basics
HTML Document Structure
The HTML document structure provides the skeletal framework for every webpage. It organizes content into a tree-like hierarchy that browsers parse to render visual elements.
A proper structure ensures that assistive technologies can traverse the DOM effectively. Always maintain a clear parent-child relationship to avoid rendering inconsistencies.
<!DOCTYPE html> <html lang="en"> <head> <title>Document</title> </head> <body> <h1>Hello World</h1> </body> </html>
DOCTYPE
The <!DOCTYPE html> declaration is an instruction to the web browser about what version of HTML the page is written in. It must be the very first line of your document.
Modern browsers trigger "standards mode" when they encounter this declaration. Without it, the browser may default to "quirks mode," leading to unpredictable layout behavior.
<!DOCTYPE html>
html element
The <html> element is the root element of an HTML page. It serves as the container for all other HTML elements, excluding the DOCTYPE.
It is standard practice to include the lang attribute on the <html> tag to specify the primary language of the document. This is vital for search engines and screen readers to interpret content correctly.
<html lang="en-US"> <!-- Content here --> </html>
head element
The <head> element acts as a container for metadata, scripts, and stylesheets that do not appear directly in the browser's main window.
Information inside this element is used by search engines to index your site and by browsers to manage resources. It should never contain visible text content meant for the end user.
<head> <meta charset="UTF-8" /> <title>Page Title</title> </head>
body element
The <body> element contains all the visible content of your document, such as headings, paragraphs, images, and links.
There should only be one <body> element per page. It is the primary area where you structure your information for accessibility, using semantic tags to delineate different parts of your page.
<body> <header>Site Logo</header> <main>Main Content</main> </body>
Meta Tags (Charset, Viewport)
The <meta charset='UTF-8'> tag ensures your browser correctly renders character sets, including emojis and non-Latin characters. It is a critical security and content integrity setting.
The viewport meta tag is essential for responsive design. It tells the browser how to control the page's dimensions and scaling on mobile devices.
Deep Dive: Scaling Ratios
The scale() function resizes an element. It takes dimensionless multipliers. A value of 1 is the original size, 2 doubles the size, and 0.5 halves it. You can scale X and Y independently using scale(X, Y) or scaleX() and scaleY().
Negative values (e.g., scaleX(-1)) will flip the element like a mirror. Scaling is highly performant because it relies on the GPU and does not trigger browser reflows.
<meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
Title
The <title> element defines the document title shown in the browser tab and search engine results pages (SERPs).
Each page should have a unique, descriptive title that reflects the content of that specific page. This is the single most important element for on-page SEO.
<title>VoidX Academy | HTML Basics</title>
Comments
HTML comments are created using the <!--... --> syntax. They are completely ignored by the browser during rendering.
Use comments to leave notes for other developers or to temporarily disable code blocks during debugging. Avoid including sensitive information, as it remains visible when viewing page source.
<!-- This is a comment that won't show in the browser -->
Knowledge Check
Ready to test your understanding of 2. HTML Basics?