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:
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:
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:
Some elements are empty (self-closing), meaning they contain no content:
Attributes add metadata to elements and appear inside the opening tag:
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:
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.
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.
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 |
|---|---|---|
|
| non-breaking space |
¦ |
¦ | broken bar |
± |
± | plus/minus |
£ |
£ | pound sign |
¥ |
¥ | yen sign |
Ø |
Ø | slashed O |
© |
© | copyright |
® |
® | registered mark |
° |
° | degree symbol |
² |
² | superscript 2 |
³ |
³ | superscript 3 |
& |
& | ampersand |
¼ |
¼ | one quarter |
½ |
½ | one half |
¾ |
¾ | three quarters |
à |
à | small a grave |
À |
À | capital A grave |
œ |
œ | oe ligature |
é |
é | small e acute |
É |
É | capital E acute |
ë |
ë | e umlaut |
î |
î | small i circumflex |
Î |
Î | capital I circumflex |
ç |
ç | c cedilla |
" |
" | quotation mark |
ß |
ß | sharp s (eszett) |
ñ |
ñ | n tilde |
< |
< | less-than sign |
> |
> | greater-than sign |
µ |
µ | micro symbol |
These entities are essential when writing characters that have special meanings in HTML (like < or >).
8. Text Formatting and Emphasis
HTML provides tags to emphasize or style text semantically:
<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.
Paragraphs are written with <p> and can include short quotes (<q>) or block quotes (<blockquote>):
10. Lists
HTML supports three list types:
- Unordered list (bulleted):
- Ordered list (numbered):
- Description list:
Lists can be nested inside one another to represent hierarchical structures.
11. Tables
Tables present data in rows and columns using the following structure:
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:
- 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:
13. Images
Images are inserted using the <img> tag:
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:
Common Input Types
text,password,number,date,color,rangecheckbox,radio,select,textarea
Example of a dropdown list:
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:
These replace older <div id="header"> (HTML4) structures, making documents more meaningful to search engines and assistive technologies.
16. References
Made by h0ag