XHtml Attributes are defined as the
name/value pairs
Eg: href=”URL” ((href= name) and(URL=value)). XHtml elements have several types of attributes to display the various types of information. The attributes should be added in starting tags only, the below figure explains about the attributes.
The code below demonstrates the Attributes of the xhtml elements.
[html]
<!DOCTYPE html>
<html>
<body>
<a href="http://www.splessons.com/">This is a link</a>
</body>
</html>
[/html]
Result
By running the above code in a preferred browser user can get the following output as shown in below image.
Rules and Values
XHTML Attribute possess some rules. Following are some of the rules to be followed while using attributes.
- Attribute should involve in starting tag only and never use in ending tag.
Eg: <a href=”splessons.com”> splessons</a>
- Name and value pair should be linked with equal sign (=).
Eg: href=”splessons.com”
- Attributes values always use with in quotes only, it should be either single quotes (‘ ….’) or double codes(“….”).
- Name/value pairs are always in lower case only which is recommended by
World Wide Web Consortium (W3C).
XHTML elements have some attributes, these attributes defines some more information about elements.User have to give attributes always in start tag, and it will come as pair i.e.
Syntax
[html]
<tagname attributename="Value"></tagname>
[/html]
XHTML allows to write multiple for a single tag as shown below.
[html]
<a href="http://www.splessons.com/" class="myclassname" ></a>
[/html]
The code below demonstrates the XHTML attributes as shown below.
[html]
<html>
<a href="http://www.splessons.com/">Click Here to go SPLessons Home Page</a> <!-- Anchor tag used in navigation.-->
<br />
<br />
<img src="http://www.splessons.com/wp-content/uploads/2013/11/SPLessonsSmall.png" alt="Logo" /> <!-- img tag used display images in web page.-->
</html>
[/html]
Result
By running the above code in a preferred browser user can get the following output as shown in below image.