Jump to content

Template:Font color/doc: Difference between revisions

From Fifth Empire Wiki
Usage: update documentation
m 82 revisions imported from wikipedia:Template:Font_color/doc
 
(40 intermediate revisions by 29 users not shown)
Line 1: Line 1:
{{Documentation subpage}}
{{Documentation subpage}}{{Warning link color}}
{{Warning|1={{big|'''Links should clearly be identifiable as links to readers'''.}}<br />Refrain from implementing colored links that may impede user ability to distinguish links from regular text, or color links for purely aesthetic reasons. See the guides to editing articles for accessibility at  [[WP:CONTRAST|contrast]], [[ Wikipedia:Manual of Style/Accessibility|accessibility]] and [[WP:NAVBOXCOLOUR|navbox colors]].}}
{{High-use| 90150 }}
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->


== Purpose ==
== Purpose ==
This is how you insert colorized text, such as
{{font color|red|red}},
{{font color|orange|orange}},
{{font color|yellow|yellow|link=yes}},
{{font color|green|green}},
{{font color|blue|blue|link=cat}} and
{{font color|indigo|indigo}},
{{font color|violet|violet}},
and [[Help:Color#Color generation guide|many others]].


It's needed for matching a color theme such as in sports templates.
{{Template shortcut|Colors|Fcolor|Fontc|Fco}}
You can specify a {{font color|bg=yellow|text=background}} color too.


You can make any text link to any page. (See "yellow" and "blue" above.)
{{tl | Font color }} is how you insert colorized text, such as
{{ font color | #f54739 | red }},
{{ font color | #d46926 | orange }},
{{ font color | #099979 | green }},
{{ font color | #6485d1 | blue }} and
{{ font color | #8d7ebd | indigo }},
and more at [[wmdoc:codex/latest/style-guide/colors.html|Codex Style Guide for Wikimedia]] and [[Help:Color#Color generation guide|Color generation guide]].
You can specify its {{ font color | bg=#d1e9d2| fg=#534fa3| text=background }} color at the same time.


For example, giving your plain <kbd>[<nowiki/>[wikilink]]</kbd>, you get
{{tl | Font color }} is also how you can color wikilinks
to something other than blue for when you need to work within background colors.
Normally <kbd>[<nowiki/>[ wikilink ]]</kbd> &rarr; [[wikilink]],  
but here we use a {{tl | font color }} with {{para | link }} to create a black wikilink &rarr;
{{ font color | black | violet | link=yes | &nbsp;&nbsp;&nbsp;wikilink&nbsp;&nbsp;&nbsp; }}
You can make any text link to any page using the {{para|link}} parameter.


{| class="wikitable" style=color:green
This template will use [[Wikipedia:HTML5]] recommendations,  
|-
inserting the span tags
! header 1
{{tag|span|params=style="color:''color''"}} and
! header 2
{{tag|span|params=style="background-color:''color''"}}, so the page increases its readability and usability in both the wikitext and the rendered page.
! header 3
|-
| row 1, cell 1 [[wikilink]]
| row 1, cell 2
| row 1, cell 3
|-
| row 2, cell 1
| row 2, cell 2
| row 2, cell 3
|}
 
You need {<nowiki/>{font color | green | wikilink | link = yes }}
 
{| class="wikitable" style=color:green
|-
! header 1
! header 2
! header 3
|-
| row 1, cell 1 {{font color|green|wikilink|link=yes}}
| row 1, cell 2
| row 1, cell 3
|-
| row 2, cell 1
| row 2, cell 2
| row 2, cell 3
|}
 
Font color will use the latest [[Wikipedia:HTML5]] recommendations,
inserting the span tag attributes
: <code>style=background-color</code>:
: <code>style=color</code>:
for you, so your page increases its readability and usability in the wikitext and its rendering.


== Usage ==
== Usage ==


{{tlf|Font color}} has a one-color and a two-color form:
{{tlf | Font color }} has a one-color and a two-color form:
: <kbd>{<nowiki/>{font color|''color''|''text''}}</kbd>
: <kbd>{<nowiki/>{font color | ''color'' | ''text'' }}</kbd>
: <kbd>{<nowiki/>{font color|''text color''|''background color''|''text''}}</kbd>.
: <kbd>{<nowiki/>{font color | ''text color'' | ''background color'' | ''text'' }}</kbd>.


Either form has a <kbd>|link=</kbd> option, for colorizing (otherwise blue or red) wikilink text.
Either form has a <kbd>|link=</kbd> option, for colorizing (otherwise blue or red) wikilink text.
Line 70: Line 39:


You can also name the other fields.
You can also name the other fields.
: <kbd>{<nowiki/>{font color|fg=''color''|text=''text''}}</kbd>
: <kbd>{<nowiki/>{font color | fg=''color'' | text=''text'' }}</kbd>
: <kbd>{<nowiki/>{font color|fg=''text color''|bg=''background color''|text=''text''}}</kbd>
: <kbd>{<nowiki/>{font color | fg=''text color'' | bg=''background color'' | text=''text'' }}</kbd>
You can name <kbd>|fg=</kbd> or <kbd>|bg=</kbd>, which is nice, but...
You can name <kbd>|fg=</kbd> or <kbd>|bg=</kbd>, which is nice, but...
if you name either of them, you must also name <kbd>|text=</kbd>, which is a compromise.
if you name either of them, you must also name <kbd>|text=</kbd>, which is a compromise.
(See [[Help:Template#Parameters]] for why.)
(See [[Help:Template#Parameters]] for why.)


Spacing is never of any concern.
Spacing is of no concern.
:<code>.</code>{<nowiki/>{ font color | tan | green |{{spaces|3}}label{{spaces|3}}with{{spaces|4}}four{{spaces|5}}words{{spaces|3}}}}<code>.</code> &rarr; <code>.</code>{{ font color | tan | green | label  with   four     words}}<code>.</code>
:<code>.</code><kbd>{<nowiki/>{font color|tan|green|text with four words}}</kbd><code>.</code> &rarr; <code>.</code>{{font color|tan|green|text with four words }}<code>.</code>
:<code>.</code> {<nowiki/>{ font color | fg = tan | bg = green | text = {{spaces|3}} label {{spaces|3}} with{{spaces|4}} four{{spaces|5}} words{{spaces|3}} }} <code>.</code> &rarr;  <code>.</code> {{ font color | fg = tan | bg = green |  text = label  with    four    words}} <code>.</code>
:<code>.</code><kbd> {<nowiki/>{font color|tan|green|text with four words}} </kbd><code>.</code> &rarr; <code>.</code> {{font color|tan|green|text with four words }} <code>.</code>
:<code>.</code><kbd> {<nowiki/>{ font color | tan | green | text with four words }} </kbd><code>.</code> &rarr;  <code>.</code> {{ font color | tan | green |  text   with    four    words }} <code>.</code>


===Parameters===
=== Parameters ===
{{Aligned table
{{Aligned table
  |cols=3 |style=padding:0.5em 0;line-height:1.35em;margin-bottom:1.0em;
  |cols=3 |style=padding:0.5em 0;line-height:1.35em;margin-bottom:1.0em;
Line 107: Line 77:


== Examples ==
== Examples ==
<div style="background-color:var(--background-color-base); border:1px solid var(--border-color-base); padding:0.6em; margin:4px;">Using the [[wmdoc:codex/latest/design-tokens/color|Codex Design Style Guide for Wikimedia]] text colors:
* {{#invoke:demoTemplate|font color|var(--color-success, #177860)|'''Success'''}}
* {{#invoke:demoTemplate|font color|#008560|'''Success green from'''}} ''(color derived from [[Template:Talk quote inline]])''
* {{#invoke:demoTemplate|font color|var(--color-error, #bf3c2c)|'''Error'''}}
* {{#invoke:demoTemplate|font color|var(--color-content-added, #006400)|'''Content added'''}}
* {{#invoke:demoTemplate|font color|var(--color-content-removed, #8b0000)|'''Content removed'''}}
* {{#invoke:demoTemplate|font color|var(--color-progressive, #36c)|Fake wikilink}}
* {{#invoke:demoTemplate|font color|var(--color-content-link-red, #bf3c2c)|Fake red link}}</div>


{|class=wikitable
{|class=wikitable
Line 112: Line 91:
!Renders as
!Renders as
|-
|-
|<code><nowiki>{{font color|green|green text}}</nowiki></code>
| <code><nowiki>{{ font color | green | green text }}</nowiki></code>
|{{font color|green|green text}}
| {{ font color | green | green text }}
|-
| <code><nowiki>{{ font color | blue | do not style text as a link }}</nowiki></code>
| {{ font color | blue | do not style text as a link }}
|-
|  | <code>{<nowiki/>{ font color'''{{large | {{! }}<nowiki/>{{! }} }}'''yellow | default text in yellow background }}</code>
| {{ font color |  | yellow | default text in yellow background }}
|-
|-
|<code><nowiki>{{font color|blue|do not style text as a link}}</nowiki></code>
| <code>{<nowiki/>{ font color'''{{large | {{! }} }}'''bg=yellow | text = default text in yellow background }}</code>
|{{font color|blue|do not style text as a link}}
| {{ font color | bg=yellow | text = default text in yellow background }}
|-
|-
|<code><nowiki>{{font color|white|black|white with black background}}</nowiki></code>
| <code><nowiki>{{ font color | white | black | white with black background }}</nowiki></code>
|{{font color|white|black|white with black background}}
| {{ font color | white | black | white with black background }}
|-
|-
||<code>{<nowiki/>{font color'''{{big|{{!}}<nowiki/>{{!}}}}'''yellow|default text in yellow background}}</code>
| <code><nowiki>{{ font color | #ffffff | #000000 | white with black background }} ([[hexadecimal colors]]) </nowiki></code>
|{{font color||yellow|default text in yellow background}}
| {{ font color | #ffffff | #000000 | white with black background}} ([[hexadecimal colors]])
|-
|-
||<code>{<nowiki/>{font color'''{{big|{{!}}}}'''bg=yellow|text=default text in yellow background}}</code>
| <code><nowiki>{{ font color | rgb(255,255,255) | rgb(0,0,0) | white with black background }}</nowiki></code>
|{{font color|bg=yellow|text=default text in yellow background}}
| {{ font color | rgb(255,255,255) | rgb(0,0,0) | white with black background}}
|}
|}


Line 132: Line 117:
!Renders as
!Renders as
|-
|-
|<code><nowiki>{{font color|white|blue|Wikipedia:Example|link=yes}}</nowiki></code></code>
| <code><nowiki>{{ font color | white | blue | Wikipedia:Example | link = yes }}</nowiki></code>
|{{font color|white|blue|Wikipedia:Example|link=yes}}
| {{ font color | white | blue | Wikipedia:Example | link = yes }}
|-
|-
|<code><nowiki>{{font color|white|blue|Example|link=Wikipedia:Sandbox}}</nowiki></code>
| <code><nowiki>{{ font color | white | blue | Wikipedia:Example | link = Wikipedia:Sandbox }}</nowiki></code>
|{{font color|white|blue|Example|link=Wikipedia:Sandbox}}
| {{ font color | white | blue | Wikipedia:Example | link = Wikipedia:Sandbox }}
|-
|-
|<code><nowiki>{{font color|text=Example|link=Wikipedia:Sandbox|bg=blue|fg=white}}</nowiki></code>
| <code><nowiki>{{ font color | text = Wikipedia:Example | link = Wikipedia:Sandbox | bg
|{{font color|text=Example|link=Wikipedia:Sandbox|bg=blue|fg=white}}
= blue | fg = white }}</nowiki></code>
| {{ font color | text = Wikipedia:Example | link = Wikipedia:Sandbox | bg = blue | fg = white }}
|}
|}


The {{para|link}} parameter is a good way to colorize wikilinks,
The {{para|link}} parameter is a good way to colorize wikilinks,
and it is about as much typing as the [[wp:pipe trick|pipe trick]].
and it is about as much typing as the [[wp:pipe trick|pipe trick]].
*<code>[<nowiki />[Wikipedia:Sandbox|{<nowiki />{font color|white|blue|Example}}]]</code> &rarr; [[Wikipedia:Sandbox|{{font color|white|blue|Example}}]]  Linked by the pipe trick. {{OK}}
*{{#invoke:DemoTemplate|font color|white|blue|Example|link=Wikipedia:Sandbox}}  Linked by {{tl|font color}} {{OK}}
*{{#invoke:DemoTemplate|font color|red|[[Wikipedia:Sandbox]]}} Not "red" like it said, because text is a wikilink. {{cross}}
*{{#invoke:DemoTemplate|font color|white|green|[[Wikipedia:Sandborax]]}}  Not white on green: text is a wikilink. {{cross}}


<span style=background-color:yellow>
Although a wikilink accepts a ''font color'' (or other template or markup):
This span is style=background-color:yellow.
:<code>{{large|[<nowiki/>[}}Wikipedia:Example{{large|{{!}}}}{<nowiki />{font color|white|blue|the Wikipedia:Example page}}{{large|]]}}</code>
{{#invoke:DemoTemplate|font color|red|some red text}}.<br />
:→ [[Wikipedia:Example | {{ font color | white | blue | the Wikipedia:Example page}}]] (a font-colored link),
Link with {{#invoke:DemoTemplate|font color|purple|''The Color Purple''|link=The Color Purple}}.
a ''font color'' does not accept a wikilink, it creates wikilinks itself with {{para|link}}.
{{spaces|5}}Span ending.</span>
*{{OK }} {<nowiki/>{ font color | green | violet | Wikipedia:Example | link=yes }} → {{ font color | green | violet | Wikipedia:Example | link=yes }} (a {{para|link}} {{tl | font color }})
*{{cross }}{<nowiki/>{ font color | green | violet | the [<nowiki/>[Wikipedia:Example]] page}} → {{ font color | green | violet | the [[Wikipedia:Example]] page }} (Text with [<nowiki/>[wikilink brackets]] overrides the designated color)
*{{cross }}{<nowiki/>{ font color | green | violet | [<nowiki/>[Wikipedia:Exammple]] }} → {{ font color | green | violet | the [[Wikipedia:Exammple]] page }} (Text with [<nowiki/>[wikilink brackets]] overrides the designated color)
<!--
<!--


--><includeonly>For more examples see [[/testcases]].</includeonly>
--><includeonly>For more examples see [[/testcases]].</includeonly>
For actual mainspace template usage, here are search links for  
For actual mainspace template usage, here are search links for
* {{sl|hastemplate:"font color"|label=all usage}}.
* {{sl | hastemplate:"font color" | label=all usage }}.
* {{template usage|font color|pattern=link=|prefix=:|label=where <code>{{!}}link=</code> is used}}.
* {{template usage | font color | pattern=link= | prefix=: | label=where <code>{{! }}link=</code> is used }}.
* {{sl|hastemplate: "font color" prefix:F}}
* {{sl | hastemplate: "font color" prefix:F }} showing its use in articles whose title begins with the letter "F".


==See also==
==See also==
[[File:SVG Recognized color keyword names.svg|thumb|SVG's color keywords that can be used as a keyword value.]]
* [[WP:COLOR|Important Manual of Style information]]
* [[WP:COLOR|Important Manual of Style information]]
* [[Web colors]]
* [[Web colors]]
Line 170: Line 155:
* {{tl|color}}
* {{tl|color}}
* {{tl|background color}}
* {{tl|background color}}
* {{tl|coltit}} — colored table header cell
* {{tl|color contrast ratio}}
* {{tl|color contrast ratio}}
* {{tl|hilite}}
* {{tl|hilite}}
Line 175: Line 161:
* {{tl|tq}}
* {{tl|tq}}
* {{tl|xt}}
* {{tl|xt}}
<includeonly>
 
<includeonly>{{sandbox other||
<!-- categories -->
<!-- categories -->
[[Category:Text color templates]]
[[Category:Text color templates]]
}}
</includeonly>
</includeonly>

Latest revision as of 20:49, 24 January 2026

Purpose

{{ Font color }} is how you insert colorized text, such as red, orange, green, blue and indigo, and more at Codex Style Guide for Wikimedia and Color generation guide. You can specify its background color at the same time.

{{ Font color }} is also how you can color wikilinks to something other than blue for when you need to work within background colors. Normally [[ wikilink ]]wikilink, but here we use a {{ font color }} with |link = to create a black wikilink →    wikilink    You can make any text link to any page using the |link= parameter.

This template will use Wikipedia:HTML5 recommendations, inserting the span tags <span style="color:color">...</span> and <span style="background-color:color">...</span>, so the page increases its readability and usability in both the wikitext and the rendered page.

Usage

{{Font color}} has a one-color and a two-color form:

{{font color | color | text }}
{{font color | text color | background color | text }}.

Either form has a |link= option, for colorizing (otherwise blue or red) wikilink text.

|link=yes[[text]]
|link=fullpagename[[fullpagename]]

You can also name the other fields.

{{font color | fg=color | text=text }}
{{font color | fg=text color | bg=background color | text=text }}

You can name |fg= or |bg=, which is nice, but... if you name either of them, you must also name |text=, which is a compromise. (See Help:Template#Parameters for why.)

Spacing is of no concern.

.{{font color|tan|green|text with four words}}..text with four words.
. {{font color|tan|green|text with four words}} .. text with four words .
. {{ font color | tan | green | text with four words }} .. text with four words .

Parameters

Use / description Default value
{{{1}}} text color inherited
{{{2}}} text
link =yes or =fullpagename
Or
Use / description Default value
{{{1}}} text color inherited
{{{2}}} background color inherited
{{{3}}} text
link =yes or =fullpagename

Examples

Using the Codex Design Style Guide for Wikimedia text colors:
  • {{font color|var(--color-success, #177860)|'''Success'''}}Success
  • {{font color|#008560|'''Success green from'''}}Success green from (color derived from Template:Talk quote inline)
  • {{font color|var(--color-error, #bf3c2c)|'''Error'''}}Error
  • {{font color|var(--color-content-added, #006400)|'''Content added'''}}Content added
  • {{font color|var(--color-content-removed, #8b0000)|'''Content removed'''}}Content removed
  • {{font color|var(--color-progressive, #36c)|Fake wikilink}}Fake wikilink
  • {{font color|var(--color-content-link-red, #bf3c2c)|Fake red link}}Fake red link
Markup Renders as
{{ font color | green | green text }} green text
{{ font color | blue | do not style text as a link }} do not style text as a link
{{ font color || yellow | default text in yellow background }} default text in yellow background
{{ font color | bg=yellow | text = default text in yellow background }} default text in yellow background
{{ font color | white | black | white with black background }} white with black background
{{ font color | #ffffff | #000000 | white with black background }} ([[hexadecimal colors]]) white with black background (hexadecimal colors)
{{ font color | rgb(255,255,255) | rgb(0,0,0) | white with black background }} white with black background
Markup Renders as
{{ font color | white | blue | Wikipedia:Example | link = yes }} Wikipedia:Example
{{ font color | white | blue | Wikipedia:Example | link = Wikipedia:Sandbox }} Wikipedia:Example
{{ font color | text = Wikipedia:Example | link = Wikipedia:Sandbox | bg = blue | fg = white }} Wikipedia:Example

The |link= parameter is a good way to colorize wikilinks, and it is about as much typing as the pipe trick.

Although a wikilink accepts a font color (or other template or markup):

[[Wikipedia:Example|{{font color|white|blue|the Wikipedia:Example page}}]]
the Wikipedia:Example page (a font-colored link),

a font color does not accept a wikilink, it creates wikilinks itself with |link=.

  • Green tickY {{ font color | green | violet | Wikipedia:Example | link=yes }} → Wikipedia:Example (a |link= {{ font color }})
  • N{{ font color | green | violet | the [[Wikipedia:Example]] page}} → the Wikipedia:Example page (Text with [[wikilink brackets]] overrides the designated color)
  • N{{ font color | green | violet | [[Wikipedia:Exammple]] }} → the Wikipedia:Exammple page (Text with [[wikilink brackets]] overrides the designated color)

For actual mainspace template usage, here are search links for

See also

File:SVG Recognized color keyword names.svg
SVG's color keywords that can be used as a keyword value.