From Wikimedia Commons, the free media repository
Jump to navigation Jump to search


Template documentationview · edit · history · purge ]
This documentation is transcluded from Template:Ns/doc.

The Template:Ns inserts any count of non-breaking spaces ( ) as the number in parameter 1 (default: 3 spaces). The count is limited to 0-83 spaces, where 0 produces nothing. The intent is to provide a short markup template to insert extra spacing, rapidly, where text-wrapping is not wanted.

Usage:  3{{ns}}spaces{{ns}}here → 3   spaces   here

The effect of the count, such as in "{{ns|30}}" is identical to putting 30 copies of " " into the text.

In translation of text to uppercase letters, the spacing is retained. Compare:

  • {{uc: Begin{{ns|4}}end }} → BEGIN    END
  • {{uc: Begin{{spaces|4}}end }} → BEGIN    END

For gaps wider than 83 spaces, then multiple instances can be used, such as "{{ns|80}}{{ns|10}}" to insert 90 non-breaking spaces.

Performance considerations[edit]

The Template:Ns has been designed to rapidly insert a few, or numerous, non-breaking spaces where wrapping is not wanted, such as to pad table headings or align some entries in columns. It has been clocked to run faster than 1,530x times per second (in December 2012). The number of spaces, from 0 to 83, does not affect the speed of formatting. It invokes wp:parser function {padleft:} to repeat " " several, or dozens, of times. Also, the expansion depth has been kept limited, as only 5 levels deep, to allow use anywhere, to generate spaces in any complex templates or tables.

Beyond the maximum count of 83 spaces, the template truncates at 500-characters long (limited by padleft), with "&#" at the end. The default count, as 3 spaces, was chosen because a 1-or-2-space gap is often coded as simply "  " and hence, 3 spaces is the first gap needing longer markup. The short template name, "ns" avoids interleaving letters as "nsbp" for dyslexic users.

For gaps wider than 83 spaces, then multiple instances of {ns} can be used, such as "{{ns|80}}{{ns|10}}" to insert 90 non-breaking spaces.


<templatedata>JSON</templatedata> ./. {{TemplateBox}}

TemplateData is a way to store information about template parameters (the description of those and of the whole template) for both humans and machines. It is used by VisualEditor and possibly other tools like Upload Wizard.

Existing template documentation
At Wikimedia Commons, it is recommended to use {{TemplateBox}} with either ‎useTemplateData=1 or ‎useTemplateData=only on the ‎/doc subpage and transcluding it with {{Documentation}} into the template. ‎<nowiki>-tags can be wrapped around the arguments, if required, to avoid templates being expanded.

Newly created template documentation and imports
Another option, especially for imported templates, or for users with JSON experience, is placing raw ‎<templatedata>-tags into the Wikitext of the template, as described in various Wikipediae.

There is an ongoing discussion about that matter. Feel invited to comment if you are experienced in either way, your time permits and if you like to share your opinion or to make a suggestion.

Wikipedia's help about TemplateDataCommons-specific information

Inserts a given number of non breaking spaces.

Template parameters[Edit template data]


The number of spaces to insert, 0 to 83. The default is three spaces.


See also[edit]

  • Template:In5 - to insert a mix of &nbsp and regular spaces which can wrap
  • Template:Gaps - to insert precisely-sized gaps between digits/words
  • Template:Spaces - to insert large, no-wrap span-tags to separate text 1-n spaces
  • Template:j - to join text or wikilinks as non-wrapped