Megacorp Documentation v2.0-beta

Images

The .. image:: directive puts a picture on the page with no caption. Its argument is a path relative to this document, a path from the source root (with a leading /), or an external URL.

A bare image

data/logo.svg

Alternative text

:alt: is what a screen reader announces. Writing :alt: with no value is the deliberate spelling for a picture that carries no information of its own.

The rinx logo

Sizing

:width: takes a length or a percentage; :height: takes a length only.

The logo at a fixed width The logo at half the available width

:scale: multiplies whatever :width: and :height: were given.

The logo scaled to half of 120px

Alignment

:align: left and :align: right float the picture, which means the text that follows flows around it rather than starting below it. That is what alignment is for, so each example below is followed by enough prose to show the wrapping.

A left-aligned logo

Floated to the left, so this paragraph wraps around its right-hand side. A floated image is taken out of the normal flow of the page: the text does not begin below it, it begins beside it, and only returns to the full width of the page once it has passed the bottom of the picture. Notice that the heading below still starts on a clean line — headings clear any float still standing, so one section's picture can never intrude into the next.

Centre alignment

:align: center does not float. The image stays in the normal flow as a block of its own, centred between the margins, and the text resumes below it.

A centred logo

This paragraph starts below the centred picture rather than beside it, which is the whole difference between centring and floating.

Right alignment

A right-aligned logo

Floated to the right, so this paragraph wraps around its left-hand side. Two images aligned to the same side stack one below the other rather than sitting side by side, and a centred image between them starts below the float rather than riding up alongside it — both of which depend on the clear rules in the stylesheet.

:target: accepts a URL, or the name of a target elsewhere in the project written with a trailing underscore.

The logo, linking to a website

This paragraph is a link target, and the next image points at it.

The logo, linking to a target in this document

Referring to an image

:name: makes the image itself a target, so the-logo reaches it.

A named logo

Classes

:class: puts extra class names on the <img> element.

A logo with a custom class

How the bytes reach the page

:loading: chooses between three answers. link is the default: the page points at the bundled file.

A linked logo

lazy links the same way, and additionally sets HTML's own loading="lazy" attribute so the browser can defer fetching the picture until it is nearly on screen.

A lazily loaded logo

embed puts the file's bytes into the page itself as a data: URI, so the page needs no second request — and no second file — to show it.

An embedded logo

An external image

An absolute URL is passed through untouched. Nothing is bundled for it and nothing is validated, since the file is not part of this project.

The Sphinx logo, loaded from the Sphinx website

A source-root-relative path

A leading / resolves from the top of the documentation source tree rather than from this document's own directory, which is what lets a deeply nested page name a shared asset without counting ../ segments.

The logo, named from the source root