DEV Community

Cover image for Mastering HTML -- The Complete Guide
Hoag
Hoag

Posted on • Originally published at hwiki.xyz

Mastering HTML -- The Complete Guide

HTML (HyperText Markup Language) is the standard language used to structure content on the web. This guide covers every fundamental aspect of HTML, from the basic syntax to more advanced features such as forms and semantic elements introduced in HTML5.


1. Introduction to HTML

HTML is a markup language used to define documents for the web. It
relies on tags (or elements) to describe both the structure and the meaning of content.

A basic HTML file contains the following structure:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>Example HTML File</title>
</head>
<body>
  <h1>Example HTML File</h1>
  <p>This is an example of an <a href="https://www.w3.org/html/">HTML</a> document.</p>
  <ul>
    <li>Readable text content</li>
    <li>Formatting elements
      <ol>
        <li>Sections with <strong>strong emphasis</strong></li>
        <li>Heading levels</li>
        <li>Numbered or unnumbered lists</li>
      </ol>
    </li>
    <li>Hypertext links (<a href="links.html">anchors</a>)</li>
    <li>Embedded images:
      <img src="images/logo.png" width="260" height="91" alt="Logo" />
    </li>
  </ul>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

The browser interprets these tags to render the document visually. Each tag defines a role, not a visual appearance --- styling is handled by CSS.


2. The DOCTYPE Declaration

Every HTML document begins with a DOCTYPE declaration, which tells the browser what type of document to expect. In HTML5, the declaration is simplified:

<!DOCTYPE html>
Enter fullscreen mode Exit fullscreen mode

Older versions (like HTML 4.01 or XHTML) required long DTD references. HTML5 simplified this to a single universal declaration that ensures consistent rendering across browsers.


3. HTML Elements and Syntax

An HTML element is defined by an opening and closing tag, enclosing its content:

<p>This is a paragraph.</p>
Enter fullscreen mode Exit fullscreen mode

Some elements are empty (self-closing), meaning they contain no content:

<br />
<img src="image.png" alt="Example" />
Enter fullscreen mode Exit fullscreen mode

Attributes add metadata to elements and appear inside the opening tag:

<a href="contact.html" target="_blank">Contact</a>
Enter fullscreen mode Exit fullscreen mode

4. The <html> Element

The <html> tag marks the beginning and end of an HTML document. It can include the lang attribute to specify the language of the content, improving accessibility and SEO:

<html lang="en">
  ...
</html>
Enter fullscreen mode Exit fullscreen mode

Inside the <html> element, there are always two main sections: -
<head>: The document header containing metadata. - <body>: The visible content.


5. The <head> Element

The header provides information about the document --- metadata, title, description, and encoding.

<head>
  <title>My Webpage</title>
  <meta charset="utf-8" />
  <meta name="author" content="h0ag" />
  <meta name="keywords" content="HTML, web, tutorial, HWIKI" />
  <meta name="description" content="Comprehensive HTML guide from HWIKI" />
</head>
Enter fullscreen mode Exit fullscreen mode

Key Points

  • <title> is mandatory and defines the title shown in browser tabs and bookmarks.
  • <meta charset="utf-8"> defines the character encoding. UTF-8 supports nearly all characters.
  • <meta> tags describe the document for search engines and browsers.

6. The <body> Element

The <body> contains the content that will be displayed on the page --- text, images, links, lists, and so on.

<body>
  <h1>Welcome to HWIKI</h1>
  <p>This is a sample paragraph.</p>
  <img src="images/logo.png" alt="HWIKI Logo" width="260" height="91" />
</body>
Enter fullscreen mode Exit fullscreen mode

Content can be textual, structural, or multimedia.


7. Character Encoding and Entities

HTML supports special characters through entities, which start with & and end with ;.

Entity Symbol Description
&nbsp;   non-breaking space
&brvbar; ¦ broken bar
&plusmn; ± plus/minus
&pound; £ pound sign
&yen; ¥ yen sign
&Oslash; Ø slashed O
&copy; © copyright
&reg; ® registered mark
&deg; ° degree symbol
&sup2; ² superscript 2
&sup3; ³ superscript 3
&amp; & ampersand
&frac14; ¼ one quarter
&frac12; ½ one half
&frac34; ¾ three quarters
&agrave; à small a grave
&Agrave; À capital A grave
&oelig; œ oe ligature
&eacute; é small e acute
&Eacute; É capital E acute
&euml; ë e umlaut
&icirc; î small i circumflex
&Icirc; Î capital I circumflex
&ccedil; ç c cedilla
&quot; " quotation mark
&szlig; ß sharp s (eszett)
&ntilde; ñ n tilde
&lt; < less-than sign
&gt; > greater-than sign
&micro; µ micro symbol

These entities are essential when writing characters that have special meanings in HTML (like < or >).

HTML entities


8. Text Formatting and Emphasis

HTML provides tags to emphasize or style text semantically:

<p>This is <em>important</em> and <strong>very important</strong>.</p>
<p><mark>Highlighted</mark> text example.</p>
<p>Equation: x<sub>1</sub><sup>2</sup> = 1</p>
Enter fullscreen mode Exit fullscreen mode
  • <em> (emphasis): conveys importance, typically italicized.
  • <strong> (strong emphasis): denotes strong importance, often bold.
  • <mark>: highlights text.
  • <sub> and <sup>: subscript and superscript.

Styling-only tags like <b>, <i>, and <u> should be used only when semantic equivalents don't apply.


9. Headings and Paragraphs

HTML defines six heading levels (<h1> to <h6>) to represent document structure, not visual size.

<h1>Main Title</h1>
<h2>Subtitle</h2>
<h3>Subsection</h3>
Enter fullscreen mode Exit fullscreen mode

Paragraphs are written with <p> and can include short quotes (<q>) or block quotes (<blockquote>):

<blockquote cite="https://hwiki.xyz/html">
HTML5 is the standard markup language for web documents.
</blockquote>
Enter fullscreen mode Exit fullscreen mode

10. Lists

HTML supports three list types:

  1. Unordered list (bulleted):
<ul>
  <li>HTML</li>
  <li>CSS</li>
  <li>JavaScript</li>
</ul>
Enter fullscreen mode Exit fullscreen mode
  1. Ordered list (numbered):
<ol>
  <li>Introduction</li>
  <li>Content</li>
  <li>Conclusion</li>
</ol>
Enter fullscreen mode Exit fullscreen mode
  1. Description list:
<dl>
  <dt>HTML</dt>
  <dd>A markup language for the web.</dd>
</dl>
Enter fullscreen mode Exit fullscreen mode

Lists can be nested inside one another to represent hierarchical structures.


11. Tables

Tables present data in rows and columns using the following structure:

<table>
  <caption>Lovers</caption>
  <thead>
    <tr><th>Name</th><th>Email</th></tr>
  </thead>
  <tbody>
    <tr><td>h0ag</td><td>h0ag@hwiki.xyz</td></tr>
    <tr><td>Emmal0y</td><td>-</td></tr>
  </tbody>
  <tfoot>
    <tr><td colspan="2">End of Table</td></tr>
  </tfoot>
</table>
Enter fullscreen mode Exit fullscreen mode

Use colspan and rowspan to merge cells horizontally or vertically.
Tables should never be used for page layout --- CSS handles that purpose.


12. Hyperlinks

Links are created with the <a> tag:

<a href="https://hwiki.xyz/">Visit HWIKI</a>
<a href="about.html" target="_blank">Open About Page</a>
Enter fullscreen mode Exit fullscreen mode
  • Absolute URLs: full path to a resource (including protocol and domain).
  • Relative URLs: local paths within your project directory.

Internal anchors can also link to specific parts of a page:

<a href="#section1">Go to Section 1</a>
...
<h2 id="section1">Section 1</h2>
Enter fullscreen mode Exit fullscreen mode

13. Images

Images are inserted using the <img> tag:

<img src="images/photo.jpg" alt="A landscape photo" width="300" height="200" />
Enter fullscreen mode Exit fullscreen mode

The alt attribute is mandatory and describes the image content, useful for screen readers and when the image fails to load.


14. Forms

Forms allow user input and interaction. A basic example:

<form>
  Name: <input type="text" name="name" /><br />
  Password: <input type="password" name="password" /><br />
  <input type="submit" value="Submit" />
</form>
Enter fullscreen mode Exit fullscreen mode

All input types

Common Input Types

  • text, password, number, date, color, range
  • checkbox, radio, select, textarea

Example of a dropdown list:

<select name="language" size="1">
  <option value="1">HTML</option>
  <option value="2">CSS</option>
  <option value="3" selected>JavaScript</option>
</select>
Enter fullscreen mode Exit fullscreen mode

Use <fieldset> and <legend> to group form sections, and <label for="id"> to connect text to input fields.


15. Semantic Page Structure (HTML5)

HTML5 introduced semantic elements that describe the role of different page sections:

<header>Header content</header>
<nav>Navigation links</nav>
<main>Main article content</main>
<aside>Sidebar or related information</aside>
<footer>Footer content</footer>
Enter fullscreen mode Exit fullscreen mode

These replace older <div id="header"> (HTML4) structures, making documents more meaningful to search engines and assistive technologies.


16. References


Made by h0ag

Top comments (0)