Elements that Do Not Contain Content (Empty elements)
Not all elements contain content; some make declarations. These are called empty elements. One of the most
common elements of this type is the line break element:
<br />
A line break causes the page content to jump down to the next line, but doesn’t contain any content in itself.
You will notice that there is a forward slash just before the closing angle bracket; this is used in place of a
separate closing tag, because again, this element doesn’t contain any content, and therefore doesn’t need a
separate closing tag to signal when it ends. An empty element is merely a one-off statement which declares
that something should exist or happen at that particular point in the document.
Another example of an empty element is the image tag, shown below:
<img />
You may say, “An image can be a part of a page’s content. How is it that an image tag is not considered to
contain any content?” Good question. Images aren’t truly defined from within an HTML document the way
text is; they exist as a separate file which can be called into an HTML page. Since this is the case, you don’t
have to create the image content inside the HTML document, but merely state that it exists. However, you do
have to tell the browser where to find the image you want to use, and for that we are going to need to use an
element attribute.
Element Attributes
Using plain elements, like in the examples above, will get you started, but you will quickly want to spice things
up and modify some of the basic properties of your HTML content. The most basic way to modify an
element is to use an element attribute. Element attributes are pre-defined properties, specific to each individual
element, which can be given unique values in order to change the way an element behaves or appears. Here is
the basic syntax for defining an attribute within a content containing element and an empty element,
respectively.
<element attribute="value">Content</element>
<element attribute="value" />
Pay careful attention to the syntax of those two previous statements. First, notice that only the first tag
contains the attribute information. Also, the spacing of is important and should be emulated. There needs to
be a space between the name of the element and the name of the attribute, then an equal sign, then the value
inside quotations. If you don’t use that exact syntax then things are liable to break.
Let’s look at a more practical example. Earlier I mentioned that we would need to use an attribute to define
an image. Here is an image element with the image’s location defined by the source attribute:
<img src="happyface.jpg" />
Support Contact:
Daniel Gibson, Technology Development Coordinator ([email protected]; 439-8244) 11