Image Tag Redocly Custom Tag
The image
tag allows you to embed images into your content with various customization options.
Syntax and usage
Use the image
tag to include images. Customize with attributes like src
, alt
, width
, and height
.
{% img src="path/to/image.jpg" alt="Description of image" width="300" height="200" %}
Attributes
Attribute | Type | Description |
---|---|---|
src | string | Conditionally required. The source URL of the image. |
srcSet | string | Conditionally required. A set of source URLs to use for different color modes. |
alt | string | Descriptive text that provides context for the image to help with accessibility and people with visual impairments or who use assistive technologies to understand the content of images. |
className | string | CSS class to apply to the image. |
width | string | number | Sets the width of the image. Accepts:
|
height | string | number | Sets the height of the image. Accepts:
|
align | string | Describes how you want the image aligned on the page. Options: left , right , center , justify , initial , or inherit . Defaults to left . |
| string | Sets the border style of the image. Accepts standard CSS border values, such as:
Note: Border styles can also be applied using the |
withLightbox | boolean | Opens the image in a lightbox when the image is clicked. The lightbox image is opened in its original size or is scaled down to fit the screen if its original size is larger than then screen size. Default: false . |
style | object | string | Inline styles to apply to the image. Accepts either a CSS string or an object with camelCase properties:
|
Examples
Basic image with alt
text
{% img
alt="Basic example image"
srcSet="./images/img-markdoc/image-example-light.png light, ./images/img-markdoc/image-example-dark.png dark"
/%}
Image with width
and height
{% img
alt="Image with dimensions"
srcSet="./images/img-markdoc/image-example-light.png light, ./images/img-markdoc/image-example-dark.png dark"
width=300
height=200
/%}
Image with alignment
{% img
alt="Center aligned image"
width=200
height=200
srcSet="./images/img-markdoc/image-example-light.png light, ./images/img-markdoc/image-example-dark.png dark"
align="right"
/%}
Image with border
{% img
alt="Image with border"
srcSet="./images/img-markdoc/image-example-light.png light, ./images/img-markdoc/image-example-dark.png dark"
border="10px solid red"
/%}
Image with custom styles
{% img
alt="Styled image"
srcSet="./images/img-markdoc/image-example-light.png light, ./images/img-markdoc/image-example-dark.png dark"
style={"border": "10px solid red", "borderRadius": "50px", "cursor": "pointer"}
/%}
Image with srcSet
for different color modes
{% img
alt="Color mode aware image"
width=200
height=200
srcSet="./images/img-markdoc/image-example-light.png light, ./images/img-markdoc/image-example-dark.png dark"
/%}
Image with className
{% img
alt="Image with custom class"
srcSet="./images/img-markdoc/image-example-light.png light, ./images/img-markdoc/image-example-dark.png dark"
className="custom-image-class"
/%}
Best practices
Write meaningful alt text
Always include descriptive alt text that conveys the purpose and content of the image. Descriptive alt text improves accessibility and helps users understand the image's context when it fails to load or if users have visual impairments or use assistive technologies to understand the content of images.
Use images purposefully
Only include images that add value to your content. Avoid decorative images that don't contribute to understanding the subject matter.
Maintain responsive design
Set appropriate width and height attributes to prevent layout shifts and to prevent pixelation. Also, consider how images display across different screen sizes.
Enhance visual hierarchy
Use alignment to create visual flow and balance. Apply consistent styling (borders, shadows, etc.) across similar image types.