I believe that many beginners are like me and don’t understand how elements, tags, and attributes are defined in HTML, and what is the difference between elements and tags. In order to understand thoroughly, I specially searched and looked up some information. Now I wrote down the conclusions I have drawn and shared them with netizens who are equally confused as me:
Many people may not understand which one is called a label or which one is called an element, including me before, and they have always been confused.
In fact, the concept between the two is still very clear:
For example, <p>This is a tag;
<p>This is content</p>This is an element, that is, the element consists of a starting tag and an ending tag to contain certain content;
There is a noteworthy exception here, that is, <br/>it is both the start tag and the end tag, but it does not contain anything, so this is just a tag.
1. Elements :HTML web pages are actually text files composed of many various HTML elements, and any web browser can directly run HTML files. So it can be said that HTML elements are the basic objects that constitute HTML files, and HTML elements can be said to be just a general term. HTML elements are defined by using HTML tags.
2. Tags :Tags are objects wrapped in angle brackets such as <head>, <body>, <table>, etc., and most tags appear in pairs, such as <table></talbe>, <form></form>. Of course, there are a few that do not appear in pairs, such as <br>, <hr>, etc.
Tags are used to mark HTML elements. The text between the starting tag and the end tag is the content of the HTML element.
3. Properties :The HTML attribute that provides various additional information for HTML elements is the HTML attribute, which always appears in the form of a name-value pair such as attribute name= attribute value, and attributes are always defined in the start tag of the HTML element.
Example :<html> <head> <title>Example title</title> </head> <body bgcolor=red> <p>This is the sample page</p> </body> </html> In this example, <p>This is the sample page</p> is the HTML element, where this is the specific content of the element. <head><title><body> etc. are HTML tags, which are the tags that constitute HTML elements. bgcolor=red in <body bgcolor=red> is the attribute of the tag, which defines how the tag should be configured in detail. In short, there is no need to pay too much attention to the difference between elements and labels. In actual work, we all use labels to collectively refer to them. The attributes are easy to understand, they are parameters that add various additional information or configuration options to HTML tags.