30 Mins

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.

Operator Note: Always indent your nested elements to maintain readability and catch unclosed tags early.
HTML
<!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.

Operator Note: Even though it looks like a tag, it is actually a document type declaration, not an HTML element.
HTML
<!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.

Operator Note: Setting the lang attribute helps screen readers select the appropriate pronunciation voice for your content.
HTML
<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.

Operator Note: Keep your head section clean by putting CSS in external files and scripts at the end of the body or deferred.
HTML
<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.

Operator Note: Avoid placing visual elements like <h1> or <div> inside the head tag; they belong in the body.
HTML
<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.

Operator Note: Omitting the viewport meta tag will often cause mobile browsers to render your page as if it were on a wide desktop screen.
HTML
<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.

Operator Note: Keep your title under 60 characters to ensure it displays fully in Google search results.
HTML
<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.

Operator Note: Do not use comments to hide sensitive data like API keys, as they are viewable by anyone who inspects your source code.
HTML
<!-- This is a comment that won't show in the browser -->

Knowledge Check

Ready to test your understanding of 2. HTML Basics?

Back