What Are Code Tags?
Computer programs and websites use different types of coding languages. Markup languages describe data items within tagged structures. HTML and XML are markup languages, both commonly used on the Web. HTML code defines Web pages, with content items arranged relative to one another. XML code defines data, with items of data arranged in hierarchical structures. Tags open and close elements, with the element content between two matching tags.
-
Elements
-
Markup elements in HTML define Web page content items. The following sample markup demonstrates:
<p>Here is some content</p>This represents a paragraph in a Web page. The paragraph element comprises an opening tag, then the element content, then the closing tag. The closing tag is identical to the opening tag, apart from the forward slash appearing before the element name. Each content item you see when you visit a Web page is included in this type of structure.
Content
-
Code tags surround element content in markup languages. Elements can contain media items, text and data, as well as other elements. When an element contains other elements, the contained elements are described as children, with the container considered the parent element. This results in tree structures, with many markup documents starting from a single root element, with multiple child elements branching out from it, as in the following XML example:
<wardrobe>
<garment>Skirt</garment>
<garment>Shirt</garment>
</wardrobe>In this case the parent element is the wardrobe, which contains two child elements, which are the garments. The garment elements could contain other child elements, resulting in deeper levels within the document structure.
-
Attributes
-
Markup elements can use attributes. These appear in the opening tag for an element, as follows:
<p class="description">Only opening tags can contain attributes, with the attribute value providing extra information about the element. Many HTML elements use attributes. Class attributes allow developers to define groups of elements in a page, for example to apply the same Cascading Sheet Style declarations to all of them. Adding an ID attribute to an element allows the developer to define the element as unique within the page, also useful with CSS. JavaScript functions also use element attributes to implement interactive effects.
Options
-
Although most elements appear with both an opening and a closing tag, some elements are self-closing. The following sample HTML code represents an image element in a Web page:
<img src="picturefile.jpg" alt="picture" />This element does not require a closing tag, as it closes itself. The source, or "src" attribute indicates the image file name and location so that the browser can fetch it. The "alt" attribute defines text to display if the image cannot be displayed. Both XML and HTML can use self-closing elements, but failing to close an element can result in errors when displaying or interacting with a markup document.
-
References
Resources
- Photo Credit Hemera Technologies/AbleStock.com/Getty Images