HTML elements
1. What are HTML elements?
In the first chapter, in order to avoid conceptual confusion when introducing tags, we briefly introduced HTML elements. , here we will start to introduce HTML elements in detail.
HTML elements refer to all code from the start tag to the end tag. 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 a general term. HTML elements are defined using HTML tags.
<Start tag> Element content <End tag>
This is an element:
<p>PHP中文网</p>
2.HTML element syntax
HTML elements start with a start tag
HTML elements end with an end tag
The content of the element is the content between the start tag and the end tag
Some HTML elements have empty content
Empty elements are closed in the opening tag (end with the end of the opening tag)
Most HTML elements can Have attributes (will be discussed below)
3. HTML element nesting
Example Let’s take a look at the previous example. , there are several elements in the following example:
<html> <body> <p>PHP中文网</p> </body> </html>
The answer is of course three, it should be easy to understand, this is the so-called nesting.
4. HTML empty element
An HTML element without content is called an empty element. < br> is an empty element without a closing tag (the < br> tag is used to define line breaks). In XHTML, XML, and future versions of HTML, all elements must be closed. Adding a slash to the opening tag, such as < br/>, is the correct way to close an empty element. Even though < br> is valid in all browsers, using < br/> is actually more efficient. Long-term protection, after saying so much, I just want to use < br/> when changing lines in the future.
We saw from the example earlier that after the < p> tag ends, there is also a line break action. Now let’s introduce it. Let me show you the < p> tag and < br> The difference between tags
The same thing is that both br and p have line-break attributes and meanings
The difference between < br/> is that only one of them needs to be used alone, while < p> and < /p> is a pair of lines using
. The br tag is a small line break (equivalent to a carriage return when we usually enter text), and the p tag is a large line break (paragraph, equivalent to two carriage returns). ) function of each line.
Let’s take a look at the difference between the two tags. Let’s do a < br/>line break
One more < p>< /p>line break
##This time You will definitely have a better grasp of them in the future