General HTML Rules
HTML is an ASCII-based markup language the defines the way pages and elements
should be rendered within the browser. Since it is ASCII-based, HTML files
can be created in any basic text editor, such as Notepad, Wordpad or Simple
Text.
The general rules for HTML are as follows:
-
HTML is composed of code words, called tags, and optional settings
for the tags called attributes.
-
Each HTML tag is surrounded by "carrots." This is what identifies an HTML
tag for the browser. For example <p> is used for blocks
of text you want to be set as paragraphs.
-
When you have a tag, such as <p>, there are optional settings,
such as the alignment of the paragraph. Thus, to create a paragraph, aligned
to the right the HTML code would look like <p align="right">.
-
Note that HTML is not case sensitive, you should make all your tags and
attributes lowercase. Note also that the value of the attribute is set
inside of double quotes.
-
Many tags have an opening and closing tag. For example, <LI>, which
stands for list item, must have an opening and closing tag. The code for
a list item would look like the following:
-
Some tags do not have a closing tag. In general, you should close all tags
that have a closing tag (even though often times you can get away without
closing a tag).
-
When you are writing HTML code, line spaces in the ASCII code, as well
as multiple spaces, are ignored by the browser. To see what I mean, use
the View Source option in the browser to see the code of this page. You
will find the places in the code that have a "hard return" (where I have
hit the enter key) as well as places where the spacebar has been hit several
times, are ignored.
-
Unrecognized tags and/or attributes will often be ignored. If you enter
an invalid tag or attribute the browser will often just ignore it. However,
this is not always the case. Sometimes, erroneous tags or attributes can
cause any number of visual errors in the page. Your best bet is to test
early and often and make sure you use only valid tags.
-
In the HTML code, you can add comments or remarks to the code as documentation
"behind the scenes." When you enter a comment, the text inside the comment
tags are ignored by the browser. This gives you a means of adding internal
documentation to your HTML code. A comment in the code would look like
this:
<!--This is a comment-->
To see an example of a comment, use the View Source option and look
at the very top of the document. I have added a comment that says "This
is a comment" at the top of this document. Note that it doesn't show up
at the top of the HTML page, even though you can see it in the code.
Coding in HTML
When you are hardcoding pages in HTML, typographical errors are the
most frequent reason that your pages don't look the way you want or won't
display properly. When you are debugging pages, check the following if
you are having problems:
-
Ensure that there are no typos
-
Ensure that you are using valid tags and attributes
-
Make sure that you close tags that are supposed to be closed and that you
leave open tags that are supposed to be open.
-
As you are coding, add a little bit of code, test it and then add some
more. It is easier to find problems if you add a little, test a little,
add a little, et cetera.
|