HTML documents are written in plain text. They can be written in any text editor that allows content to be saved as plain text (although most HTML authors prefer to use a specialized editor that highlights syntax and shows the DOM). Tag names may be written in either upper or lower case. However, the W3C (the global consortium that maintains the HTML standard) recommends using lower case (and XHTML requires lower case).
HTML attaches special meaning to anything that starts with the less-than sign (“<“) and ends with the greater-than sign (“>“). Such markup is called a tag. Make sure to close the tag, as some tags are closed by default, whereas others might produce unexpected errors if you forget the end tag.
Closing tags (/>) are the same as the start tag but also contain a forward slash immediately after the leading less-than sign. Most elements in HTML are written using both start and closing tags. Start and closing tags should be properly nested, that is closing tags should be written in the opposite order of the start tags. Proper nesting is one rule that must be obeyed in order to write valid code.
Some elements do not contain any text content or any other elements. These are empty elements and need no closing tag. Many people mark up empty elements using a trailing forward slash (which is mandatory in XHTML). In HTML this slash has no technical functionality and using it is a pure stylistic choice.
The start tag may contain additional information. Such information is called an attribute. Attributes usually consist of 2 parts:
- An attribute Name.
- An attribute Value.
A few attributes can only have one value. They are Boolean attributes and may be shortened by only specifying the attribute name or leaving the attribute value empty.
Attribute values that consist of a single word or number may be written as they are, but as soon as there are two or more strings of characters in the value, it must be written within quotation marks. Both single quotes (‘) and double quotes (“) are allowed. Many developers prefer to always use quotes to make the code less ambiguous to the eye and to avoid mistakes.
Named Character References
Named character references (often casually called entities) are used to print characters that have a special meaning in HTML. For example, HTML interprets the less-than and greater-than symbols as tag delimiters. When you want to display a greater-than symbol in the text, you can use a named character reference. There are four common named character references one must know:
> denotes the greater than sign (>)
< denotes the less than sign (<)
& denotes the ampersand (&)
" denotes double quote (“)
There are many more entities, but these four are the most important because they represent characters that have a special meaning in HTML.