HTML can divide a document into several paragraphs. The paragraph tag <p> can be used in HTML to divide the content of the document into several paragraphs. The syntax format is as follows:
<p>Paragraph, content. </p>
The paragraph tag consists of a start tag <p> and an end tag </p>. The content between the start tag and the end tag will be regarded as a paragraph. The paragraph tag is a very basic tag that we use when publishing articles on the web.
Section:
1. HTML paragraphs are defined through <p> tags.
Note: Browsers automatically add blank lines before and after paragraphs. (</p> is a block-level element)
2. Don’t forget the closing tag
Even if you forget to use the closing tag, most browsers will display the HTML correctly:
<p>This is a paragraph<p>This is another paragraph
The running results are shown in the figure below:
The example above will work fine in most browsers, but don't rely on this approach. Forgetting to use closing tags can produce unexpected results and errors.
Note: In a future version of HTML, omitting the closing tag will not be allowed.
3. HTML line wrapping
If you want to wrap (new line) without creating a new paragraph, use the <br> tag:
Example:
<p>This<br>paragraph<br> demonstrates the effect of branching</p>
The running results are shown in the figure below:
The <br /> element is an empty HTML element. Since a closing tag doesn't make any sense, it doesn't have a closing tag.
4. HTML output - using reminders
We cannot determine the exact effect of the HTML being displayed. The size of the screen and adjustments to the window may lead to different results.
With HTML, you cannot change the output by adding extra spaces or line breaks to the HTML code.
When displaying the page, the browser removes extra spaces and blank lines from the source code. All consecutive spaces or empty lines are counted as one space. Note that all consecutive empty lines (newlines) in HTML code are also displayed as a space.
<!DOCTYPEhtml><html><head><metacharset=utf-8><title>C Language Network (dotcpp.com)</title></head><body><h1>春晓</h1><p> When I sleep in spring, I don't realize the dawn. <p>I hear birds singing everywhere. <p>The sound of wind and rain comes at night, <p>How many flowers have fallen. <p></p><p>Note that the browser ignores typography in the source code (extraneous spaces and line breaks are omitted). </p></body></html>
The running results are shown in the figure below:
5. White space in paragraphs
By default, the paragraph tag will merge the whitespace characters in the text and display multiple consecutive whitespace characters as one space. The specific performance is as follows:
(1) If multiple consecutive spaces appear in a paragraph, the browser will ignore these spaces and keep only one;
(2) If multiple consecutive line breaks appear in a paragraph, the browser will convert these line breaks into a space.
Example display:
<!DOCTYPEhtml><html><head><metacharset=UTF-8><title>C Language Network (dotcpp.com)</title></head><body><p>C Language Network (dotcpp.com) , an online learning programming website, URL: <ahref=https://www.dotcpp.com/target=_blank>https://www.dotcpp.com/</a></p><p>C language The website has currently released tutorials for nearly <b>15</b> modules, including HTML, C language, C++, JavaScript and other modules. You can <ahref=https://www.dotcpp.com/course/target= _blank>Click here</a> to view all tutorials. </p><p>Our purpose: a website that helps everyone learn programming in a down-to-earth manner. </p></body></html>
The running results are shown in the figure below: