Barry Michael Doyle
Barry Michael Doyle

Reputation: 10608

Is there another way of breaking lines in html apart from <br />?

I'm building an asp.net application and I'm using a <br /> element inside one of my ListItems. This isn't recommended but it works anyway.

Is there another way to break a line in HTML? (not CSS!)

I use &nbsp; alot and other characters like &close;. Is there some equivalent for breaklines using &<code> ?

Upvotes: 4

Views: 3995

Answers (4)

Tahir Shahzad
Tahir Shahzad

Reputation: 649

I am not sure about short code for new line in html but there are block elements in html. A block element takes entire width of container and element after it will be on next line. for example

<p></p> or <div></div>

You can also use <pre>, now every new line in editor/code will reflect in browser without any special code or element.

Upvotes: 0

idik
idik

Reputation: 882

You can use the "pre" tag to send text aleady breaked. Example:

<pre>
LINE 1
LINE 2
LINE 3
</pre>

Another option is to use Paragraphs:

<p> Line 1 </p>
<p> Line 2 </p>

Upvotes: 1

&#193;lvaro Gonz&#225;lez
&#193;lvaro Gonz&#225;lez

Reputation: 146450

The HTML tag that does not ignore white space by default is <pre>:

The HTML <pre> element (or HTML Preformatted Text) represents preformatted text. Text within this element is typically displayed in a non-proportional ("monospace") font exactly as it is laid out in the file. Whitespace inside this element is displayed as typed.

All others would require CSS to do so.

Upvotes: 0

Asaph
Asaph

Reputation: 162801

Paragraphs can be surrounded by <p> tags.

<p>This is my first paragraph.</p>
<!-- a line break will be rendered here -->
<p>This is my second paragraph.</p>

If your content is a list, you can markup each list item with <li> tags and surround the whole list with either <ul> or <ol> tags for unordered or ordered lists, respectively. The latter have numbers on the left instead of bullets.

<ul>
    <li>list item 1</li>
    <li>list item 2</li>
    <li>list item 3</li>
</ul>

For non-semantic blocks, you can surround content in <div> tags.

Upvotes: 1

Related Questions