Google News
logo
UI Developer - Interview Questions
What is the difference between a tag and an attribute in HTML?
Tags and attributes are two concepts used in HTML. They work together but perform different functions. The main difference between an HTML tag and an HTML attribute is that an HTML tag is a way of representing an HTML element in the program. On the other hand, an HTML attribute describes the characteristics of an HTML element.

For example : <a>, <href>, <button>, and <div> etc. are HTML tags and src, class, and id etc. are the example of HTML attributes.
 
See this example :
<img src="myhome.jpg" alt="A photo of my home.">  
In the above example, the image source (src) and the alt text (alt) are attributes of the <img> tag.
 
Difference between HTML tags and HTML attributes :

HTML Tags HTML Attributes
HTML tags are generally the starting and ending parts of the HTML code. HTML attributes are used to define the character of the HTML elements.
HTML tags define a way to represent and hold HTML elements in the program. HTML attributes are generally used to provide additional styling to the element.
HTML tags begin with < symbol and end with > symbol. HTML attributes are always placed in the opening tag of an element.
HTML tags are like keywords where every single tag has a unique meaning. HTML attributes provide various additional properties to the existing HTML element.
Advertisement