Images & Spacing When Published
Using these best practice for adding images will ensure the correct spacing when published. Learn more best practices for graphics and images here.
In DITA, images are typically not wrapped in a paragraph element for the following reasons:
- Semantic Ambiguity - DITA is designed for semantic structure where each element has a meaning and purpose. The p element in DITA is intended for blocks of text that form a coherent paragraph. Images, while often related to text, are distinct media types and have their own semantic meaning. Wrapping an image inside a paragraph can blur the distinction between an image that's part of the narrative flow (like an icon in a sentence) and a separate, illustrative figure. This can complicate automated processing, translation, and accessibility efforts.
- Layout and presentation control: DITA's strength lies in its ability to separate content from presentation. While the
placementattribute on the image tag allows for some control (inline or on a new line), wrapping images in paragraphs can make fine-tuning layout across different output formats more complex. Images within figures (using the<fig>element) offer more robust control over layout and placement. - Accessibility challenges: Images placed within paragraphs, especially if they are large or complex, can create accessibility issues for screen readers and other assistive technologies. While alternative text (
<alt>) is crucial for accessibility, placing images as standalone figures with descriptive captions provides a more structured and comprehensible experience for users with visual impairments. - Translation difficulties: When images are tightly coupled with the surrounding text within a paragraph, it can be harder for translators to separate and translate the text accurately without affecting the image or its placement.
- Consistency and best practices: DITA best practices encourage using the
<fig>element to encapsulate images that are meant to be standalone figures, including a title and a description. This promotes consistency across documentation and allows for easier management and reuse of images.
Wrap the Image in Figure Element
- It's efficient because the CSS manages the padding around the image without additional steps to add placement attributes.
- When you wrap the image in the figure element, the lightbox class is automatically added.
<fig>
<image "href="../images/darwin_library_of_congress.jpg">
<alt>Photo of Charles Darwin: Library of Congress, Prints and
Photographs Division, [reproduction number, LC-USZ61-104]</alt>
<image>
</fig>Aligning Images
align-left, align-right, align-center.Images in Steps
You can include images in or after the </cmd> element. To insert an inline image in a command, select the placement attribute, then break.
To place an image right after a step, insert the </info> element, then insert the </image> or a figure element. If not using the figure element, select the placement attribute, then break.
Images in Tasks
View examples for including inline images, images with breaks, and images wrapped in figures within task elements.