Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Template:If dark

Permanently protected template
From Wikipedia, the free encyclopedia

Light modeDark mode

Template documentation[view] [edit] [history] [purge]
CSSThis template usesTemplateStyles:

This template detects whether it is being used with dark mode, and displays different content accordingly. This should however NOT be relied upon. For instance: It may not work with thedark mode gadget. You can use thebackground-image property with a URL insideTemplateStyles with different versions for dark mode and light mode instead.

Rationale

Some images and text need to be different depending on the mode selected by the user. This template provides an easy way to do that.

Usage

{{If dark|content for dark mode|content for light mode}}

By default,<span>...</span> tags are used to wrap the specified content. A different tag may be specified using|tag=

E.g.|tag=div can be used if the content contains block-level elements.

Notes

  • This template will only work with Wikipedia's official dark theme. It will not work with browser extensions such as Dark Reader orthe dark mode gadget, due to relying on the<html> tag having the.skin-theme-clientpref-night class.
  • This templatedoes not actually switch the content between the light and dark mode; it simply outputs both, and hides the content for the opposite theme using CSS.

Example

Normal usage

{{If dark|You are using dark mode!|You are using light mode!}} yields:

Light modeDark mode
You are using light mode!You are using dark mode!You are using light mode!You are using dark mode!
Namespace and pagename-detecting templates
Namespace
Particular
More generic
Pagename
When on basepage
Detects and acts according to whether it is on a basepageor on any subpage (that is, a../.. subpage).
When pagename is
For pattern matching on the pagename.
Module:Page
Can take apart and put together pagenames in several ways.
If temporary account
Page identifies a temporary account
IP-talk
Returns IP-user talkpage, registered-user talkpage or non-user talkpage.
IP-user other
For detecting IP-user pages.
Subpage other
Pagename has an after-slash part (not in mainspace)
Sandbox other
Page is subpage /sandbox (template space)
Testcases other
Page is subpage /testcases (template space)
Rootpage other
Page is rootpage (vs. /subpage) (template space)
Others
Stub other
Detects whether it is on a page with a stub template or not.
Redirect other
Detects whether it is on a redirect or not.
If preview
Detects whether page is viewed as a preview or not.
If IP
Displays different content to IP users and logged-in users.
If autoconfirmed
Displays different content to autoconfirmed and non-autoconfirmed users.
If extended confirmed
Displays different content to extended confirmed and non-extended confirmed users.
If administrator
Displays content only to admins.
If mobile
Displays different content to mobile users and desktop users.
If dark
Displays different content to dark mode users and light mode users.
Noscript
Detects whether page is viewed with a JavaScript-capable client or not.
The abovedocumentation istranscluded fromTemplate:If dark/doc.(edit |history)
Editors can experiment in this template'ssandbox(edit |diff) andtestcases(edit) pages.
Add categories to the/doc subpage.Subpages of this template.
Retrieved from "https://en.wikipedia.org/w/index.php?title=Template:If_dark&oldid=1308061311"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp