A Payload site, ready to clone

Images in text

An image in a text, small, medium or full width, to the left or the right with the text around it, or centred.

What it does

An image placed in a rich text, the Prose block or a post’s text, has two settings of its own: its size and its alignment. Small and medium are two fixed widths the site’s theme decides, the same everywhere, so the pages stay consistent; full width is the image as it was, up to the width of the text. An image is never enlarged past its own file.

Start and end put the image to one side with the text flowing around it and a gap between them: the text’s own sides, left and right in a left-to-right language, swapped in a right-to-left one. Centre puts it in the middle on a line of its own. On a phone there is no room for text beside an image, so every image sits on its own line at its size. A floated image never runs into the next block.

The size is also in the page’s markup, not only in its style: a feed reader, an email or anything that reads the HTML without the site’s stylesheet shows the image at the chosen size, not aligned. Images saved before these settings existed look as they did.

See it in the demo

Below, three images in one Prose block: a small one to the left, a medium one to the right and a small one centred. Narrow the window under the width of a tablet and they stack. In the admin, edit this page, click an image in the text and then its edit button: the drawer has Size and Alignment, and a Caption and an Alt text of its own. The news posts have one too.

For developers

The fields are on the rich text’s upload node (UploadFeature’s fields for Media, src/lib/richTextEditor.ts), stored in the rich text’s JSON: no migration. The upload converter in src/components/site/RichTextContent.tsx writes the rich-text-image class with data-size and data-align, the width and height of the size’s default width (src/lib/richTextImage.ts) and a sizes attribute for it; styles.css floats and sizes them from the tokens --opa--rich-text--layout--image-small and --image-medium (15rem and 30rem) and --opa--rich-text--space--image-gap, which a theme may set. The feeds keep the size and drop the alignment.

Small, at the start

Placeholder: rounded tiles in soft blue and orange

This image is set to Small and Start (on the left in English). The text of the paragraph flows around it on its right, with a gap that comes from the theme, and goes back to the full width of the column once it has passed the image. On a phone, or in a narrow window, the image stands on a line of its own above the text instead, at the same size, so the text never gets squeezed into a thin strip beside it. It is the arrangement an imported WordPress post with an alignleft image gets.

Medium, at the end

Teal waves beside a paragraph about image sizes
Layered waves, a caption of this text only: it floats with the image.

This one is Medium and End (on the right in English): twice the width of a small image, on the other side. The width of each size is a token of the theme, so a project can make every medium image in the site wider or narrower in one place, without touching a single page. The browser still picks a file that fits: the image offers its copies in several widths, and the sizes attribute says how wide a medium image is, so a small copy is downloaded, not the original. Its caption, under it, is its own: written in this text, not taken from the Media library, and so is its alt text.

Small, centred

Placeholder: concentric circles in violet

And this one is Small and Centre: on its own line, in the middle of the column. Centred images never have text beside them.

One block, every feature page

This strip is a reusable block: written once and placed at the end of every feature page. Edit it under Reusable blocks and all of them change.

All features