- All HTML files should begin with a doctype, which since HTML5 has become very simple:
<!DOCTYPE html>
The above doctype is for HTML5 but works with older HTML specifications as well. You must place this at the very first line of an HTML document. After this declaration, an HTML file needs opening and closing HTML tags: "<html>" and "</html>." Everything but the doctype will go between these tags. - Two parts make up an HTML document: the head and the body. The head goes between "<head>" tags, which you must place directly after the opening "<html>" tag. This portion of the document contains information about the Web page that does not appear on the browser screen, such as keywords or links to embedded files. Whatever you need to appear in the browser screen, such as text, forms and tables, goes between "<body>" tags that must come right after the closing "</head>" tag.
- Write HTML tags in all lowercase letters between right and left angle brackets, like this:
<strong>
Most tags come in pairs of opening and closing tags that wrap around text you need to mark-up. The proper use of the tag above is as follows:
<strong>This is strong text, which most browsers make bold.</strong>
Some tags do not come in a pair, such as horizontal rules, line breaks, images and link tags (not related to hyperlinks, which use anchor tags instead). In XHTML, you must make the tag self-closing like so:
<br /> - Attributes add extra information and formatting to HTML tags. Since the popularization of Cascading Style Sheets (CSS) around 2002, use of tag attributes for formatting is no longer considered a good practice. The generally accepted format for attributes uses double quotation marks around the attribute values, but you can get away with single quotes or even none. Here is an example:
<img src="mypic.png" alt="My Picture" />
The above code places an image in the HTML document and uses two attributes. The first -- "src" -- stands for "source" and tells the browser which image to load. XHTML requires use of "alt" for alternative text when the image fails to load. - Nested tags refers to tags inside of tags, like the following example:
<li><a href="/links/?u=link.html">Link</a></li>
The above code creates an item in a list that contains a link. This is useful for building menus. When nesting tags, you should not nest like this:
<strong><em>This is bold, italic text.</strong></em>
Always close the last tag you opened. This keeps you from inadvertently creating strange, unwanted effects in your Web pages.
Beginning an HTML Document
The Head and Body
HTML Tag Formatting
Tag Attributes
Nesting Tags
SHARE