Help:Line-break handling
{{Short description|Wikimedia help page}}
{{Wikipedia how to|WP:LINEBREAK|H:LINEBREAK}}
This page explains different methods for creating, controlling and preventing line breaks and word wraps in Wikipedia articles and pages.
When a paragraph or line of text is too long to fit on one line, web browsers, like many other programs, automatically wrap the text to the next line. Web browsers usually wrap the line where there are natural breaks such as spaces, hyphens, etc. in the text.
Causing line breaks
=Newlines=
{{see|Wikipedia:Line breaks usage|Wikipedia:Manual of Style#Controlling line breaks}}
{{shortcut|H:PARAGRAPH}}
There are several ways to force line breaks and paragraph breaks in the text. The simplest method is by inserting newlines; for example:
{{markup
|
does not cause a visible line break.
|A single newline in the markup
does not cause a visible line break.
|
causes a paragraph break.
|Two newlines in the markup
causes a paragraph break.
|
causes an extra-wide paragraph break. This should normally be avoided.
|Three newlines in the markup
causes an extra-wide paragraph break. This should normally be avoided.
}}
= <br> =
{{shortcut|H:BR}}{{anchor|<br> or <br />|br|br/|br /}}
,
,
,
The MediaWiki software uses any of them for a single forced line break. All of them are converted to {{tag|br|s}} in the HTML that browsers read.
MediaWiki also converts
to {{tag|br|s}}, but this form is invalid. Please correct these tags.
For content that is semantically a list, such as in infoboxes, actual list markup is preferred. See {{format link|#Lists}} below.
{{markup
|
will break in the middle.
|And this line of text
will break in the middle.
}}
The example below includes four forms, that are rendered as line breaks and two that display as plain text.
Wiki source
Two
Three
Four
Five < br>Six br>Seven
Rendered result
One
Two
Three
Four
Five < br>Six br>Seven
= <poem> =
{{anchor|poem}}
The {{xtag|poem}} extension adds HTML-like tags to maintain newlines and spaces. This is useful for longer blocks of text such as poems, lyrics, mottoes, oaths and the like. These tags may be used inside other tags such as {{tag|blockquote|o}}. For example:
{{markup
|
In Xanadu did Kubla Khan
A stately pleasure-dome decree:
Where Alph, the sacred river, ran
Through caverns measureless to man
Down to a sunless sea.
So twice five miles of fertile ground
With walls and towers were girdled round:
And there were gardens bright with sinuous rills,
Where blossomed many an incense-bearing tree;
And here were forests ancient as the hills,
Enfolding sunny spots of greenery.
|
In Xanadu did Kubla Khan
A stately pleasure-dome decree:
Where Alph, the sacred river, ran
Through caverns measureless to man
Down to a sunless sea.
So twice five miles of fertile ground
With walls and towers were girdled round:
And there were gardens bright with sinuous rills,
Where blossomed many an incense-bearing tree;
And here were forests ancient as the hills,
Enfolding sunny spots of greenery.
}}
= <pre> =
{{xtag|pre|p}} and its alternatives are typically used to display code; their contents are rendered in monospace with a frame and different background colour. Both markup and newlines within {{tag|pre}} are reproduced verbatim. However, the first newline after {{tag|pre|o}} and last newline before {{tag|pre|c}} are ignored, allowing the tags to be placed on their own lines without extra empty lines appearing on the page.
{{markupv
|
m=
{{2x|foo}}
bar
|
r=
{{2x|foo}}
bar
}}
To evaluate markup while still preserving newlines, the alternatives
and {{tl|Pre}} can be used.>
{{markupv
|
m=
{{2x|foo}}
bar
}}
|
r={{Pre |
{{2x|foo}}
bar
}}
}}
= <nowiki> =
The effect of the tag {{xtag|nowiki|p}} on line breaks is that single and double line breaks are ignored, and you also cannot add a line break with {{tag|br|s}}:
{{markupv
|
markup=<nowiki>
Single line breaks,
and double line breaks as well,
are ignored,
and the tag
is just displayed as is.
</nowiki>
|
renders=
Single line breaks,
and double line breaks as well,
are ignored,
and the tag
is just displayed as is.
}}
There are several ways to enable line breaks in text that uses {{tag|nowiki}}:
Solution 1. Use {{tag|nowiki}} for each line separately, with {{tag|br|s}} or double newline between lines.
{{markupv
|
m=
or only around text that must be escaped:
|
r=
or only around text that must be escaped:
}}
Solution 2: Use {{tag|poem}}.
{{markupv
|
m=<poem><nowiki>Twas bryllyg, and ye slythy toves
Did gyre and gymble in ye wabe:
All mimsy were ye borogoves,
And ye mome raths outgrabe.</nowiki></poem>
|
r=
Did gyre and gymble in ye wabe:
All mimsy were ye borogoves,
And ye mome raths outgrabe.
}}
When {{tag|poem}} is used with {{tag|nowiki}}, the contents must begin on the same line as the tags, because a leading newline will appear in the output. However, the last newline is ignored, so the closing tags may be on their own line.
{{markupv
|
m=
Extra line above
</nowiki>
|
r=
Extra line above
}}
Solution 3: Consider using <pre> instead of {{tag|nowiki}}.
= Lists =
{{main|Help:List}}
Numbered and bulleted lists are created using standard wiki markup. In cases where a plain list without number or bullet is desired, such as in an infobox, many editors will simply create a list using breaks. This method does not apply the semantics of a list, and for those using screen readers it will not sound like a list. For these cases, {{tl|plainlist}} and {{tl|unbulleted list}} both use list markup without numbers or bullets:
{{markup
|1=
- cat
- dog
- horse
- cow
- sheep
- pig
}}
|2={{plainlist|
- cat
- dog
- horse
- cow
- sheep
- pig
}}}}
= Formulas =
To display formulas with {{tag|math|o}} on their own line, Wikipedia:Manual of Style/Mathematics#Using LaTeX markup recommends {{tag|math|o|params=display=block}}.
Preventing and controlling word wraps
{{Nutshell|title=This section|To prevent word wraps use
in place of each space; and use ‑
in place of each hyphen. For more complex cases, see below.}}
There are several ways to prevent word wraps (line wraps) from occurring in unwanted places. This is an overview of when to use which method.
= Non-breaking space =
{{anchor|nbsp}}
The HTML entity
is a non-breaking, or hard, space. It renders like a normal space " ", but prevents a line wrap from occurring, like this:
{{markup
|
|It may render like this:
:Lots of text 10 kg
:more text.
Or it may render like this:
:Lots of text
:10 kg more text.
But it will not render like this:
:Lots of text 10
:kg more text.
}}
The non-breaking space works within links exactly like a regular space. Thus you can link to
directly and it will render as J. R. R. Tolkien. The initials will not be separated across a line break.
However,
renders the source text harder to read and edit. Avoid using it unless it is really necessary to avoid a line break.
= Non-breaking hyphen =
{{anchor|8209}}
Browsers may break words at hyphens. A non-breaking hyphen
may be used to prevent this occurring, as in:
As seen on page C‑2 of the newspaper.
This code generates "page C‑2" just like the plain code "
", but prevents a line break at the hyphen.
However, like
, the use of
instead of "
" renders the source text harder to read and edit. Don't use it unless it is really necessary to avoid a line break.
=Inline blocks=
The templates {{tlx|Inline block}} and {{tlx|Avoid wrap}} avoid breaks, but allow them if there is not enough space.
{{awrap|{{tlx|awrap}} is a shorthand of the latter.}}
{{markup
|
dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt.}}}}
|{{inline block|{{color|blue|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.}}}}
|
unde omnis iste natus error sit
voluptatem accusantium.}}}}
|{{inline block|{{color|green|Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium.}}}}
|
dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt.}}}}
|{{avoid wrap|{{color|blue|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.}}}}
|
unde omnis iste natus error sit
voluptatem accusantium.}}}}
|{{awrap|{{color|green|Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium.}}}}
}}
Both put the content in
. The latter also adds the CSS class "avoidwrap".
= <nowiki>{{nowrap}}</nowiki> =
{{anchor|nowrap}}
{{shortcut|WP:NOWRAP}}
{{redirect|WP:NOWRAP|the Manual of Style guideline|MOS:NOWRAP}}
The {{tl|nowrap}} template is less flexible and will prevent breaks even when the line is too long for the window, forcing the user to scroll:
{{nowrap|{{color|blue|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.}}}}
{{nowrap|{{color|green|Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium.}}}}
It is good for short text sections like {{nowrap|"10 kg (22 lb)",}} which should always stay together.
This could also be achieved with the non-breaking space:
{{nowrap|Lots of text 10 kg (22 lb) more text.
}}
But this makes the source text hard to read. The template is recommended instead:
{{nowrap|Lots of text
}}
class="wikitable" |
It may render like this
| or like this | or like this. | But not like this. |
style="vertical-align: top;"
| Lots of text 10 kg (22 lb) more text. | Lots of text 10 kg (22 lb) more text. | Lots of text 10 kg (22 lb) more text. | Lots of text 10 kg (22 lb) more text. |
(For the specific case of unit conversions, see {{tl|convert}}.)
In some cases {{tl|nowrap}} doesn't work so well. For instance, when you want to prevent wraps in longer or more complex text, then it might be hard to see where the {{tl|nowrap}} ends. Additionally, the MediaWiki template mechanisms interpret characters such as equal signs "=
" and pipes "|
" in template parameters as special characters, and thus they cause problems. In these cases, it is instead recommended to use {{tl|nowrap begin}} + {{tl|nowrap end}}, like this:
{{nowrap begin}}2 + 2 = 4{{nowrap end}} and
{{nowrap begin}}|2| < 3{{nowrap end}}
It may render like this:
:2 + 2 = 4 and
:|2| < 3
But it will not render like this:
:2 + 2 = 4 and |2|
:< 3
= <wbr> and soft hyphens=
{{anchor|wbr|<wbr>}}
To insert a word-break opportunity, use {{tag|wbr|o}}.
It specifies where it would be OK to add a line-break where a word is too long, or it is perceived that the browser will break a line at the wrong place. Whether the line actually breaks is then left up to the browser. The break will look like a space - see soft hyphen below when it would be more appropriate to break the word or line using a hyphen.
{{markupv
|markup=
|renders=It may render like this:
:Now is the time to become a power editor, by learning HyperText Markup Language...
Or it may render like this (in a narrow browser window):
:Now is the time to become a power editor, by learning Hyper
:Text Markup Language ...
}}
Note that {{tag|wbr|o}} will not work inside {{tl|nowrap}}.
In many cases breaking up a word with a space would be inappropriate. Soft hyphens also creates word-break opportunities, but will add a hyphen rather than a space. In other words, a soft hyphen is a hyphen inserted into a word not otherwise hyphenated, to be displayed or typeset only if it falls at the end of a line of text.
The code ­
is employed in the same manner as {{tag|wbr|o}}. For example:
{{markup
|
|This long German word Datenschutzerklärung breaks between its constituent parts "Datenschutz" and "erklärung".
}}
Use of soft hyphens should be limited to special cases, usually involving very long words or narrow spaces (such as captions in infoboxes or other tight page layouts, or column labels in narrow tables). Widespread use of soft hyphens is strongly discouraged, because it makes the wikitext very difficult to read and to edit. For example:
{{markup
|
|This Wikisource example is difficult to understand
}}
Consider instead using the {{tlx|shy}} template for such complex cases:
{{markup
|
|This alternative syntax improves readability
}}
{{see also|MOS:SHY}}
= Wrap between (linked) list items =
{{anchor|nowraplinks}}
In lists of links such as inside infoboxes and navboxes, use a horizontal list (perhaps via the template {{tl|flatlist}}) to format lists.
For occasional cases where you need to delineate two pieces of text outside of a list, you can use the templates {{tn|·}} or {{tn|•}} which contain a
before the dot, thus handling some of the wrapping problems.
See also
- mw:Manual:Newlines and spaces
- {{tl|break}}
- {{tl|clear}}
- {{section link|Wikipedia:Manual of Style|Non-breaking spaces}}
{{Wikipedia technical help|collapsed}}