How To Format Text in XHTML

Before you can begin formatting text in XHTML you have to understand how XHTML elements and attributes are used to present the data on a page on your website. There are several elements and attributes you can use to define and describe the content you wish to display. Understanding the XHTML tags will help you understand how these elements and attributes affect your content.

1. XML and HTML

There are differences between HTML and XML and they will be apparent to web designers who have been using HTML for a while. In HTML codes are not case sensitive unlike in XML which is strictly case sensitive and is written only in lower case. You can create your own tags in XML, which is not the case with HTML. When you use elements or tags in HTML you don’t necessarily have to close them with closing tags, XML requires that you properly close your tags so the content will be properly presented on the browser.

2. Attributes

Attribute names have to be written in lower case since XML is case sensitive so for example an attribute for table width should be written <table width=”100%”> and never with capital letters such as “Width” or “WIDTH”. This applies to all attribute names so make sure to write them properly. The XHTML attributes should not be shortened as it is in HTML, take this code for example <input type=”checkbox” value=”yes” name=”agree” checked> the check attribute was left as it is, where in HTML it is acceptable but when you use XHTML you should complete the code for example checked=”checked”.  Other attributes like selected, disabled, nohref, or noresize should be written properly as selected=”selected, disabled=”disabled=”disabled”, nohref=”nohref”, noresize=”noresize”. Name attribute is no longer used in XHTML for elements like img, iframe, applet, and frame. In its place we use the “id Attribute”. Instead of using the code or images <img src=”picture.jpg” name=”pic” /> we use <img src=”picture.jpg” id=”pic” /> in XHTML.

3. XHTML Elements

Elements are used in XHTML as tags that contain attributes and data. They define which parts of the code are paragraphs, headings, inserted media, tables or links. Block elements may contain the various levels of headings using the h1, h2, h3, h4, h5, and h6 tags. They also contain <p></p> tags to indicate a paragraph. Other examples of block elements are table tags <td></td>, <tr></tr> and unordered list using the code <ul></ul>.

Understanding the differences between XHTML and HTML will help you produce clean codes that are widely accepted by browsers and applications. W3C or the World Wide Web Consortium has agreed to make XHTML the standard and it will do away with incompatible web pages and make formatting easier for all web designers.


Share this article!

Follow us!

Find more helpful articles: