What is a Paragraph in HTML?
For anyone who is new to HTML, the way paragraphs are recognized in HTML can seem a bit strange. If you have experience with text processing programs, most likely you expect that you press Enter and this is how you tell the program to put a paragraph.
However, pressing the Enter key doesn’t help in HTML. Unlike in word processing programs, in a code-based HTML editor, Enter is not the end of a paragraph. When you press Enter in the HTML code, you just start typing your code/text on a new line but you are still in the same paragraph.
If you want to tell HTML to end a paragraph and start a new one, you need to use the tag. The tag is the way to make HTML recognize a paragraph. For instance,
displays the “This is a new paragraph.” in the browser (without the quotes, of course).
As most HTML tags, the tag is used for opening a paragraph and the closing tag is used to mark the end of a paragraph. Though you can omit the closing tag, it is recommended not to do it because in some browsers this paragraph might not display properly. Also, since most other tags require a closing paragraph, it is more consistent if you close tags as well.
When your paragraphs are not properly put, this can cause a lot of issues. For instance, if you use a stylesheet to apply formatting on a paragraph-level and you don’t use the tag to mark the beginning of a paragraph but use other gimmicks instead, you will see that your text looks formatted in a way that you don’t expect. When you apply paragraph-level formatting, it affects everything between the opening tag and the closing tag (or the next tag, if you don’t close the opening tag).
Paragraphs and Line Breaks in HTML
As in text processing programs, in HTML a paragraph starts on a new line but not every new line is necessarily a separate paragraph. Very often it is necessary to place some text on a new line but keep it with the previous paragraph. In both text processing with Microsoft Word or a similar program and in HTML you can do this with a line break.
Unlike Microsoft Word, in HTML there is no use in pressing Shift+Enter while in code view. If you are using a visual HTML editor, it might be possible to use Enter to end a paragraph and Shift+Enter to put in a line break, but in HTML source these keys don’t help. Instead, you can use the tag to split a line. The tag is an exception to all rules because it has no closing counterpart.
Here is how to use the tag to put in a line break:
The above example will be displayed in the browser like this:
This is a new paragraph
with a line break.
Paragraphs are fundamental to HTML and this is why it is really important to learn how to put paragraph space in HTML. On the other hand, paragraphs are among the easiest concepts in HTML, so it will hardly take you much effort to master them.