Template:CSS image crop

Explain xkcd: It's 'cause you're dumb.
Revision as of 15:13, 13 January 2026 by JohnHawkinson (talk | contribs) (Can we just copy in the docs like that?)
Jump to: navigation, search

Template:Documentation subpage Template:High-use

Template:hatnote

{{CSS image crop}} creates a crop of an image inline for previewing the look and feel of a page, or for linking to full images when a slight crop is preferred in an article, but the full image is more encyclopaedic in general. Where only a small section of the image is used after the crop, it's best to upload the crop as a new file, to avoid sending the extra image data to users.

Note: There was a previous glitch for which some people had to use "tleft" "tright" etc. as a workaround because "left" and "right" did not work. As a result, to avoid having to fix all those pages that used the workaround, the template has been designed to function properly regardless of whether tright or right is used. See template talk for details.

Usage

<syntaxhighlight lang="wikitext">

<div class="thumbinner" style="width: Expression error: Unrecognized word "crop".px;">

[[File:The Name of the image file, or may accept Template:Annotated image.|The Base Image width in pixels (the image we are cropping on)px|alt=The alt text for the image.|link=Name of an article to be linked by clicking on the image (omit unless there is a good reason to link to an article instead of the image).|page=The page of the file, if there are multiple pages (such as pdf files).|class=The MediaWiki class, if needed. Useful for adding skin-invert for dark mode.]]
[[:The image to be linked by the magnify icon (Use if the Image parameter is set to Template:Annotated image or the Link parameter leads to something other than the image).| ]]
Description (will render out using thumbnail class)

</div> </syntaxhighlight>

Examples

Create a cropped image of a single water drop:

Thumbnail of the original file
Dew on grass Luc Viatour.jpg
  • Offset: oTop and oLeft define the upper left corner of the cropped image
  • Crop: cWidth and cHeight define the size of the cropped image
  • Base Size: Offset and Crop are calculated as if the original file had the width bSize
<syntaxhighlight lang="wikitext">
Dew on grass Luc Viatour.jpg
</syntaxhighlight>

In addition, the cropped image can have a caption-text and be positioned on the page:

  • Location= to position (center, right, left, none)
  • Description= to add a text to the caption
Dew on grass Luc Viatour.jpg
A drop of dew on grass (focus on the drop)
<syntaxhighlight lang="wikitext">
Dew on grass Luc Viatour.jpg
A drop of dew on grass (focus on the drop)
</syntaxhighlight>

Groups of cropped images can be arranged in an image frame: Template:Image frame <syntaxhighlight lang="wikitext"> Template:Image frame </syntaxhighlight>

Tracking categories

Scripts

The user script User:BrandonXLF/CSSImageCrop can be used to generate code to use this template with an interactive UI.

See also