What is an attribute What is an attribute

In the previous tutorial you understood about a tag and how a tag is written. In this tutorial you will learn about an important concept very closely related to a tag - attributes. Attributes are used to add more meaning to a tag. It might not be possible to learn a markup language without having a good understanding about attributes. So let's try to learn about attributes and how they are used with tags.

English grammar teaches us about a Noun and adjectives. An adjective is a property of a noun. For example, Apple IPhone is a noun and its cost is one of its adjectives (property that describes an object). Similarly, color is another adjective of this phone. So if we use only tags to write information about mobile phones, it will be written in the following format

<Phone>  
    <Name> Apple IPhone 5 </Name>  
    <Cost> Rs 50,000 </Cost>  
    <Color> Black </Color>  
</Phone>  

<Phone>  
    <Name> Samsung Note 2 </Name>
    <Cost> Rs 45,000 </Cost>  
    <Color> White </Color>  
</Phone>

We have used tags to write code and provide information about two phones. We have described 3 properties about each phone - name, cost and color.

Questions: How many lines of code we have written above to provide information about phones, its cost and color ?

Answer: 10 lines of code

Question: Can we provide the same information above in just 2 lines?

Answer: Yes.

Question: How?

Answer: Using attributes along with tags.

What is an attribute?

So what is an attribute? An attribute is used to provide additional information about a tag. It’s written inside the opening of the tag using name / value pairs.

Let’s write the same information written above about phones again using tags and attributes
 
Image 
 
We have written the same information by adding attributes to tags. Let’s explain the above code

<Phone> is a Tag.

name, cost and color are its attributes. Each attribute has a name and a value. In the above code cost is an attribute and Rs 50,000 is its value. Color is an attribute and Black is its value. Using attributes, you can provide additional information about a tag in just one line.

All the tags you will learn in HTML come with their own attributes. You should know about these attributes in order to properly use a tag.

Need Learning Guidence?
Join our Study Groups and get step by step guidence.
Learn HTML and CSS
The goal of creating this study group is to help students who are beginners to HTML and CSS program
7
Members
1
Questions Asked
0
Tasks Added
Learn Website Development
This goal of this study group is to help students learn the basics of website development using HTM
1
Members
0
Questions Asked
0
Tasks Added
Website Development Interview Preparation
This goal of this study group is to help students prepare for their website development interviews.
1
Members
0
Questions Asked
0
Tasks Added
Web Wars 1.0 - Build Your Digital CV
The goal of this study group is to manage all the communication for the 'Web Wars 1.0 - Build Your
110
Members
0
Questions Asked
0
Tasks Added

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp