- How to Add a Paragraph in HTML: Tips and Best Practices for Web Developers
- Using the tag to define a paragraph
- Using the tag to insert line breaks
- How to make a HTML Paragraph
- Styling paragraphs with CSS
- Manipulating paragraphs with JavaScript
- Best practices for adding paragraphs to a webpage
- Other code snippets for adding paragraphs in HTML
- Conclusion
- HTML Paragraphs
- HTML Paragraphs
- Example
- HTML Display
- Example
- HTML Horizontal Rules
- Example
- This is heading 1
- This is heading 2
- HTML Line Breaks
- Example
- The Poem Problem
- Example
- Solution — The HTML Element
- Example
- HTML Exercises
- HTML Tag Reference
- : The Paragraph element
- Try it
- Attributes
- Examples
- HTML
- Result
- Styling paragraphs
- HTML
- CSS
- JavaScript
- Result
- Accessibility concerns
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
How to Add a Paragraph in HTML: Tips and Best Practices for Web Developers
tag and
tag, as well as tips and best practices for styling and manipulating paragraphs with CSS and JavaScript.
- Using the
tag to define a paragraph
- Using the
tag to insert line breaks - How to make a HTML Paragraph
- Styling paragraphs with CSS
- Manipulating paragraphs with JavaScript
- Best practices for adding paragraphs to a webpage
- Other code snippets for adding paragraphs in HTML
- Conclusion
- How do I add a paragraph to a class in HTML?
- Which tag is used to add paragraph in HTML?
- How do you add a paragraph?
HTML is a markup language used to create webpages, and it provides various tags to define the structure and content of a webpage. One of the most commonly used tags in HTML is the
tag, which is used to define a paragraph. In this article, we will discuss how to add a paragraph in HTML and various tips and best practices for styling and formatting paragraphs.
Using the
tag to define a paragraph
The
tag is a block-level element that is used to define a paragraph on a webpage. Browsers automatically add a single blank line before and after each
element. To add a new paragraph, type
, type the contents of the new paragraph, and type
to end the paragraph. Multiple
tags can be used to add more than one paragraph.
This is a paragraph.
This is another paragraph.
Using the
tag to insert line breaks
The
tag is used to insert a line break on the webpage. Use
to insert a line break within a paragraph or between paragraphs. The
tag is an empty element, so there is no need for a corresponding tag.
This is a paragraph.
This is another line in the same paragraph.
This is another paragraph.
How to make a HTML Paragraph
Follow this step by step guide to get a basic concept of HTML paragraphing and its usage in a Duration: 1:11
Styling paragraphs with CSS
Use CSS to style paragraphs, such as adjusting font size, color, and line-height to create a visually appealing layout. The HTML style attribute can be used to add styles to an element, including paragraphs. A class attribute can be added to elements to apply specific styles to paragraphs.
This is a paragraph with custom styles.
Manipulating paragraphs with JavaScript
The HTML DOM Paragraph Object can be used to manipulate paragraphs using JavaScript. JavaScript can be used to change the content, style, and attributes of paragraphs dynamically. For example, the following code changes the text of a paragraph with the ID my-paragraph :
Multiple resources are available online that provide step-by-step guidance on manipulating paragraphs with JavaScript.
Best practices for adding paragraphs to a webpage
Proper indentation and spacing should be used to improve readability. HTML5 introduces new semantic elements, such as and , that can be used to organize content on a webpage. Avoid using
excessively to break up paragraphs. Use the entity to add space between paragraphs. Common issues when adding paragraphs in HTML include improper syntax and styling conflicts with other elements on the webpage.
Other code snippets for adding paragraphs in HTML
In Html , in particular, how to make a paragraph in html code example
write then inside the two tags write something that you want like this: visit https://www.youtube.com/channel/UCZRNeVTWLXmx1ww5S9IUnoA to learn japanese
yeah pls subscribe and comment
In Html , in particular, how to add a paragraph in html code sample
This is paragraph #1
This is paragraph #2
This is paragraph #3
Conclusion
Adding a paragraph in HTML is a fundamental skill for web developers and content creators. HTML provides the
tag to define a paragraph, and CSS can be used to style and format paragraphs. JavaScript can be used to manipulate paragraphs dynamically, and best practices should be followed to ensure proper syntax and readability. By adhering to these tips and best practices, web developers can create visually appealing and well-structured webpages that are easy to read and navigate.
HTML Paragraphs
A paragraph always starts on a new line, and is usually a block of text.
HTML Paragraphs
The HTML
element defines a paragraph.
A paragraph always starts on a new line, and browsers automatically add some white space (a margin) before and after a paragraph.
Example
This is a paragraph.
This is another paragraph.
HTML Display
You cannot be sure how HTML will be displayed.
Large or small screens, and resized windows will create different results.
With HTML, you cannot change the display by adding extra spaces or extra lines in your HTML code.
The browser will automatically remove any extra spaces and lines when the page is displayed:
Example
This paragraph
contains a lot of lines
in the source code,
but the browser
ignores it.
This paragraph
contains a lot of spaces
in the source code,
but the browser
ignores it.
HTML Horizontal Rules
The
tag defines a thematic break in an HTML page, and is most often displayed as a horizontal rule.
The
element is used to separate content (or define a change) in an HTML page:
Example
This is heading 1
This is some text.
This is heading 2
This is some other text.
The
tag is an empty tag, which means that it has no end tag.
HTML Line Breaks
The HTML
element defines a line break.
Use
if you want a line break (a new line) without starting a new paragraph:
Example
This is
a paragraph
with line breaks.
The
tag is an empty tag, which means that it has no end tag.
The Poem Problem
This poem will display on a single line:
Example
My Bonnie lies over the ocean.
My Bonnie lies over the sea.
My Bonnie lies over the ocean.
Oh, bring back my Bonnie to me.
Solution — The HTML Element
The HTML element defines preformatted text.
The text inside a element is displayed in a fixed-width font (usually Courier), and it preserves both spaces and line breaks:
Example
My Bonnie lies over the ocean.
My Bonnie lies over the sea.
My Bonnie lies over the ocean.
Oh, bring back my Bonnie to me.
HTML Exercises
HTML Tag Reference
W3Schools’ tag reference contains additional information about HTML elements and their attributes.
Tag | Description |
---|---|
Defines a paragraph | |
Defines a thematic change in the content | |
Inserts a single line break | |
Defines pre-formatted text |
For a complete list of all available HTML tags, visit our HTML Tag Reference.
: The Paragraph element
The HTML element represents a paragraph. Paragraphs are usually represented in visual media as blocks of text separated from adjacent blocks by blank lines and/or first-line indentation, but HTML paragraphs can be any structural grouping of related content, such as images or form fields.
Paragraphs are block-level elements, and notably will automatically close if another block-level element is parsed before the closing
tag. See «Tag omission» below.
Try it
Content categories | Flow content, palpable content. |
---|---|
Permitted content | Phrasing content. |
Tag omission | The start tag is required. The end tag may be omitted if the element is immediately followed by an , , , , , , , , , h1, h2, h3, h4, h5, h6, , , , , , , , , or another element, or if there is no more content in the parent element and the parent element is not an element. |
Permitted parents | Any element that accepts flow content. |
Implicit ARIA role | paragraph |
Permitted ARIA roles | Any |
DOM interface | HTMLParagraphElement |
Attributes
This element only includes the global attributes.
Note: The align attribute on
tags is obsolete and shouldn’t be used.
Examples
HTML
p> This is the first paragraph of text. This is the first paragraph of text. This is the first paragraph of text. This is the first paragraph of text. p> p> This is the second paragraph. This is the second paragraph. This is the second paragraph. This is the second paragraph. p>
Result
Styling paragraphs
By default, browsers separate paragraphs with a single blank line. Alternate separation methods, such as first-line indentation, can be achieved with CSS:
HTML
p> Separating paragraphs with blank lines is easiest for readers to scan, but they can also be separated by indenting their first lines. This is often used to take up less space, such as to save paper in print. p> p> Writing that is intended to be edited, such as school papers and rough drafts, uses both blank lines and indentation for separation. In finished works, combining both is considered redundant and amateurish. p> p> In very old writing, paragraphs were separated with a special character: ¶, the i>pilcrowi>. Nowadays, this is considered claustrophobic and hard to read. p> p> How hard to read? See for yourself: button data-toggle-text="Oh no! Switch back!"> Use pilcrow for paragraphs button> p>
CSS
p margin: 0; text-indent: 3ch; > p.pilcrow text-indent: 0; display: inline; > p.pilcrow + p.pilcrow::before content: " ¶ "; >
JavaScript
.querySelector("button").addEventListener("click", (event) => document.querySelectorAll("p").forEach((paragraph) => paragraph.classList.toggle("pilcrow"); >); [event.target.innerText, event.target.dataset.toggleText] = [ event.target.dataset.toggleText, event.target.innerText, ]; >);
Result
Accessibility concerns
Breaking up content into paragraphs helps make a page more accessible. Screen-readers and other assistive technology provide shortcuts to let their users skip to the next or previous paragraph, letting them skim content like how white space lets visual users skip around.
Using empty
elements to add space between paragraphs is problematic for people who navigate with screen-reading technology. Screen readers may announce the paragraph’s presence, but not any content contained within it — because there is none. This can confuse and frustrate the person using the screen reader.
If extra space is desired, use CSS properties like margin to create the effect:
p margin-bottom: 2em; /* increase white space after a paragraph */ >
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Jun 13, 2023 by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.