Click here to Skip to main content
6,629,377 members and growing! (21,018 online)
Email Password   helpLost your password?
Web Development » HTML / CSS » XHTML     Intermediate License: The Microsoft Public License (Ms-PL)

Five XHTML Elements You Didn't Know But Were Afraid to Ask

By Adam Tibi

Exploring five useful XHTML/HTML elements that are important but not commonly used. Moreover, pointing to their relation with Internet Explorer, Firefox, and ASP.NET.
HTML, XHTML, Windows, .NET, ASP.NET, Visual Studio, Dev
Posted:5 May 2006
Updated:15 May 2006
Views:138,716
Bookmarked:130 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
123 votes for this article.
Popularity: 9.53 Rating: 4.56 out of 5
2 votes, 1.6%
1

2
7 votes, 5.7%
3
32 votes, 26.0%
4
82 votes, 66.7%
5

Introduction

With experience, working with ASP.NET, I noticed some important XHTML tags that are rarely used by web developers, even the experienced ones, so I thought of writing this article to promote them.

Most of the mentioned elements are HTML compatible, but all of them are XHTML compatible. I've tested these elements on Internet Explorer 6 and Firefox 1.5. Also, I've validated the demo project against XHTML 1.1 and XHTML 1.0 Transitional on the W3C Validator.

The elements are optgroup, label, fieldset/legend, col/colgroup and acronym. In this article, I point out the differences in displaying each of these elements between IE and Firefox, moreover, I show their relation with ASP.NET. What follows is a quick introduction for each element:

1. optgroup

optgroup sample

<label for="county">County</label>
<select id="county">
    <optgroup label="England">
        <option>Surrey</option>
        <option>Kent</option>
    </optgroup>
    <optgroup label="Scotland">
        <option>Orkney</option>
    </optgroup>
</select>

<label for="languages">Languages</label>
<select size="6" multiple="multiple" id="languages">
    <optgroup label="Classical">
        <option>C#</option>
        <option>C++</option>
        <option>Java</option>
    </optgroup>
    <optgroup label="Web">
        <option>ASP.NET</option>
        <option>PHP</option>
    </optgroup>
</select>

The optgroup, which stands for Option Group, is an element that groups a set of option elements, inside a select element, and labels them. It is perfect for showing states and cities, countries and states, and other similar categorized items.

Unfortunately, this element is not generated by any ASP.NET server controls, however, I believe you can easily inherit from the DropDownList, ListBox, or the Item controls and make the necessary modifications to generate it.

2. label

label sample

<label for="FirstName">Full Name</label>
<input id="FirstName" type="text" />
Gender: 
<label for="male">Male</label>
<input id="male" type="radio" name="gender" />
<label for="female">Female</label>
<input id="female" type="radio" name="gender" />

The label element provides a caption for a form element. Its main attribute is the "for" attribute which will point to the element that you want to provide a caption for.

In addition to providing a caption for the element, label will make selecting the associated element easier; so by clicking on the caption, you will be setting focus to the associated element, as if it is making the caption text a part of the associated element. In the provided demo, try clicking on the word "Full Name" and the text box next to it will be selected; also, when you click on the word "Male", the radio button will be selected.

ASP.NET generates this element for the Text property of the RadioButton and CheckBox server controls (and other controls as well). This explains the secret of setting focus to the control whenever clicking the text next to it. In ASP.NET 2.0, the Label server control has a new attribute AssociatedControlID that will render the control as an HTML label associated to the specified element versus rendering it as a span element.

3. fieldset/legend

fieldset sample

<fieldset>
    CP is a good place to publish XHTML related articles. 
</fieldset>

<fieldset>
    <legend>Personal Information</legend>
    <label for="FirstName">Full Name</label>
    <input id="FirstName" type="text" />
    Gender: 
    <label for="male">Male</label>
    <input id="male" type="radio" name="gender" />
    <label for="female">Female</label>
    <input id="female" type="radio" name="gender" />
</fieldset>

The fieldset is an element that creates a frame, and legend is an optional element that creates a title for this frame.

In ASP.NET 2.0, there is a new attribute GroupingText for the Panel web control that will render it a legend and fieldset. However, ASP.NET 1.1 doesn't have any standard web control that could generate this element.

4. col/colgroup

optgroup sample

<table border="1">
    <colgroup>
        <col width="150px" />
        <col width="10px"  />
        <col width="220p" />
    </colgroup>
    <tr>
        <td valign="top">1</td>
        <td> </td>
        <td>2</td>
    </tr>
    <tr>
        <td>3</td>
        <td> </td>
        <td>4</td>
    </tr>
</table>

The colgroup element is a table element. Its only child element is the col element. Each col element affects a column in the table. You can specify attributes that apply to all the columns in the colgroup element, and specific attributes for individual columns in the col element. You can also omit the colgroup element and keep the col elements.

The advantage of using the col element is that you only need to specify an attribute once rather than adding the same attribute across every td element in the column, and the result is less attributes and easier to manage code.

For cross-browser issues, use the width attribute only with the colgroup and col elements because I noticed that Firefox doesn't support all the attributes of the colgroup and col.

Sadly, the ASP.NET's Table and GridView server controls do not generate these elements.

5. acronym

acronym sample

<acronym title="Code Project">CP</acronym> is a good place to publish 
<acronym title="Extensible HyperText Markup Language">XHTML</acronym>
related articles.

The acronym element provides a definition for a term via the title attribute. By using this element, you are helping readers who are not familiar with the term, better optimizing your page for search engines and supporting accessibility.

By default, IE 6 doesn't show any sign on the text surrounded by this element; however, Firefox displays a dashed line under it. Both browsers display a tool tip of the full meaning whenever you stop your cursor over it.

If you like this element, have a look at the abbr (abbreviation) element which has a similar role.

Conclusion

I have spotted some elements that I thought need to have extra light on; however, there are more hidden elements to spot like th, tf, base, address, bdo, blockquote, code, dl, dt, dd, and dfn elements.

This article served as a quick reference for each element; for a full list of the attributes and usage, try the W3 Schools, htmldog.com, and you can always go back to the official documentations at the World Wide Web Consortium.

If you found the contents of this article useful, then please remember to vote.

History

  • 25 April 2006 - First version.
  • 10 May 2006 - Second version.
  • 13 May 2006 - Third version.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

Adam Tibi


Member
New technology addict and C# fan. Started developing commercial applications in 2000 with VB6 and MFC then moved to VB.NET, landed on C# and ASP.NET and never looked back.
Currently focusing on enterprise architecture, design patterns, web development, web controls and web services. Lives in Guildford/Surrey, UK.
Looking to hire .NET Software Consultant in London or South East UK?
Adam Tibi Blog on ASP.NET, C# & SEO
Occupation: Web Developer
Location: United Kingdom United Kingdom

Other popular HTML / CSS articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 58 (Total in Forum: 58) (Refresh)FirstPrevNext
RantFieldset Must always have a Legend PinmemberUgot2BkidNme7:54 8 Jun '09  
GeneralGood article!.. Pinmemberbgriffin_tpa5:51 26 Jul '07  
GeneralRe: Good article!.. Pinmemberkevnord6:42 26 Jul '07  
GeneralRe: Good article!.. Pinmemberbgriffin_tpa8:25 26 Jul '07  
GeneralRe: Good article!.. Pinmemberbgriffin_tpa12:45 26 Jul '07  
GeneralOPTGROUP Pinmemberbiggun9:38 17 Jul '07  
GeneralRe: OPTGROUP PinmemberAdam Tibi0:28 18 Jul '07  
GeneralNice Article Pinmembersmsayami12:27 16 Jul '07  
GeneralGood One! PinmemberCharuT15:01 29 Oct '06  
GeneralClarification re: label PinmemberVBScab22:22 18 Sep '06  
GeneralRe: Clarification re: label PinmemberAdam Tibi9:34 19 Sep '06  
GeneralYou missed Caption PinadminChris Maunder16:52 23 May '06  
GeneralGreat Things But..... PinmemberSameers (theAngrycodeR )14:07 21 May '06  
GeneralRe: Great Things But..... PinmemberAdam Tibi23:57 21 May '06  
GeneralRe: Great Things But..... Pinmemberxxrono11:10 7 May '07  
GeneralRe: Great Things But..... PinmemberAdam Tibi23:44 7 May '07  
Generalfieldset rounded corners Pinmemberwebber1234569:02 13 May '06  
GeneralRe: fieldset rounded corners PinmemberAdam Tibi9:24 13 May '06  
GeneralRe: fieldset rounded corners Pinmemberwebber12345610:40 13 May '06  
GeneralRe: fieldset rounded corners PinmemberJon Rista20:26 16 Jun '06  
GeneralRe: fieldset rounded corners Pinmemberxxrono2:25 8 May '07  
GeneralClarification acronym vs. abbr Pinmemberl0b023:38 10 May '06  
GeneralRe: Clarification acronym vs. abbr PinmemberAgeKay12:06 12 May '06  
GeneralRe: Clarification acronym vs. abbr Pinmemberl0b00:54 13 May '06  
GeneralRe: Clarification acronym vs. abbr PinmemberAgeKay1:19 13 May '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 15 May 2006
Editor: Smitha Vijayan
Copyright 2006 by Adam Tibi
Everything else Copyright © CodeProject, 1999-2009
Web19 | Advertise on the Code Project