About Image Captions
This feature wraps images in a <figure>
tag only when the image carries independent meaning. If the image is part of the content and does not stand alone, it will not be enclosed in a <figure>
tag. Only CommonMark syntax is supported.
Usage
Single Image
With Caption
Markdown:

HTML:
<figure> <div> <figure> <img alt="A description of the image" src="url"> <figcaption>An image title</figcaption> </figure> </div></figure>
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
Without Caption
Markdown:

HTML:
<figure> <div> <img alt="A description of the image" src="url"> </div></figure>
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
Multiple Images
When you include only images within a paragraph, they will be grouped together. Hard or soft breaks can also be used.
With Caption
Markdown:

HTML:
<figure> <div> <figure> <img alt="Image 1 description" src="url1"> <figcaption>Image Title 1</figcaption> </figure> <figure> <img alt="Image 2 description" src="url2"> <figcaption>Image Title 2</figcaption> </figure> </div></figure>
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
Without Caption
Markdown:

HTML:
<figure> <div> <img alt="Image 1 description" src="url1"> <img alt="Image 2 description" src="url2"> </div></figure>
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
With Shared Caption
Markdown:

HTML:
<figure> <div> <img alt="Image 1 description" src="url1"> <img alt="Image 2 description" src="url2"> </div> <figcaption>This becomes the caption</figcaption></figure>
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
Single Image Link
With Caption
Markdown:
[](link-url "A link title")
HTML:
<figure> <a href="link-url"> <figure> <img alt="A description of the image" src="image-url"> <figcaption>An image title</figcaption> </figure> </a> <figcaption>A link title</figcaption></figure>
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
Markdown:
[](link-url "A link title")
HTML:
<figure> <a href="link-url"> <img alt="A description of the image" src="image-url"> </a> <figcaption>A link title</figcaption></figure>
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
Markdown:
[](link-url)
HTML:
<figure> <a href="link-url"> <figure> <img alt="A description of the image" src="image-url"> <figcaption>An image title</figcaption> </figure> </a></figure>
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
Without Caption
Markdown:
[](link-url)
HTML:
<figure> <a href="link-url"> <img alt="A description of the image" src="image-url"> </a></figure>
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
Multiple Image Link
When you include only a multiple-image link within a paragraph, the images will be grouped together. Hard or soft breaks can also be used.
With Caption
Markdown:
[](link-url "A link title")
HTML:
<figure> <a href="link-url"> <figure> <img alt="Image 1 description" src="image-url1"> <figcaption>Image Title 1</figcaption> </figure> <figure> <img alt="Image 2 description" src="image-url2"> <figcaption>Image Title 2</figcaption> </figure> </a> <figcaption>A link title</figcaption></figure>
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
Markdown:
[](link-url "A link title")
HTML:
<figure> <a href="link-url"> <img alt="Image 1 description" src="image-url1"> <img alt="Image 2 description" src="image-url2"> </a> <figcaption>A link title</figcaption></figure>
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
Markdown:
[](link-url)
HTML:
<figure> <a href="link-url"> <figure> <img alt="Image 1 description" src="image-url1"> <figcaption>Image Title 1</figcaption> </figure> <figure> <img alt="Image 2 description" src="image-url2"> <figcaption>Image Title 2</figcaption> </figure> </a></figure>
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
Without Caption
Markdown:
[](link-url)
HTML:
<figure> <a href="link-url"> <img alt="Image 1 description" src="image-url1"> <img alt="Image 2 description" src="image-url2"> </a></figure>
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
,girl,_Blue,yellow,green,cyan,purple,red,pink,_best,8k,UHD,masterpiece,male%20focus,%201boy,gloves,%20ponytail,%20long%20hair,.jpeg)
Root Relative Path and Relative Path
Root Relative Path
A root relative path refers to assets located in the public
directory of your project.
Markdown:


Relative Path
A relative path refers to assets inside the src
directory, and it is relative to the location of the current file.
Markdown:


Options
You can specify the options in the astro.config.mjs
file.
...import remarkImageCaption from "./src/plugins/remark-image-caption.ts"...export default defineConfig({ ... markdown: { ... remarkPlugins: [ ... remarkImageCaption, // Plugin here ...
Name | Type | Default | Description |
---|---|---|---|
className | string | "" | The class name to apply to the outer <figure> element. |
excludedPaths | (string | RegExp)[] | [] | An array of image paths that should be excluded from transformation. This can also be used to exclude paths like those under the src folder in Astro projects. |
lazyLoad | boolean | false | Set the loading attribute on <img> elements. |
linkAttributes | LinkAttributes | Set the target and relationship attributes for external links. These attributes can also be left unset to delegate handling to other plugins. |
linkAttributes
Name | Type | Default | Description |
---|---|---|---|
target | string | ” | Specify where to open linked documents. The default (empty) does not set a target on links. |
rel | string | ” | Define the relationship between the current document and the linked document. The default (empty) does not set any relationship. |