• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Learning DITA

Free DITA training

Free DITA training

  • Log in
  • Register
  • Newsletter
  • Profile
  • Privacy
  • Home
  • About
  • Courses
  • News
  • Resources
  • Support the site
  • Contact
  • Recordings

Adding inline styling

Posted on 08.30.15

Adding inline styling
Lesson Progress
0% Complete

DITA uses several elements for inline styling, or styling of pieces of text inside a paragraph:

<b>

bold text

<i>

italic text

<u>

underlined text

<term>

a word or phrase that needs a definition

<cite>

a word or phrase that needs a citation

<varname>

a word or phrase that may change based on the user’s circumstances

<sub>

subscript text

<sup>

superscript text

The inline elements <b>, <i>, and <u> are familiar and easy to use. However, because they are closely linked with the appearance of text, it is easy to misuse them and defeat the purpose of separating content from formatting. Use these elements sparingly; in most cases, it is better to use more meaningful elements instead, such as the <term>, <cite>, or <varname> elements.

In the following examples, you will learn how to insert the simple <b>, <i>, and <u> elements first, then how to replace them with the semantically rich alternatives.

Practice
  1. Make a copy of the file lesson3/l_concept_elements_start.dita and open it in your editor.

    Note:

    If you are using a DITA-aware text editor, make sure you are in text mode, rather than author or visual mode.

    You should see this:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    <concept id="concept_elements">
    <conbody>
    </conbody>
    </concept>

  2. Add a <p> element containing <b>, <i>, and <u> elements as shown in the following example:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    <concept id="concept_elements">
    <conbody>
    <p>Ducklings need <b>round-the-clock access</b> to both <i>food</i> and <i>water</i> 
    during the first <u>two weeks</u> of their lives.</p>

    </conbody>
    </concept>
    By adding the <b> element to this paragraph, you have indicated that the words “round-the-clock access” should be rendered in boldface. Similarly, by adding the <i> element, you have indicated that the words “food” and “water” should be rendered in italic, and by adding the <u> element, you have indicated that the words “two weeks” should be rendered with an underline.
    Although these inline elements add emphasis to important words, they have no other semantic value. Suppose you wanted to define the words “round-the-clock access” later, or to style them the same way as other words describing feeding frequency. Rather than using the <b> element to tag the words simply as bold, you could use the <term> element to tag them as an important term.
    There are similar, more semantically rich alternatives for the <i> and <u> elements, as you will see in the next step.
  3. After the <p> element, add another <p> element containing the same text as the previous paragraph, with the <b> element changed to <term>, the <i> element changed to <cite>, and the <u> element changed to <varname>, as shown in the following example:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    <concept id="concept_elements">
    <conbody>
    ...
    <p>Ducklings need <term>round-the-clock access</term> to both <cite>food</cite> and 
    <cite>water</cite> during the first <varname>two weeks</varname> of their lives.</p>

    </conbody>
    </concept>
    In this example, you have tagged “round-the-clock access” with the <term> element to show that it is a term that should be defined later. You have tagged “food” and “water” with the <cite> element to show that they are words that could be given bibliographic citations should you need them. Finally, you have tagged “two weeks” with the <varname> element to show that it may need to be substituted with other information based on the user’s circumstances (for example, certain breeds of ducks may need round-the-clock access to food and water longer than two weeks).
  4. After the last <p> element, add another <p> element containing a <sub> element as shown in the following example:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    <concept id="concept_elements">
    <conbody>
    ...
    <p>Because duck feed has a dry, gritty texture, ducklings need plenty of 
    H<sub>2</sub>O to keep their bills clean.</p>

    </conbody>
    </concept>
    The <sub> element is used to tag subscript text, or text that appears smaller and slightly below the main line. In the example you added, the <sub> element is used to ensure that the “2” in H2O is displayed as subscript.
  5. After the last <p> element, add another <p> element containing a <sup> element as shown in the following example:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    <concept id="concept_elements">
    <conbody>
    ...
    <p>You can make your own low, no-spill food and water dishes out of recycled 
    plastic containers, or buy ready-made dishes from E-Z-Feed<sup>2</sup>.</p>

    </conbody>
    </concept>
    The <sup> element is used to tag superscript text, or text that appears smaller and slightly above the main line. In the example you added, the <sup> element is used to indicate that the “2” (symbol for “squared”) in the name of the duck food company (“E-Z-Feed2”) should be displayed as superscript.

    Note: Do not use <sup> elements to create raised numbers for footnotes. Instead, use the DITA <fn> (footnote) element, which we will cover later in this lesson.

Contributors
  • Gretyl Kinsey, Scriptorium
Back to

sidebar

Blog Sidebar

  • Scriptorium logo
    Maximize the value of your content. Read more.
  • Scriptorium logo
    Need DITA help? We offer flat-rate consulting. Get help.
  • Scriptorium logo
    Already in DITA and need support? Contact us.
RSSTwitter

Want to add content? Join the ditatraining GitHub repository.

  • Home
  • Sponsor
  • News
  • Contact
  • Privacy

Maintained by Scriptorium Publishing

Logo and site presentation © 2015-2021 Scriptorium Publishing. Content based on the open-source DITA training project.