Help:Line-break handling: Difference between revisions

Content deleted Content added
-raw hlist
 
(28 intermediate revisions by 11 users not shown)
Line 9:
 
===Newlines===
{{see|Wikipedia:Don'tLine usebreaks line breaksusage|Wikipedia:Manual of Style#Controlling line breaks}}
 
{{shortcut|H:PARAGRAPH}}
{{see|Wikipedia:Don't use line breaks|Wikipedia:Manual of Style#Controlling line breaks}}
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:
}}
 
=== <br /> or <br> ===
{{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 {{tag|br|s}} or {{tag|br|o}} tags are used for a single forced line break. For content that is semantically a list, such as in infoboxes, actual list markup is preferred. See {{format link|#Lists}} below.
 
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.
 
The {{tag|br|s}} or {{tag|br|o}} tags are used for a single forced line break. 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 />will break in the middle.</nowiki>
|And this line of text<br />will break in the middle.
}}
 
The example below includes four forms that are rendered as line breaks and two that display as plain text.
The MediaWiki software converts valid forms like {{tag|br|o}}, {{tag|br/|o}}, and {{tag|br&nbsp;|o}} to {{tag|br|s}}. It also converts the invalid form {{tag|br|c}} to {{tag|br|s}}. The invalid forms {{tag|&nbsp;br|o}} and {{tag|&nbsp;br|c}} are not converted and will not create line breaks.
<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;">
While valid forms without the <code>/</code> (such as {{tag|br|o}} or {{tag|br&nbsp;|o}}) will work properly in the rendered page because modern browsers are forgiving of [[Well-formed element|malformed HTML]], they can break several of the available [[Wikipedia:Syntax highlighting|syntax highlighters]] for wiki code in the editing view (mis-highlighting all text in the page after the occurrence of that tag), and so should be avoided.
'''Rendered result'''
 
One <br>Two <br >Three <br/>Four <br />Five < br>Six </ br>Seven
Please correct invalid occurrences&nbsp;– such as {{tag|br|c}}, {{tag|&nbsp;br|o}}, or {{tag|&nbsp;br|c}}&nbsp;– to {{tag|br|s}} as you encounter them, though preferably as a part of a more substantive edit.
</div>
 
=== &lt;poem> ===
Line 216 ⟶ 229:
 
== Preventing and controlling word wraps ==
{{Nutshell|title=This section|To prevent word wraps use <code>&amp;nbsp;</code> in place of each space,; and oruse <code>&amp;#8209;</code> in place of aeach 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.
Line 285 ⟶ 298:
{{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 333 ⟶ 347:
:< 3
 
=== &lt;wbr /> and soft hyphens===
{{anchor|wbr|&lt;wbr&gt;}}
 
To insert a word-break opportunity, use {{tag|wbr|o}}.
{{tag|wbr|s}} is a word-break opportunity; that is, 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.
 
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 />Text Markup Language...</nowiki>
|renders=It may render like this:
:Now is the time to become a power editor, by learning HyperText Markup Language...
Line 348 ⟶ 364:
}}
 
Note that {{tag|wbr|so}} will not work inside {{tl|nowrap}}.
 
In many cases breaking up a word with a space would be inappropriate. [[Soft hyphenshyphen]]s also create acreates word-break opportunityopportunities, but will add a hyphen rather than a space. TheIn codeother <code>&amp;shy;</code>words, a soft hyphen is employeda inhyphen theinserted sameinto mannera asword {{tag|wbr|s}}not asotherwise seenhyphenated, into be displayed or typeset only if it falls at the examplesend of a line of abovetext.
 
The code <code>&amp;shy;</code> is employed in the same manner as {{tag|wbr|o}}. For example:
 
{{markup
|<nowiki>This long German word Datenschutz&amp;shy;erklärung breaks between its constituent parts "Datenschutz" and "erklärung".</nowiki>
|This long German word Datenschutz&shy;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 358 ⟶ 381:
|This Wikisource example is difficult to understand
}}
 
Consider instead using the {{tlx|shy}} template for such complex cases:
 
{{markup
Line 374 ⟶ 399:
 
== See also ==
* [[metamw:HelpManual:Newlines and spaces]]
* {{tl|break}}
* {{tl|clear}}