Figuring out Figures
Images form a major part of what makes the internet such a delightful and terrifying place in equal measure. On sites like this one and similar small web auspices, you’ll likely find all kinds of images, but much will just be cruft. I use the term here in a non-derogatory way, though. I’m referring to the pretty icons and such that blend into the user interface of the website. These are important, but that’s not what we’re talking about today.
A second category of image that goes on your pages, of course, will be those that you want to show your visitors for illustrative purposes. This could be anything from a photo of an interesting rock you’ve found to a graph showing the rise of income inequality in America. Most people just insert these into their pages with an <img src=“path”> tag - and you quite well should. There is, however, an addition to the equation that can be rather helpful, but has been forgotten by many - <figure> tags.
Back in the Before Times, <figure> and related tags were intended to separate images (and some other stuff) from the rest of the content (both stylistically and in terms of functionality). These include the <figcaption> tag, which (perhaps most importantly) provides extra information (a title, for example) about the contents of the <figure>.
View a live preview of two versions of this on Codepen... content warning: sad architecture.
HTML
In this example, and on my sites in general, I use <figure> to surround images, but playing with it a bit will allow for more. Here, I’ve created a <figure> configuration (pun intended) displaying an image. The image itself is linked, both as itself and within a descriptive caption, to a source for it, so that the user knows where to find more about it quickly, as does the browser itself. You can and obviously should include both the image and proper, useful information in the caption when rendering your own version of this - otherwise, what’s the point of using <figure> tags?
CSS
This will work without CSS to a degree as most things on the web will; however, here are some basic aesthetic (sort of) stylings for figures. The below brutalist-themed example hopefully explains well enough how you might go about customizing the appearance of these things. I believe customization of some sort is ideal - at least add borders to distinguish things.
The example above will position the <figure> element and its contents central within the page on their own line. You might also want to (in certain contexts) float the figure or caption to the right or left within the flow of the text. In order to do that (with the exact same stylings as above, give the below styles a go…