Using Br To Insert Line Breaks In HTML: Here's How »

Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn moreElement ofLearn How Fonts And Web Typography Work In HTML: A Beginner's GuideWhat does Using br To Insert Line Breaks In HTML: Here's How do?The <br> element is used to insert a line break or carriage-return within a parent element such as a paragraph without breaking out of the parent container.DisplayinlineUsagetextual

Contents

  • 1 Code Example
  • 2 Don’t abuse line breaks
  • 3 Browser Support for br
  • 4 Attributes of br

Code Example

This sentence and the next will be on different lines.<br>This sentence and the one before will be on different lines.This sentence and the next will be on different lines.This sentence and the one before will be on different lines.

Don’t abuse line breaks

The <br> element creates a line break. It can be easy to abuse this element to create styling which that mimics better, more semantic options like paragraphs ( <p> ) and lists. Generally, the <br> element should only be used if the line break itself is an intrinsic part of the content. This might be the case, for example, with:

  • addresses
  • poetry
  • code samples
John Smith<br> c/o Jane Smythe<br> 123 Main St.<br> Northeast Southwestershire, XY 12345 John Smithc/o Jane Smythe123 Main St.Northeast Southwestershire, XY 12345<blockquote> <p>Out of the night that covers me,<br> Black as the pit from pole to pole,<br> I thank whatever gods may be<br> For my unconquerable soul.</p> <p>In the fell clutch of circumstance<br> I have not winced nor cried aloud.<br> Under the bludgeonings of chance<br> My head is bloody, but unbowed.</p> <p>Beyond this place of wrath and tears<br> Looms but the Horror of the shade,<br> And yet the menace of the years<br> Finds, and shall find me, unafraid.</p> <p>It matters not how strait the gate,<br> How charged with punishments the scroll,<br> I am the master of my fate:<br> I am the captain of my soul.</p> — <cite>Invictus</cite>, by William Ernest Henley </blockquote>

Out of the night that covers me,Black as the pit from pole to pole,I thank whatever gods may beFor my unconquerable soul. In the fell clutch of circumstanceI have not winced nor cried aloud.Under the bludgeonings of chanceMy head is bloody, but unbowed. Beyond this place of wrath and tearsLooms but the Horror of the shade,And yet the menace of the yearsFinds, and shall find me, unafraid. It matters not how strait the gate,How charged with punishments the scroll,I am the master of my fate:I am the captain of my soul.

— Invictus, by William Ernest Henley

If you find yourself using <br> to separate blocks of texts, you may need to think about using paragraph tags or another element. If you are using them to create more space between items, you should use CSS margin.

Adam WoodAdam is a technical writer who specializes in developer documentation and tutorials.

Browser Support for br

iefirefoxchromeedgesafariopera
AllAllAllAllAllAll

Attributes of br

Attribute nameValuesNotes
clearWas used to ensure that line breaks "cleared" floated or aligned elements above them. Deprecated.

Từ khóa » Html Br Options