Quick Contact

     

    HTML Paragraphs

    Creating Paragraphs

    Paragraph element is used to publish text on the web pages.

    Paragraphs are defined with the < p> tag. Paragraph tag is a very basic and typically the first tag you will need to publish your text on the web pages. Here’s an example:

    < !DOCTYPE html>
    < html lang="en">
    < head>
    < title>Creating Paragraphs in HTML< /title>
    < /head>
    < body>
    < p>Write paragraph.< /p>
    < p>Write another paragraph.< /p>
    < /body>
    < /html>
    

    Output

    Write paragraph.

    Write another paragraph.

    Note:

    Browsers built-in style sheets automatically create some space above and below the content of a paragraph (called margin), but you can override it using CSS.

    Closing a Paragraph Element

    In HTML 4 and earlier versions, it was enough to initiate a new paragraph using the opening tag. Most browsers will display HTML correctly even if you forget the end tag.

    Example:

    < !DOCTYPE html>
    < html lang="en">
    < head>
    < title>Closing HTML Paragraphs< /title>
    < /head>
    < body>
    < p>Write paragraph.
    < p>Write another paragraph.
    < p>< strong>Note:< /strong> Always close the paragraphs otherwise it shows unexpected results or errors!< /p>
    < /body>
    < /html>
    

    Output

    Write paragraph.

    Write another paragraph.

    Note:

    Always close the paragraphs otherwise it shows unexpected results or errors.

    Note:

    For the purposes of forwards-compatibility and good coding practice, it’s advisable to use both the opening and closing tags for the paragraphs.

    Creating Line Breaks

    The < br> tag is used to insert a line break on the web page.

    Since the < br> is an empty element, so there is no need of corresponding < /br> tag.

    Example

    < !DOCTYPE html>
    < html lang="en">
    < head>
    < title>Inserting Line Breaks in HTML< /title>
    < /head>
    < body>
    < p>Write paragraph < br> with line break.< /p>
    < p>Write < br>another paragraph < br> with line breaks.< /p>
    < /body>
    < /html>
    

    Output

    Write paragraph
    with line break.
    Write
    another paragraph
    with line breaks.
    

    Note:

    Don’t use the empty paragraph i.e. < p>< /p> to add extra space in your web pages. The browser may ignore the empty paragraphs since it is logical tag. Use the CSS margin property instead to adjust the space around the elements.

    Creating Horizontal Rules

    You can use the < hr> tag to create horizontal rules or lines to visually separate content sections on a web page. Like < br>, the < hr> tag is also an empty element.

    Here’s an example:

    < !DOCTYPE html>
    < html lang="en">
    < head>
    < title>Creating Horizontal Lines in HTML< /title>
    < /head>
    < body>
    < p>Write paragraph.< /p>
    < hr>
    < p>Write another paragraph.< /p>
    < /body>
    < /html>
    

    Output

    Write paragraph.
    ________________________________________
    
    Write another paragraph.
    

    Managing White Spaces

    Normally the browser will display the multiple spaces created inside the HTML code by pressing the space-bar key or tab key on the keyboard as a single space. Multiple line breaks created inside the HTML code through pressing the enter key is also displayed as a single space.

    The following paragraphs will be displayed in a single line without any extra space:

    Example

    < !DOCTYPE html>
    < html lang="en">
    < head>
    < title>White Space Collapsing in HTML< /title>
    < /head>
    < body>
    < p>In this paragraph it contains  multiple   spaces    in the source code.

    < p> In this paragraph it contains multiple tabs and line breaks in the source code. < /p> < /body> < /html>

    Output

    In this paragraph it contains multiple spaces in the source code.

    In this paragraph it contains multiple tabs and line breaks in the source code.

    Defining Preformatted Text

    Sometimes, using & nbsp;, < br>, etc. for managing spaces isn’t very convenient. Alternatively, you can use the < pre> tag to display spaces, tabs, line breaks, etc. exactly as written in the HTML file. It is very helpful in presenting text where spaces and line breaks are important like poem or code.

    The following example will display the text in the browser as it is in the source code:

    Example

    < !DOCTYPE html>
    < html lang="en">
    < head>
    < title>HTML Preformatted Text< /title>
    < /head>
    < body>
    < pre>
    	Humpty Dumpty sat on a wall,
    	Humpty Dumpty had a great fall.
    	Four-score Men and Four-score more,
    	Could not make Humpty Dumpty where he was before.
    < /pre>
    < /body>
    < /html>
    

    Output

    	Humpty Dumpty sat on a wall,
    	Humpty Dumpty had a great fall.
    	Four-score Men and Four-score more,
    	Could not make Humpty Dumpty where he was before.
    

    FAQS

    Q1. How to write a paragraph in HTML?

    A paragraph is defined by the HTML element. A paragraph normally begins on a new line, so browsers add additional white space (a margin) before and after it.

    Q2. How to add a paragraph in HTML CSS?

    A paragraph is defined by the < p> tag. Browsers insert a single blank line before and after each element. To style paragraphs, use CSS.

    Q3. What is paragraph breaks in HTML?

    The HTML element causes a line break in the text (carriage-return). It is beneficial when composing a poem or an address where the line separation is important.

    Q4. What are paragraph tags?

    The paragraph tags are used to identify a section of text as a paragraph. This HTML element is one of the fundamental HTML tags that you should understand how to utilize correctly.

    Copyright 1999- Ducat Creative, All rights reserved.

    Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.