HTML 101: Back to Basics - Elements: Do That SGML Thing You Do | WebReference

HTML 101: Back to Basics - Elements: Do That SGML Thing You Do

Front Page12345

Elements: Do That SGML Thing You Do

I mentioned that HTML, as a computer language, has a defined syntax. This syntax was not thought up at random, since the idea of a markup language is hardly new. A language called SGML, the Standard Generalized Markup Language, exists that is used to define markup languages. Make sure you get this right: SGML is a markup language whose sole use is to define other markup languages. And one of those many languages is HTML.

Now wait. Before you click on our sponsor's ad and get out of here, afraid that you'll have to learn another language, let me assure you that no such thing is needed. You do not need to know SGML to learn HTML. It's just useful to know that HTML is an application of SGML, which will explain a few things.

Now let's get down to business. Remember the heading we saw in the last section? If not, here it is again.

Acme Computer Corp.

We know this is a heading, but we need a way of encoding this in the document itself. To do this, we make this heading an element. We do this by writing the following (yes, this is HTML!):

<H1>Acme Computer Corp.</H1>

This element can be split into three parts. The first part, <H1> is called the start-tag. Then comes the element's content, which in this case is the text "Acme Computer Corp.". Finally, </H1> is the end-tag.

This element is an H1 element, which happens to mean that it is a level 1 heading (we'll get to that later). You need tags to indicate where the element starts and where it ends. Tags always start with a less-than symbol (<) and end with a greater-than symbol (>). A start tag has the element's name in between these symbols, (in this case, H1). An end-tag has a slash (/) followed by the element's name. Here are some more examples of elements:

<H2>I'm an element.</H2>
<P>So am I!</P>
<P>Hey, me too! <B>And me!</B></P>
<P>There's another element after me.</P>
<HR>

The perceptive amongst you may have noticed a few things in the above elements: first, the B element is inside a P element. This is fine; you can have elements inside other elements, as long as you have proper nesting. This means that if an element starts within another element, it must end within that same element, like this:

<P>This is <B>right</B></P>
<P>This is <B>wrong</P></B>

The second line above is incorrect because the B element starts inside the P element, but ends outside the P element.

The second curious thing you should have noticed is that the HR element has no content and no end-tag. This is also allowed, for some element types. The HR element in this case is called an empty element. Using only a start-tag is permitted in this case, but only for elements that are empty.

Now that you know what an element is and how to specify it in your document, it's time to learn about some of the elements in HTML and use them to make your first HTML document.

Front Page12345

http://www.internet.com

Produced by Stephanos Piperoglou

All Rights Reserved. Legal Notices.

URL: http://www.webreference.com/html/tutorial1/3.html
Created: May 28, 1998
Revised: May 28, 1998