A container element for technical content such as programming language code, pseudo-code, schemas, or a markup fragment.


The <code> element may contain preformatted text, containing emphasis elements for syntax coloring, or it may be contain an external link to a binary executable file.

Best Attribute Practice: The various semantic attributes should be used to name the type of code, the language, the intended platform(s), etc. Executable code should always be marked as such using the @executable attribute. The @specific-use attribute may also be used to describe the rationale or uses for a code sample.

Alternatives: When code is present in more than one form, the <code> element can be used inside an <alternatives> element. The various versions of the code can be syntax colored using the face markup from this Tag Set, syntax colored using processing instructions or other mechanisms from a syntax coloring program, plain ASCII for cut and paste, an executable version, et al.

MathML: The MathML elements to describe equations are not permitted within <code>. If equations are encountered within computer code, they can be tagged using the element <named-content> to preserve the fact that they were equations or the element <styled-content> to preserve the fact that they were set in a math font.


code-type Type of Code
code-version Code Version
executable Executable
id Document Internal Identifier
language Code Language
language-version Code Language Version
orientation Orientation
platforms Platforms
position Position
specific-use Specific Use
xml:base Base
xml:lang Language
xml:space Space

Related Elements

This element is similar to <preformat> in the preservation of whitespace, line-endings, and such formatting. The <code> element differs from <preformat> semantically; a <preformat> element may contain almost anything, for example, ASCII art, a man-machine dialogue, error messages, 3 words on a line with space between them, or a poem. The <code> element is specifically for technical coding fragments, for example: computer programming language code; executable binary code; illustrative pseudo-code; an XSD, RNG or DTD schema fragment; an SQL or XQuery query, or a markup fragment that is part of an XML document instance.

Historical Note: Previous versions of this Tag Set have used the <preformat> element with an attribute @preformat-type="code" to express the semantic material that will hereafter be tagged as <code>.

Expanded Content Model

(#PCDATA | email | ext-link | uri | bold | fixed-case | italic | monospace | overline | overline-start | overline-end | roman | sans-serif | sc | strike | underline | underline-start | underline-end | ruby | abbrev | milestone-end | milestone-start | named-content | styled-content | fn | target | xref | sub | sup)*


Any combination of:

This element may be contained in:

<abstract>, <ack>, <alternatives>, <app>, <app-group>, <bio>, <body>, <boxed-text>, <chem-struct>, <chem-struct-wrap>, <disp-formula>, <disp-quote>, <fig>, <floats-group>, <glossary>, <license-p>, <named-content>, <notes>, <p>, <ref-list>, <sec>, <styled-content>, <supplementary-material>, <table-wrap>, <td>, <term>, <th>, <trans-abstract>

Example 1

Part of an XML document:

<p>An example XML WorkOrder element is shown as follows:
   position="anchor" >
&lt;WorkOrder ID=”P7710”&gt;
  &lt;WorkItem name=”Testing”&gt;
    &lt;Datum xsi:type=”string” value=”A123”/&gt;

Example 2

Part of an XSD Schema:

<p>As of the release of this standard, the schema described 
incorporates the following “header” information:
  position="anchor" >
  &lt;xs:import namespace="urn:IEEE-1671:2008.01:Common"