HTML Tutorial #5 - the Scope of HTML Tags

Kantus
The topic of discussion for the previous tutorial was the presedence of nested HTML tags. That tutorial was really talking about the scope of HTML tags. In this tutorial, we will see why that is.

The scope of an HTML tag is simply everything that is contained from the opening of that tag to the closing of that tag. In the previous tutorial, the topic was where exactly the 3 tags close (where there scope ends), as where they end is where their scope ends. In this tutorial, the topic is the scope of the tags.

Take the following for example:

< font color="red" >
I am red.
< /font >

I am default.

< font color="green" >
I am green.
< /font >

In this code, there are two < font > tags. One of them makes the color red and the other green. Since the scope of an HTML tag is defined as everything from the start tag to the end tag, then in this example, the scope of the tag that defined the color as red would include the sentence "I am red."

The next sentence "I am default." is out of the scope of the tag that defined the color to be red because that < /font > tag has already closed it. The < font > tag for the green color has not yet begun, so the text "I am default." will be out of the scope of both of these < font > tags and will be colored in the default color defined by the < body > or what the web browser's settings are set to.

Finally the tag that sets the color to green will only include the text "I am green." as that is the only text in the scope of that tag.

When writing HTML, you should try to make sure you don't accidentally end up using an HTML tag that had already gone out of scope.

Published by Kantus

I love writing short stories and humor articles, but tend to stick with topics that are discoverable by search engines and capable of spreading virally.  View profile

1 Comments

Post a Comment
  • Snowy1/26/2008

    PHP users can try the htmLawed script to balance/properly-nest HTML tags -- http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/index.php.

To comment, please sign in to your Yahoo! account, or sign up for a new account.