What is the @class attribute in DITA XML?

The @class attribute in DITA XML is a valuable tool for classifying and categorizing elements within your content. It enables you to assign specific attributes to elements, making it easier to control their appearance and behavior when rendering or processing DITA documents. This attribute is highly flexible, allowing you to define your own custom values based on your document’s requirements. Here’s a detailed look at how the @class attribute works in DITA XML.

Assigning Classes

You can assign the @class attribute to various DITA elements, such as <p>, <step>, or <table>, among others. By assigning classes to these elements, you can categorize content in a way that makes sense for your documentation. For example, you might assign a class like “important” to a specific paragraph or a class like “warning” to a step element to indicate its significance or purpose.

Defining Styles

Once you’ve assigned classes, you can define how elements with these classes should be styled or processed. This can be done through CSS (Cascading Style Sheets) or custom processing instructions. For instance, you can use CSS to apply different fonts, colors, or formatting to paragraphs with a particular class. This provides a way to achieve consistency and visual clarity in your documents.


Here’s an example of how the @class attribute can be used to categorize and style elements:

<p class="important">This is an important note.</p>
<step class="warning">Caution: Handle with care.</step>

In this example, two elements, a paragraph and a step, have been assigned classes. These classes, “important” and “warning,” can be defined in your CSS to apply specific styling to these elements, ensuring they stand out as intended.