Content deleted Content added
→Line breaks without wiki formatting: renamed the paragraph |
|||
(44 intermediate revisions by 17 users not shown) | |||
Line 4:
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
== 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 [[newline|line breaks]] and [[hard return|paragraph breaks]] in the text. The simplest method is by inserting newlines; for example:
Line 36:
}}
===
{{shortcut|H:BR}}{{anchor|<br> or <br />|br|br/|br /}}
<code><nowiki><br></nowiki></code>, <code><nowiki><br ></nowiki></code>, <code><nowiki><br/></nowiki></code>, <code><nowiki><br /></nowiki></code>
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 <code><nowiki></br></nowiki></code> 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
|<nowiki>And this line of text<br
|And this line of text<br
}}
The example below includes four forms that are rendered as line breaks and two that display as plain text.
<div style="display:inline-table; border: 2px solid var(--border-color-content-added); padding: 0.5em;">
'''Wiki source'''
<nowiki>One <br>Two <br >Three <br/>Four <br />Five < br>Six </ br>Seven</nowiki>
</div>
<div style="display:inline-table; border: 2px solid var(--border-color-content-added); padding: 0.5em;">
'''Rendered result'''
One <br>Two <br >Three <br/>Four <br />Five < br>Six </ br>Seven
</div>
=== <poem> ===
Line 86 ⟶ 99:
Enfolding sunny spots of greenery.
</poem>
}}
=== <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=<nowiki><pre>
{{2x|foo}}<br />bar
[[wiki]]
</pre></nowiki>
|
r=<pre>
{{2x|foo}}<br />bar
[[wiki]]
</pre>
}}
To evaluate markup while still preserving newlines, the alternatives <code><nowiki><pre<includeonly></includeonly>></pre></nowiki></code> and {{tl|Pre}} can be used.
{{markupv
|
m=<nowiki>{{Pre |
{{2x|foo}}<br />bar
[[wiki]]
}}</nowiki>
|
r={{Pre |
{{2x|foo}}<br />bar
[[wiki]]
}}
}}
=== <nowiki> ===
{{markupv
Line 99 ⟶ 142:
are ignored,
and the tag <br />
is just displayed as is.
</nowiki>
Line 108 ⟶ 151:
are ignored,
and the tag <br />
is just displayed as is.
</nowiki>
}}
There are several ways to
'''Solution 1'''. Use {{tag|nowiki}} for each line separately, with
{{markupv
|
or only around text that must be escaped: <nowiki>{{2x|bar}}</nowiki>.
|
r=<nowiki>Around
or only around text that must be escaped: <nowiki>{{2x|bar}}</nowiki>.
<nowiki>
}}
'''Solution 2''':
{{markupv
|
m=<poem><nowiki>Twas bryllyg, and ''y<sup>e</sup>'' slythy toves
Did gyre and gymble in ''y<sup>e</sup>'' wabe:
All mimsy were ''y<sup>e</sup>'' borogoves,
And ''y<sup>e</sup>'' mome raths outgrabe.</nowiki></poem>
|
r=<
<nowiki>Twas bryllyg, and ''y<sup>e</sup>'' slythy toves
Did gyre and gymble in ''y<sup>e</sup>'' wabe:
All mimsy were ''y<sup>e</sup>'' borogoves,
And ''y<sup>e</sup>'' mome raths outgrabe.
</nowiki></poem>
}}
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
|
Extra line above
</nowiki></poem></nowiki>
|
r=<poem><nowiki>
Extra line above
</nowiki></poem>
}}
'''Solution 3''': Consider using [[#<pre>|<pre>]] instead of {{tag|nowiki}}.
=== Lists ===
Line 202 ⟶ 229:
== Preventing and controlling word wraps ==
{{Nutshell|title=This section|To prevent word wraps use <code>&nbsp;</code> in place of each space
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.
Line 247 ⟶ 274:
{{awrap|{{tlx|awrap}} is a shorthand of the latter.}}
{{markup
|<nowiki>{{inline block|{{color|
dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt.}}}}</nowiki>
|{{ |<nowiki>{{
unde omnis iste natus error sit voluptatem accusantium.}}}}</nowiki> |{{inline block|{{color|green|Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium.}}}}
|<nowiki>{{avoid wrap|{{color|blue|Lorem ipsum
dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt.}}}}</nowiki>
|{{avoid wrap|{{color|blue|Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.}}}}
|<nowiki>{{awrap|{{color|green|Sed ut perspiciatis
unde omnis iste natus error sit
voluptatem accusantium.}}}}</nowiki>
|{{awrap|{{color|green|Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium.}}}}
}}
=== <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:
Line 306 ⟶ 347:
:< 3
=== <wbr
{{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=<nowiki>Now is the time to become a power editor, by learning Hyper<wbr
|renders=It may render like this:
:Now is the time to become a power editor, by learning HyperText Markup Language...
Line 321 ⟶ 364:
}}
Note that {{tag|wbr|
In many cases breaking up a word with a space would be inappropriate. [[Soft
The code <code>&shy;</code> is employed in the same manner as {{tag|wbr|o}}. For example:
{{markup
|<nowiki>This long German word Datenschutz&shy;erklärung breaks between its constituent parts "Datenschutz" and "erklärung".</nowiki>
|This long German word Datenschutz­erklärung breaks between its constituent parts "Datenschutz" and "erklärung".
}}
Use of soft hyphens should be limited to special cases, usually involving [[Longest English words|very long words]] or narrow spaces (such as captions in [[infobox|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:
Line 331 ⟶ 381:
|This Wikisource example is difficult to understand
}}
Consider instead using the {{tlx|shy}} template for such complex cases:
{{markup
Line 342 ⟶ 394:
{{anchor|nowraplinks}}
In lists of links such as inside infoboxes and [[WP:NAVBOX|navboxes]], use
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 <code>&nbsp;</code> before the dot, thus handling some of the wrapping problems.
== See also ==
* [[
* {{tl|break}}
* {{tl|clear}}
|