Help:Gallery tag
Template:For Template:For Template:Redirect Template:Wikipedia how-to Template:Warning
A gallery tag displays several pictures in an array or similar layout.
Galleries can display images formed into rows and columns by using the Template:Xtag (conversion of Wikitext to HTML) tag. Be aware that different screen sizes and browsers may affect accessibility for some readers.
Attributes and values
Attributes and values go after the word gallery and a blank space, and before the ending angle bracket:
<gallery attributes...>
mode=traditionalDefault, effect is explained belownolinesNo borders, less padding, captions centered under imagespackedAll images aligned by having same height, justified, captions centered under imagespacked-overlayLike packed, but caption overlays the image, in a translucent boxpacked-hoverLike packed-overlay, but caption is only visible on hover (degrades gracefully on screen readers, and falls back to packed-overlay if a touch screen is used)slideshowSlideshow
caption=Adds an overall caption (or title) above the gallery; for multiple words, enclose in double quoteswidths=Maximum image widths in pixels (has no effect if mode is set to packed, packed-overlay, packed-hover, or slideshow)heights=Image heights in pixels (has no effect if mode is set to slideshow)perrow=Number of images per row (has no effect if mode is set to packed, packed-overlay, packed-hover, or slideshow; See usage notes, below)showfilename=yesShow each filename below the corresponding imageclass=One or more class names separated with spaces and enclosed in double quotesstyle=One or more CSS declarations separated with semicolons and enclosed in double quotes
Usage notes
- Indiscriminate use of the
perrowattribute is strongly discouraged, because it overrides flexible use of different display sizes and aspect ratios, ranging from mobile miniature to wide "cinema" screens. However, the attribute should be used when a fixed grid arrangement is appropriate, such as "before/after", "low/medium/high", or other systematic comparisons of images. - If
perrowis omitted, the width is fluid: one row comprises as many images as will fit across the available width of the user's display, wrapping automatically to as many additional lines as needed. - Omitting
perrowis now the recommended default. Prior to MediaWiki 1.17, the default wasperrow=4. - The default width and height are currently 120px. Images displayed by the Template:Tag tag do not obey user viewing preferences.
- The
packedmode will automatically adjust image sizes to use available display space optimally. - Every line specifies an image file. The
File:prefix is unnecessary. - Captions are optional and are separated from file name by a vertical bar ("|").
- A common mistake is to forget the closing Template:Tag tag.
- When using, note that many parameters, specifically those relating to visual appearance, may not apply or work as expected to certain skins (notably the Minerva skin used by the mobile site).
Inserting images
When inserting images using the Insert > Images and media option, you will get the following:
[[File:Name of file|thumb|Caption]]
In a gallery, you must remove all brackets ("[" or "]") (except in wikilinks embedded within captions). You must also remove all options except for the caption and Template:Para. Note that Template:Para, Template:Para, Template:Para, Template:Para, Template:Para, Template:Para, and px values are not supported and may cause invalid image option errors.
The File: prefix can be omitted, leaving you with Name of file|Caption. However, it is helpful to include the prefix as an aid for quickly locating image specifiers in a gallery.
If you do not want to include a caption, remove |Caption as well.
Syntax
There are several "modes" of galleries.
"Traditional" mode is currently the default, and, as such, need not be specified. The basic syntax is:
<syntaxhighlight lang="xml">
-
1
-
2
-
3
-
4
</syntaxhighlight>
Which gives:
-
1
-
2
-
3
-
4
If you want to make sure that any future changes to the default gallery mode will keep this style of gallery, you may specify "mode=traditional", similar to the examples below.
By specifying the "nolines" mode parameter, the boxes are removed. Using the same syntax as before, but replacing Template:Xtag with Template:Xtag we get:
-
1
-
2
-
3
-
4
Changing Template:Xtag to Template:Xtag produces a Template:Em gallery, with slightly to significantly less space around each image (depending on its relative width and height), as shown below. It may relatively enlarge some images that were smaller in the above views.
-
1
-
2
-
3
-
4
For lengthy captions under narrow images, it's probably best to add a heights= parameter to make the images somewhat larger, as the default small size can lead to overly long stacks of caption text. See below.
Template:Visible anchor: This uses Template:Xtag to produce captions overlaying the bottom of the image. The captions are probably best kept short.
This uses Template:Xtag. Hover your mouse over the images below.
-
The captions
-
appear when
-
you
-
mouse over
This uses Template:Xtag.
Extended syntax
Besides mode, the extended syntax is (see gallery tag help and hereafter on MediaWiki.org for full list of parameters):
<syntaxhighlight lang="xml">
- Sample gallery
-
Captioned
-
Captioned with alt text
-
Links can be put in captions.
</syntaxhighlight>
Which produces:
- Sample gallery
-
Captioned
-
Captioned with alt text
-
Links can be put in captions.
The widths= and perrow= parameters do nothing in the packed, packed-overlay, or packed-hover modes, and class="center" does nothing when perrow= is used.
However, the heights= parameter can be extremely useful in these modes. This parameter specifies the initial height to render every image thumbnail, before images are possibly scaled up (keeping their size ratio) by JavaScript to fill rows; when needed the Javascript will query the image server to get resized thumbnails for several scales between 100% (the initial height specified) and about 125%. This gives good-looking galleries that can fill pages even when their size ratio are not exactly the same and allows using the actual area available for displaying on narrow mobile and large notebook/desktop/TV, and printing on various paper formats. (This mode also allows horizontally auto-scrollable galleries by embedding them in a large container within a scrollable container sized to fit the page width.)
For example, take the following:
<syntaxhighlight lang="xml">
-
A Yeoman Warder, from a Victorian-era photochrom
-
The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.
-
Howard Thurston performing the Indian rope trick
-
"The Pirate Publisher", a satire of copyright infringement from the magazine Puck.
</syntaxhighlight>
gives:
-
A Yeoman Warder, from a Victorian-era photochrom
-
The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.
-
Howard Thurston performing the Indian rope trick
-
"The Pirate Publisher", a satire of copyright infringement from the magazine Puck.
As you can see, the narrowness of the image distorts the caption. This may easily be fixed by adding the heights= parameter, as such.
<syntaxhighlight lang="xml">
-
A Yeoman Warder, from a Victorian-era photochrom
-
The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.
-
Howard Thurston performing the Indian rope trick
-
"The Pirate Publisher", a satire of copyright infringement from the magazine Puck.
</syntaxhighlight>
gives:
-
A Yeoman Warder, from a Victorian-era photochrom
-
The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.
-
Howard Thurston performing the Indian rope trick
-
"The Pirate Publisher", a satire of copyright infringement from the magazine Puck.
To avoid long stacks of caption text keep captions for narrow images short.
Captions
For all modes except traditional, captions are centered. To left-align the captions, specify the CSS declaration text-align:left in the style= attribute:
<syntaxhighlight lang="xml">
-
A Yeoman Warder, from a Victorian-era photochrom
-
The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.
-
"The Pirate Publisher", a satire of copyright infringement from the magazine Puck.
</syntaxhighlight>
gives:
-
A Yeoman Warder, from a Victorian-era photochrom
-
The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.
-
The Pirate Publisher, a satire of copyright infringement from the magazine Puck.
Centered captions: To center a caption when other options are ineffective, perhaps the most-reliable alternative is to use:
<syntaxhighlight lang="xml">yourimage.jpg |
</syntaxhighlight>
Multi-line captions: To specify line breaks, add Template:Xtag HTML tags, or use Template:Tlx. If you need a blank line, you can use Template:Tlx.
Center
To center a gallery use class="center":
<syntaxhighlight lang="wikitext">
-
1
-
2
-
3
-
4
</syntaxhighlight>
Which gives:
-
1
-
2
-
3
-
4
The use of the perrow attribute will cause this to not work. Where a specific number of images per row is desired, use separate Template:Tag elements. Centered galleries are the default for most variant gallery modes.
See also
- Wikipedia:Image use policy
- Wikipedia:Manual of Style/Images
- Wikipedia:Manual of Style/Accessibility#Images
- Wikipedia:Extended image syntax
- Template:Tim
- More gallery options: see the drop-down box for more CSS gallery code
- mw:Help:Images#Rendering a gallery of images