Tags define the look and placement of the contents of a tag. The content of a tag is contained between an opening and closing tag. The combination of starting tag, content inside the tag, and closing tag is referred to as an element.
So how do you create a tag? In XHTML, tags can be identified by the presence of angled (< and >) brackets. Inside these brackets, we write the code that identifies a tag. For instance, in
This is a <b>tag</b> for making some text bold.
we have two sets of angled brackets. Each of these two sets contain a lowercase “b” to make the word “tag” bold typeface. In the example, <b> is the opening tag. An opening tag starts an instruction: displays the content of the tag as bold typeface. In contrast, a closing tag stops an instruction. In the example, it instrcuts the browser to stop applying the bold typeface instruction. Since our element (<b>tag</b>) consists of the text only “tag”, only this text will be displayed as bold typeface and the rest of the text will be displayed as regular text. The following confirms this output:
So you can see XHTML is not difficult to use though there are some rules, as described in the next section, that you should remember to create XHTML documents.
Just as spoken languages have rules (called grammar), computer-based languages too have rules called syntax. You need to follow the tag syntax to instruct the browser exactly what you are trying to portray in an XHTML document. The following lists the basic principles that apply to XHTML documents:
- Place a document type declaration before the <html> tag.
- All XHTML documents must contain <html>, <body>, and <title> tags.
- All tags in XHTML must have a closing tag.
- Tags must be XHTML-compliant
- All tags their attributes must be lowercase.
- Enclose attribute values in quotation marks.
- Tags can be nested within other tags.