HTML Basics

HTML Paragraphs

Learn how to work with HTML paragraphs, line breaks, horizontal rules and text formatting.

HTML Paragraphs

The HTML <p> 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.

Browsers will automatically remove any extra spaces and line breaks from your HTML source code. These spaces will be dealt with by the browser.

HTML Line Breaks

The HTML <br> element defines a line break. Use <br> if you want a line break (a new line) without starting a new paragraph. The <br> tag is an empty element, which means that it has no end tag.

The Preformatted Text Element

The HTML <pre> element defines preformatted text. The text inside a <pre> element is displayed in a fixed-width font (usually Courier), and it preserves both spaces and line breaks.

HTML Text Formatting

HTML contains several elements for defining text with a special meaning:

  • <strong> — Important text (bold)
  • <em> — Emphasized text (italic)
  • <mark> — Marked/highlighted text
  • <small> — Smaller text
  • <del> — Deleted text
  • <ins> — Inserted text
  • <sub> — Subscript text
  • <sup> — Superscript text

Example

html
<!DOCTYPE html>
<html lang="en">
<body>
  <p>This is a paragraph. Browsers add space before and after paragraphs.</p>
  <p>This is another paragraph.<br>With a line break inside it.</p>

  <pre>
  Text in a pre element
  is displayed in a fixed-width
  font, and it preserves
  both      spaces and
  line breaks
  </pre>

  <p>
    <strong>Bold text</strong> and
    <em>italic text</em> and
    <mark>highlighted text</mark>
    <sup>superscript</sup> and
    <sub>subscript</sub>
  </p>
</body>
</html>
Try it yourself — HTML