Galleries are images formed into rows and columns by use of the <gallery>...</gallery>
parser (conversion of Wikitext to HTML) tag.
Video Help:Gallery tag
Attributes and values
mode=
traditional
Default, effect is explained belownolines
No borders, less padding, captions centered under imagespacked
All images aligned by having same height, justified, captions centered under imagespacked-overlay
Like packed, but caption overlays the image, in a translucent boxpacked-hover
Like 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)slideshow
Slideshow
caption=
Adds an overall caption above the gallerywidths=
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=yes
Show 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
Maps Help:Gallery tag
Usage notes
- Indiscriminate use of the
perrow
attribute 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
perrow
is 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
perrow
is now the recommended default. Prior to MediaWiki 1.17, the default was 4. - The default width and height are currently 120px. It is good practice not to overspecify the size (instead, accept the default size), unless there is a strong reason to override the user's viewing preferences; see WP:IMAGESIZE for further explanation of this issue.
- The
packed
mode will automatically adjust image sizes to use available display space optimally. - Every line specifies an image file. The
File:
prefix is optional. However, it is helpful to include it as an aid for quickly locating image specifiers in the wikitext (for example, when cleaning up page layout). - The parameter "thumb" is invalid, and must not be used.
- Captions are optional, and are separated from file name by a vertical bar ("|").
- Brackets ("[" or "]") must not be included, except for Wikilinks embedded within captions.
- A common mistake is to forget the closing
</gallery>
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)
Syntax
There are several "modes" of galleries.
traditional:
"Traditional" mode is currently the default, and, as such, need not be specified. The basic syntax is:
Which gives:
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.
nolines:
By specifying the "nolines" mode parameter, the boxes are removed. Using the same syntax as before, but replacing <gallery>
with <gallery mode=nolines>
we get:
packed:
Changing <gallery>
to <gallery mode=packed>
produces a centered gallery with significantly less wasted space around each image, as shown below.
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 ugly images. See below.
Packed-overlay: This uses <gallery mode=packed-overlay>
to produce captions overlaying the bottom of the image. The captions are probably best kept short.
Packed-hover:
This uses <gallery mode=packed-hover>
. Hover your mouse over the images below. NOTE: This defaults to the behaviour of packed-overlay on the mobile site.
Slideshow:
By default this mode uses all the available space for the slideshow which usually results in very large images. As the heights
and weights
parameters are ignored, the size needs to be restricted manually as show in the following example.
gives:
Extended syntax
Besides mode, the extended syntax is (see gallery tag help and hereafter for full list of parameters):
Which produces:
The widths=
and perrow=
parameters do nothing in the packed, packed-overlay, or packed-hover modes.
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 galeries 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:
gives:
As you can see, the narrowness of the image distorts the caption. This may easily be fixed by adding the heights=
parameter, as such.
gives:
Other advice for using packed mode is to keep captions for particularly narrow images as short as is convenient.
Captions
For all modes except traditional, captions are centred. To left-align the captions, specify the CSS declaration text-align:left
in the style=
attribute:
gives:
Center
To center a gallery use class="center"
:
<gallery class="center"> File:Detroit Publishing Co. - A Yeoman of the Guard (N.B. actually a Yeoman Warder), full restoration.jpg|1 File:Official_program_-_Woman_suffrage_procession_March_3,_1913_-_crop.jpg|2 File:Thurston, the famous magician - East Indian Rope Trick.jpg|3 File:Joseph Ferdinand Keppler - The Pirate Publisher - Puck Magazine - Restoration by Adam Cuerden.jpg|4 </gallery>
Which gives:
The use of the perrow
attribute will cause this to not work. Where a specific number of images per row is desired, use separate <gallery>
elements. Centered galleries are the default for most variant gallery modes.
See also
- Wikipedia:Manual of Style/Images
- Wikipedia:Picture tutorial
- Wikipedia:Extended image syntax
- m:Template:gallery (backlinks edit)
- More gallery options: see the drop-down box for more CSS gallery code
- mw:Help:Images#Rendering a gallery of images
Source of article : Wikipedia