How To Understand the Basics of XHTML Tags and Attributes

XHTML uses tags and attributes to describe and define the ways to display data or content. In XHTML you can design your website by creating the way your content is to be presented to the people who visit the website. We will explore a few tags and attributes that are commonly used in XHTML.

1. Tags within tags

It is possible to have only one tag in a XHTML code but it is also possible to have two or more tags within a tag. Take for example the body tag written in XHTML as <body></body>. Content goes between the beginning and closing tags of the body element but there can be several other tags that define each part of the content that goes between the body tags. For example <body><h1>this is an example</h1><p>hello there</p></body>. The code begins with a body tag followed by the h1 tag that formats the text “this is an example” into a heading with bold font and then followed by the paragraph tag <p>. Each is closed with the proper closing tags. You will notice that several other tags were placed between the beginning and closing body tags and another tag between the heading tags.

2. Attributes to format elements

In the above example no attributes to format the content were made. But you can change how the content appears with attributes. Take for example the body tags; you can define how the body tag will appear with attributes. We can change how the background for the content will appear by writing <body bgcolor=”blue”>hello there</body> in XHTML code and the color for the content background will take on a blue tone.

3. Writing Attributes

Writing the codes in XHTML must be done carefully as one wrong tag or attribute condition can stop the code from doing what is intended to do. Attributes contain a name and a value and have an equal sign to separate them from each other. The above example <body bgcolor=”blue”> shows the name of the attribute, the equals sign, and then the value. You must remember that tags and attributes have to be written in lower case letters. You can have several attributes within a tag as in this tag for a heading <h2 style="font-family: Georgia,serif; font-size: 18px; font-weight: bold; color: #000000;">hello there!</h2>. In this example the font, font size, font weight and color have been set to display the heading in a certain way.

There is a standard list of tags and attributes used in XHTML that you have to be familiar with if you want to present a well organized website. Tags and attributes will help you create the exact look and feel you are trying to achieve on the pages of your website.


Share this article!

Follow us!

Find more helpful articles: