Help:Gallery tag

(Redirected from H:GT)

A gallery displays several pictures in an array or similar layout.

Galleries can display images formed into rows and columns by use of the <gallery>...</gallery> parser (conversion of Wikitext to HTML) tag. Be aware that different screen size 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=
    • traditional Default, effect is explained below
    • nolines No borders, less padding, captions centered under images
    • packed All images aligned by having same height, justified, captions centered under images
    • packed-overlay Like packed, but caption overlays the image, in a translucent box
    • packed-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 (or title) above the gallery; for multiple words, enclose in double quotes
  • widths= 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 image
  • class= One or more class names separated with spaces and enclosed in double quotes
  • style= One or more CSS declarations separated with semicolons and enclosed in double quotes

Usage notes

c
p
123456789101112
1011111111111
2002222222222
3010333333333
4001044444444
5012105555555
6000210666666
7011321077777
8002032108888
9010143210999
1000120432101010
110123154321011
12000020543210
13011131654321
14002242065432
15010303176543
16001014207654
17012125318765
18000230420876
19011341531987
20002002642098
21 – 60 pictures
Green: ideal, Yellow: under half full, Red: orphan
c
p
123456789101112
210101130531109
220012241642010
230123352753111
24000040306420
25011101417531
26002212528642
27010323630753
28001034041864
29012145152975
30000200263086
31011311374197
320020224052108
33010133516309
340012446274110
350123050385211
36000010140630
37011121251741
38002232362852
39010343473963
40001004504074
41012115615185
42000220026296
430113311373107
44002042248408
45010103350519
460012144616210
470123255727311
48000030603840
49011141014951
50002202125062
51010313236173
52001024347284
53012135458395
540002405604106
55011301671507
56002012002618
57010123113729
580012342248310
590123453359411
60000000446050
Green: ideal, Yellow: under half full, Red: orphan

Number of pictures on last row of gallery
with c columns (browser-dependent)
and p pictures (editor can control)

i.e. good number of pictures to have in a gallery:
1, 2, 3, 4, 6, 8, 12, 14, 18, 20, ...
  • 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. Images displayed by the <Gallery>...</Gallery> tag do not obey user viewing preferences.
  • The packed mode 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 </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).

Loading in images

When loading in images using the Insert > Images and media, you will get the following:[[File:Name of file|thumb|Caption]]

In a gallery, you must remove all brackets ("[" or "]") (Except in wikilinks that are embedded within captions). You must also remove the |thumb. Finally, remove the File: prefix. You will be left with the following:Name of file|Caption

This is acceptable to the gallery. If you do not want to include a caption, remove |Caption.

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:

<gallery>Detroit Publishing Co. - A Yeoman of the Guard (N.B. actually a Yeoman Warder), full restoration.jpg|1Official_program_-_Woman_suffrage_procession_March_3,_1913_-_crop.jpg|2Thurston, the famous magician - East Indian Rope Trick.jpg|3Joseph Ferdinand Keppler - The Pirate Publisher - Puck Magazine - Restoration by Adam Cuerden.jpg|4</gallery>

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 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.

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.

Extended syntax

Besides mode, the extended syntax is (see gallery tag help and hereafter for full list of parameters):

<gallery caption="Sample gallery" widths="180px" heights="120px">Wiki.png|CaptionedWiki.png|alt=The Wikipedia logo|Captioned with alt textWiki.png|[[Help:Contents/Links|Links]] can be put in captions.Wiki.png|Full [[MediaWiki]]<br />[[syntax]] may now be used...</gallery>

Which produces:

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:

<gallery mode="packed">Detroit Publishing Co. - A Yeoman of the Guard (N.B. actually a Yeoman Warder), full restoration.jpg|A Yeoman Warder, from a Victorian-era [[photochrom]]Official_program_-_Woman_suffrage_procession_March_3,_1913_-_crop.jpg|The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.Thurston, the famous magician - East Indian Rope Trick.jpg|[[Howard Thurston]] performing the [[Indian rope trick]]Joseph Ferdinand Keppler - The Pirate Publisher - Puck Magazine - Restoration by Adam Cuerden.jpg|"The Pirate Publisher", a satire of copyright infringement from the magazine ''[[Puck (magazine)|Puck]]''.</gallery>

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.

<gallery mode=packed heights=200px>Detroit Publishing Co. - A Yeoman of the Guard (N.B. actually a Yeoman Warder), full restoration.jpg|A Yeoman Warder, from a Victorian-era [[photochrom]]Official_program_-_Woman_suffrage_procession_March_3,_1913_-_crop.jpg|The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.Thurston, the famous magician - East Indian Rope Trick.jpg|[[Howard Thurston]] performing the [[Indian rope trick]]Joseph Ferdinand Keppler - The Pirate Publisher - Puck Magazine - Restoration by Adam Cuerden.jpg|"The Pirate Publisher", a satire of copyright infringement from the magazine ''[[Puck (magazine)|Puck]]''.</gallery>

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 centered. To left-align the captions, specify the CSS declaration text-align:left in the style= attribute:

<gallery mode=packed heights=150px style="text-align:left">Detroit Publishing Co. - A Yeoman of the Guard (N.B. actually a Yeoman Warder), full restoration.jpg|A Yeoman Warder, from a Victorian-era [[photochrom]]Official_program_-_Woman_suffrage_procession_March_3,_1913_-_crop.jpg|The Official program of the 1913 Woman Suffrage Procession held in Washington, D.C.Joseph Ferdinand Keppler - The Pirate Publisher - Puck Magazine - Restoration by Adam Cuerden.jpg|"The Pirate Publisher", a satire of copyright infringement from the magazine ''[[Puck (magazine)|Puck]]''.</gallery>

gives:

To center a caption when other options are ineffective, perhaps the most-reliable alternative is to use:

yourimage.jpg | <div style="text-align: center;">yourcaption</div>

Center

To center a gallery use class="center":

<gallery class="center">Detroit Publishing Co. - A Yeoman of the Guard (N.B. actually a Yeoman Warder), full restoration.jpg|1Official_program_-_Woman_suffrage_procession_March_3,_1913_-_crop.jpg|2Thurston, the famous magician - East Indian Rope Trick.jpg|3Joseph 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