Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

Line Breaks

In the editor, we have added a short poem to the Physiology section. In the code, it is written on four lines, but look at the preview: the browser runs the lines together as if they were one long sentence.

That's because the browser joins any spaces, tabs and line breaks that follow one another in the code into a single space. Pressing Enter in the code doesn't start a new line on the page. This is also why indentation doesn't change how the page looks: we indent the code only to make it easier for us to read.

When we want to start a new line inside a text, we use the br element (br stands for break, as in line break):

<p>Happy Paws Cat Shelter<br>
12 Garden Street<br>
Springfield</p>

This code is displayed like this:

Happy Paws Cat Shelter
12 Garden Street
Springfield

The br element is special: it has no content and no closing tag, just the opening tag. Elements like this are called void elements. You already know one from the previous lesson: meta. We will meet others later, such as img and input.

Sometimes you will see it written with a slash, as <br />. That is an older way of writing the same thing. In this course, we write <br>.

Use br only for line breaks that belong to the content, such as in a poem or an address. Don't use it to make space between pieces of text: separate blocks of text belong in separate paragraphs, and spacing is set with CSS.

Instructions

  1. 1

    Add a <br> at the end of the first line of the poem (after a day,). Run the code and look at the preview.

  2. 2

    Add a <br> at the end of the second and third lines as well, so that each line of the poem starts on a new line.

Back

6/10

  1. 1. Headings
  2. 2. Paragraphs
  3. 3. Quiz: Paragraphs
  4. 4. Divs
  5. 5. Text Styling
  6. 6. Line Breaks
  7. 7. Lists
  8. 8. Quiz: Lists
  9. 9. Comments
  10. 10. Recap
Next

Try it yourself

Do this exercise right here in your browser. No account needed.