Jump to content

Help:Gallery tag

From Wikipedia, the free encyclopedia
(Redirected from Help:Gallery)

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

[edit]

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

[edit]
c
p
1 2 3 4 5 6 7 8 9 10 11 12
1 0 1 1 1 1 1 1 1 1 1 1 1
2 0 0 2 2 2 2 2 2 2 2 2 2
3 0 1 0 3 3 3 3 3 3 3 3 3
4 0 0 1 0 4 4 4 4 4 4 4 4
5 0 1 2 1 0 5 5 5 5 5 5 5
6 0 0 0 2 1 0 6 6 6 6 6 6
7 0 1 1 3 2 1 0 7 7 7 7 7
8 0 0 2 0 3 2 1 0 8 8 8 8
9 0 1 0 1 4 3 2 1 0 9 9 9
10 0 0 1 2 0 4 3 2 1 0 10 10
11 0 1 2 3 1 5 4 3 2 1 0 11
12 0 0 0 0 2 0 5 4 3 2 1 0
13 0 1 1 1 3 1 6 5 4 3 2 1
14 0 0 2 2 4 2 0 6 5 4 3 2
15 0 1 0 3 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 4 3 4 7 2 8 4
53 0 1 2 1 3 5 4 5 8 3 9 5
54 0 0 0 2 4 0 5 6 0 4 10 6
55 0 1 1 3 0 1 6 7 1 5 0 7
56 0 0 2 0 1 2 0 0 2 6 1 8
57 0 1 0 1 2 3 1 1 3 7 2 9
58 0 0 1 2 3 4 2 2 4 8 3 10
59 0 1 2 3 4 5 3 3 5 9 4 11
60 0 0 0 0 0 0 4 4 6 0 5 0
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 perrow=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).

Inserting images

[edit]

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; |thumb=, |right=, |left=, and px values are not supported and may cause invalid image option errors. Optionally, remove the File: prefix. You will be left with the following: Name of file|Caption

If you do not want to include a caption, remove |Caption as well.

Syntax

[edit]

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|1
Official_program_-_Woman_suffrage_procession_March_3,_1913_-_crop.jpg|2
Thurston, the famous magician - East Indian Rope Trick.jpg|3
Joseph 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 overly long stacks of caption text. 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

[edit]

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

<gallery caption="Sample gallery" widths="180px" heights="120px">
Wiki.png|Captioned
Wiki.png|alt=The Wikipedia logo|Captioned with alt text
Wiki.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:

To avoid long stacks of caption text keep captions for narrow images short.

Captions

[edit]

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:

Centered captions: 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>

Multi-line captions: To specify line breaks, add <br> HTML tags, or use {{br}}. If you need a blank line, you can use {{br|2}}.

Center

[edit]

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|1
Official_program_-_Woman_suffrage_procession_March_3,_1913_-_crop.jpg|2
Thurston, the famous magician - East Indian Rope Trick.jpg|3
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

[edit]