The Wayback Machine - https://web.archive.org/web/20240823025404/https://www.geeksforgeeks.org/html-paragraph/
Open In App

HTML Paragraphs

Last Updated : 22 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The <p> tag in HTML signifies a paragraph. Enclosed within the opening <p> and closing </p> tags, any content is recognized as a paragraph. As a block-level element, a new paragraph inherently starts on a fresh line, with browsers intuitively adding space before and after a paragraph for enhanced readability.

Syntax:

<p> Content </p>

Properties of the paragraph Tag

  • The browser reduces multiple spaces added by users to a single space.
  • If a user adds multiple lines, the browser compresses them into a single line.
  • By default, the display of the paragraph element is set to “block,” meaning each new paragraph is placed on a new line. This behavior can be modified using CSS.

Example 1: The example explains the HTML <p> tag.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0">
    <title>The p tag</title>
</head>

<body>
    <p>A Computer Science portal for geeks.</p>
    <p>It contains well written, well thought articles.</p>
</body>

</html>

Output:

Multiple p Tags

Example 2: This example explains the HTML <p> tag having multiple lines.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0">
    <title>HTML p tag</title>
</head>

<body>
    <p>
        This paragraph has multiple lines.
        But HTML reduces them to a single line,
        omitting the carriage return we have used.
    </p>
    <p>
        This paragraph has multiple spaces.
        But HTML reduces them all to a single
        space, omitting the extra spaces and 
          line we have used.
    </p>
</body>

</html>

Output:

p tag with multiple lines

The <br> tag

The HTML <br> tag element creates a line break, giving you a new line without starting a new paragraph. Use <br> when you want to move to the next line without beginning a whole new paragraph.

Syntax:

 <br>

Example: This example explains the <br> tag inside the <p> tag to add the line-break.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0">
    <title>HTML paragraph
    </title>
</head>

<body>
    <p>
        This paragraph has multiple
        <br />lines. But HTML reduces them
        <br />to a single line, omitting
        <br />the carriage return we have used.
    </p>
</body>

</html>

Output:

Use of br tag inside the p tag

The <hr> tag

The HTML <hr> tag is used to create a horizontal rule or line, visually separating content on a webpage. Use <hr> when you want to insert a horizontal line to signify a division between sections or elements, providing a clear visual break in the page.

Syntax: 

 <hr>

Example: In this example we will use the <hr> tag with an example by using <p> tag also.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0">
    <title>HTML Horizontal Rule Example</title>
</head>

<body>
    <h1>
        Welcome to My Website
    </h1>

    <p>
        GeeksforGeeks is a leading
        platform that provides computer
        science resources and coding challenges
    </p>

    <hr>

    <p>
        GeeksforGeeks is a leading platform
        that provides computer science resources
        and coding challenges
    </p>
</body>

</html>

Output:

Screenshot-2023-12-18-152336

Output

Align attribute

The <p> tag specifically supports the alignment attribute and allows us to align our paragraphs in left, right, or center alignment. 

Syntax: 

<p align="value">

Note: The align attribute is deprecated in HTML5, and styles should be used via CSS for better practices.

Example: This example explains the align attribute to align the content in the <p> tag.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0">
    <title>HTML paragraph
    </title>
</head>

<body>
    <p align="center">
        Welcome Geeks
    </p>
    <p align="left">
        A Computer Science portal for geeks.
    </p>
    <p align="right">
        It contains well written, well thought articles.
    </p>
</body>


</html>

Output:

Use of align attribute in p tag

The <pre> tag

The HTML <pre> tag is used for pre-formatted text. It keeps the original spaces and line breaks exactly as they are in the code. When you use <pre>, the text appears in a fixed-width font, preserving the formatting and layout just as it looks in the HTML code.

Syntax:

<pre> Content </pre> 

Example: This example explains the use of the <pre> tag in the <p> tag.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0">
    <title>HTML paragraph
    </title>
</head>

<body>
    <pre>
    This paragraph has multiple
    lines. But it is displayed 
    as it is unlike the paragraph 
    tag.
   </pre>

    <pre>
    This     paragraph has multiple
    spaces. But     it is displayed 
    as it is    unlike the paragraph 
         tag.
   </pre>
</body>

</html>

Output:

Use of pre tag in the p tag

Supported Browsers  

  • Google Chrome: 1
  • Edge: 12
  • Firefox: 1
  • Opera: 15
  • Safari: 1

HTML Paragraphs – FAQs

What is an HTML paragraph?

An HTML paragraph is defined using the <p> tag and is used to group sentences and text content into a single block of text.

How to create a paragraph in HTML?

You create a paragraph using the <p> tag. Example: <p>This is a paragraph.</p>

Can paragraphs contain other HTML elements?

Yes, paragraphs can contain other inline elements like <a>, <strong>, <em>, <span>, and more.

Can you nest paragraphs within other paragraphs?

No, paragraphs cannot be nested within each other. Each <p> tag should be a separate paragraph.

How to create a line break within a paragraph?

Use the <br> tag to create a line break within a paragraph. Example: <p>This is a line.<br>This is another line.</p>



Previous Article
Next Article

Similar Reads

How to insert some HTML after all paragraphs using jQuery ?
In this article, we will insert some HTML content after all paragraphs using jQuery. To add some content after all paragraph elements, we use the after() method. This method is used to insert the specified content after each selected element in the set of matched elements. Syntax: $( selector ).after( content ); Example: C/C++ Code &lt;html&gt;
1 min read
How to insert a DOM element after all paragraphs using jQuery ?
In this article, we will insert a DOM element after all paragraph elements using jQuery. To insert a DOM element we use after() and createTextNode() methods. The createTextNode() method is used to create a TextNode which contains an element node and a text node. It is used to provide text to an element. The after() method is used to insert the spec
1 min read
How to append some text to all paragraphs using jQuery ?
In this article, we will append some text to all paragraph elements using jQuery. To append some text to all paragraph elements, we use append() and document.createTextNode() methods. jQuery append() method is used to insert some content at the end of the selected elements. Syntax: $(selector).append( content, function(index, html) ) Example: C/C++
1 min read
How to display a message on dblclick event on all paragraphs of a page using jQuery ?
The purpose of this article is to display a message to the double click event on all paragraphs on a page. Whenever you double-click on any of the paragraphs then the message will appear. Used method in jQuery: dblclick(): This method is used to trigger the dblclick event, or attaches a function to run when a double click event occurs. Syntax: $(se
1 min read
How to append a jQuery object to all paragraphs using jQuery ?
In this article, we will see how to append a jQuery object to all paragraphs using jQuery. Append means we add something to an existing element. The object is used to define a container for an external resource like a page, a picture, a media player, or a plug-in application. Used Methods: ready() Method: This method is used to specify a function t
2 min read
How to remove all paragraphs from the DOM using jQuery ?
To remove elements and content, we use jQuery remove() method which removes the selected element as well as everything inside it, also it will remove all bound events associated with that target element. Syntax: $(selector).remove() Example : C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script src=&quot;https://code.jquery.com/jqu
1 min read
How to insert a jQuery object after all paragraphs using jQuery ?
The task is to insert a jQuery object after all the paragraphs using jQuery. Approach: Create DOM element or jQuery object using &lt;span&gt; tag.Create a paragraph using &lt;p&gt; tag.Create a button using button tag after clicking on which the object will be inserted after paragraph.Write a script that will call a function jQuery.after() which is
1 min read
How to iterate over three paragraphs and sets their color property red in jQuery ?
In this article, we will learn how to iterate over three paragraphs and sets their color property red in jQuery. We have three paragraphs, and we want to iterate on these paragraphs and set their color property to red. Approach: To do that, first, we add a button and on click this button, a function is called which name is fun() and in this functio
1 min read
How to removes all child nodes from all paragraphs in jQuery ?
In this article, we will learn how to remove all child nodes from all paragraphs in jQuery. Child nodes are the sub-tags of the paragraph. Here, our task is to remove all the sub-tags from the &lt;p&gt; tag in DOM. We can remove all child nodes from all paragraphs in jQuery by using different methods. detach() methodremove() methodempty() method Ap
4 min read
Foundation CSS Base Typography Paragraphs
Foundation CSS is an open-source &amp; responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails to look amazing &amp; can be accessible to any device. It is used by many companies such as Facebook, eBay, Mozilla, Adobe, and even Disney. The framework is b
3 min read
How to find all textarea and paragraphs to make a border using jQuery ?
Given a set of textareas, the task is to apply a border on each of them and subsequently add some paragraphs and then define a border on every paragraph using the jQuery library. Approach 1: Using the click(), css() and add() methods in jQuery: There are two textareas, two paragraphs, and one button defined in the following example. The button has
3 min read
Blaze UI Typography Paragraphs
Blaze UI is a free open source UI Toolkit that provides a great structure for building websites quickly with a scalable and maintainable foundation. All components in Blaze UI are developed mobile-first and rely solely on native browser features, not a separate library or framework. It helps us to create a scalable and responsive website fast and e
2 min read
How to Add 6 Rows of Paragraphs with Bootstrap 5 ?
Bootstrap (CSS framework) is one of the most favorable frameworks that is also mobile-friendly for web application development. This means that the code and the template available on the Bootstepap apply to different screen sizes. Paragraphs in the application are the information-passing components that are represented in the Application. Bootstrap
6 min read
Bootstrap 5 Reboot Headings and Paragraphs
Bootstrap 5 Reboot Headings and paragraphs are used for removing the default margin that has been provided by HTML header tags which are margin-bottom: .5rem and for paragraph margin-bottom: 1rem. If we attach CDN links and use a header and paragraph tag then the margin will be removed. BootStrap5 Reboot Headings and paragraphs Class: There is no c
2 min read
Paragraphs in Pug View Engine
Pug is a template engine for NodeJS and browsers, enabling dynamic content rendering. It compiles templates to HTML, supports JavaScript expressions for formatting, and facilitates the reuse of static pages with dynamic data. Its indentation-based syntax simplifies tag specification, enhancing readability. Table of Content Paragraphs in Pug:Approac
4 min read
How to insert an object before all paragraphs using jQuery ?
jQuery is a Javascript library to ease the task of web developers. Developers can use the Jquery library rather than using Javascript in their code. Jquery provides a lot of good features like DOM manipulation, event handling, AJAX support, etc. It is highly recommended to learn the basics of HTML, CSS, and JavaScript before learning Jquery. Approa
2 min read
How to change the font styles of paragraphs on mouseenter and mouseleave using jQuery?
jQuery is one of the powerful libraries of JavaScript which has many powerful methods that make the manipulation of DOM much simpler using the selectors. In this article, let us see different ways on how to change the font-weight and color of paragraphs on mouse enter and mouse leave using jQuery. ApproachUsing jQuery we can add many functionalitie
5 min read
HTML | DOM HTML Object
The HTML Object property in HTML DOM is used to represent or access the HTML &lt;html&gt; element with in the object. The &lt;html&gt; element is used to return the HTML document as an Element Object. Syntax: It is used to access a &lt;html&gt; element.var x = document.getElementsByTagName("HTML")[0]; It can also be used to access a &lt;html&gt; el
3 min read
HTML | &lt;html&gt; xmlns Attribute
The HTML &lt;html&gt; xmlns Attribute is used to specify the xml namespace for a document. Important Note: This attribute is mainly required in XHTML, not valid in HTML 4.01, and optional in HTML 5. Syntax: &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; Attribute Values: https://www.geeksforgeeks.org/ It defines the namespace to use (for XHTML d
1 min read
Inline HTML Helper - HTML Helpers in ASP.NET MVC
HTML Helpers are methods that returns HTML strings. These are used in the view. In simple terms, these are C# methods that are used to return HTML. Using HTML helpers you can render a text box, an area, image tag, etc. In MVC we have many built-in HTML helpers and we can create custom helpers too. Using HTML helpers a view can show model properties
2 min read
How to return HTML or build HTML using JavaScript ?
JavaScript is very powerful and with it, we can build dynamic web content and add many features to a web application. With HTML, we create the structure of the web page and the same thing can also be done with JavaScript. There are a few JavaScript methods called as createElement(), appendChild() with which we can add nodes to the DOM tree on the f
2 min read
How to convert html.slim to html.erb ?
Introduction to slim and erb: Slim files and tools are used to make the code more light and will help to use it instead of the particular code. erb is also used to do the similar but if you want to make the changes in the code then the user should be familiar with slim/erb respectively. If you have to convert an HTML Document into html.slim file th
1 min read
How to include HTML code snippets in HTML ?
In this article, we will learn how to include HTML snippets in HTML code. We will include the HTML code snippet of "gfg.html" into "index.html". To achieve this task, we are going to write a JavaScript function in "index.html" which traverses the collection of all HTML elements in "gfg.html" and searches for elements with specific attributes. It cr
3 min read
How to display HTML tags as plain text in HTML ?
In this article, we will learn how to display HTML tags as plain text in HTML. We can replace the plain text by using &lt; with   &amp;lt; or &amp;60; and &gt;   with  &amp;gt; or &amp;62; on each HTML tag. HTML Entities:Sign DescriptionEntity nameEntity number&lt;Less than(start of HTML element)&amp;lt;&lt;&gt;Greater than(end of HTML element)
2 min read
HTML Complete Guide – A to Z HTML Concepts
What is HTML ? HTML stands for Hypertext Markup Language. It is a standard markup language used to design the documents displayed in the browsers as a web page. This language is used to annotate (make notes for the computer) text so that a machine can understand it and manipulate text accordingly. Most markup languages (e.g. HTML) are human-readabl
7 min read
HTML &lt;html&gt; Tag
HTML is a language full of diverse elements, and one such element is the &lt;html&gt; tag. This tag, standing for ‘HyperText Markup Language’, is used to define the root of an HTML or XHTML document. It serves as the main container for all other HTML elements, excluding the &lt;!DOCTYPE&gt; declaration. Understanding the &lt;html&gt; TagThe &lt;htm
2 min read
HTML Course Basics of HTML
In this article, we will go through all the basic stuff required to write HTML. There are various tags that we must consider and know about while starting to code in HTML. These tags help in the organization and basic formatting of elements in our script or web pages. These step-by-step procedures will guide you through the process of writing HTML.
5 min read
HTML Course Structure of an HTML Document
HTML(Hypertext Markup Language), structures web pages. Unlike programming languages, it isn't compiled or interpreted. Browsers render HTML directly, displaying content without typical errors. It's a markup language, not a programming one, making execution smooth without encountering compilation or interpretation issues. Table of Content HTML Docum
3 min read
What is the difference between &lt;html lang="en'&gt; and &lt;html lang="en-US'&gt; ?
The lang attribute specifies which language is used to write the content of a web page. It is used to set the language for the whole text of the web page. The &lt;html lang="en"&gt; specifies the language of the document as English, while &lt;html lang="en-US"&gt; narrows it down to English as used in the United States. Table of Content The &lt; ht
2 min read
HTML Code to JSON Converter App Using HTML, CSS, and JavaScript
HTML tables are a common way to represent structured data on web pages, but transforming this data into a JSON format can be troublesome. JSON is a lightweight data-interchange format that is easy for humans to read and write and for machines to parse and generate. We will be creating the HTML Code for the JSON Converter tool. The converter is desi
3 min read
three90RightbarBannerImg