Home >> FAQs/Tutorials >> XHTML Tutorials and Tips >> Index

XHTML Tutorials - Introduction To Tag and Attribute Syntax

By: FYICenter.com

Part:   1  2  3  4  

(Continued from previous part...)

How To Write Ampersand Sign in Attribute Values?

If you need enter an ampersand sign in an attribute value, you can not enter it directly. You must replace it with entity: &.

Here are some interesting examples of quoted attribute values:

  • <img src="tt.gif" alt="Tutorials &amp; Tips"/> - Valid.
  • <img src="tt.gif" alt="Tutorials & Tips"/> - Invalid, & must be replaced by entity &amp;.

What Is a Required Attribute?

A required attribute is an attribute required by the XHTML element. When you write an XHTML element, you must include all attributes required by this element in the opening tag. Optional attributes can be omitted in the opening tag.

Here are some examples of required attributes:

  • <form action="submit.php"> - "form" element requires one attribute: "action".
  • <script type="text/javascript"> - "script" element requires one attribute: "type".
  • <img src="fyi.gif" alt="FYI"/> - "img" element requires two attributes: "src" and "alt".

What Are Predefined Attribute Values?

Some XHTML attributes have predefined values. If an attribute has predefined values, you must use one of the predefined values.

For example, attribute "valign" of element "td" has 4 predefined values "baseline", "bottom", "middle", and "top". Here are some examples of how to use "valign" attribute:

  • <td valign="top"> - Valid, "top" is one of the predefined values of "valign".
  • <td valign="center"> - Invalid, "center" is not a predefined value of "valign".

What Is Wrong with My "checked" Attribute Values?

Attribute "checked" is an optional attribute for XHTML element "input". In XHTML specification, attribute "checked" has only predefined value: "checked". However, in HTML specification, attribute "checked" requires no value.

If you are converting existing HTML documents to XHTML format, you will get some syntax error on your pre-selected items in radio buttons, check boxes and dropdown lists, "checked" attributes are used without any values.

Here are some interesting examples of "checked" attributes:

  • <input type="radio" name="lang" value="HTML" checked> - Invalid, all attributes must have values. This is valid as HTML documents.
  • <input type="radio" name="lang" value="HTML" checked="yes"> - Invalid, "yes" is not the predefined value of attribute "checked".
  • <input type="radio" name="lang" value="HTML" checked="checked"> - Valid, attribute "checked" is assigned with predefined vlaue "checked".

Part:   1  2  3  4  


Selected Developer Jobs:

More...