coding180 icon

Coding180

Html Elements: Paragraph

Html Elements: Paragraph

Tutorials > HTML > HTML Elements


A paragraph is a sentence or group of sentences referring to the same topic. Anything between the <p> and </p> tags will be considered as a paragraph by the browser.

Example

<p>This is a paragraph</p>
<p>This is another paragraph</p>

<p> is a block-level element, the Browsers automatically add blank lines before and after paragraphs.

Tip: It is a bad practice to use an empty paragraph tag <p></p> to insert a blank line. Replace it with a <br /> tag!

Don't forget the closing tag

Even if you forget to use the closing tag, most browsers will display the HTML correctly:

Example

<p>This is a paragraph
<p>This is another paragraph

The above example will work fine in most browsers, but don't rely on this practice. Forgetting to use closing tags can produce unexpected results and errors.

Tip: Closing HTML with closing tags is a future-proof way to write HTML. Clearly marking where an element starts and ends makes the code easier to understand, both for you and the browser.

HTML wrapping

If you want a line break (new line) without generating a new paragraph, use the <br /> tag:

<p>This is<br />a para<br />graph with line breaks</p>

The <br /> is a self closing tag and doesn't need another closing tag.

<br> or <br />

You may find that <br> is very similar to <br />.

In XHTML, XML, and future versions of HTML, HTML elements without closing tags (closing tags) are not allowed.

Even if <br> displays fine in all browsers, using <br /> is a longer-term guarantee.

HTML output - useful hints

We cannot be sure of the exact effect of the HTML being displayed. The size of the screen, and the resizing of the window can all lead to different results.

For HTML, you cannot alter the output by adding extra spaces or line breaks to the HTML code.

When the page is displayed, the browser removes extra spaces and blank lines from the source code. 

Note that all consecutive blank lines (newlines) in the HTML code are also displayed as a single space.

Tip: To remember the name of this HTML element: 

<p> comes from the word paragraph


user

Robort Gabriel

Lagos, Nigeria

Freelance Web Developer, Native Android Developer, and Coding Tutor.

Skills
  • UI / UX
  • JavaScript
  • Python
  • PHP
  • Kotlin
  • Java
  • Bootrap
  • Android
  • Laravel