Agent Ready HTML

Mark code samples with a language class and a fenced block

In short

In HTML, a block sample is a pre element holding a code element, with a class such as language-python on the code element. The markdown twin should hold the same sample as a fenced code block whose info string starts with the language word. An indented code block has no info string to carry the language.

Published 22 November 2026

Start each block sample in the HTML page with a pre element and put a code element inside it. The HTML Standard defines pre as a block of preformatted text and states that pre can be used with a code element to represent a block of computer code (HTML Standard on pre). On its own, code only represents a single phrase of code or line of code, and MDN tells you to wrap it in pre to represent multiple lines (MDN on code).

Name the language with a class on code

The code element represents a fragment of computer code, and the standard says there is no formal way to indicate the language of the code being marked up. Authors who want to mark the language can use the class attribute, for example a class prefixed with "language-", and the standard's own block example is <pre><code class="language-pascal"> (HTML Standard on code).

Syntax highlighters read that class. Prism's home page calls a pre element with a code element inside the recommended way to mark up a code block, both for semantics and for Prism, and gives this markup (Prism):

<pre><code class="language-css">p { color: red }</code></pre>

Prism also accepts the shorter lang-xxxx form. Its documentation adds that Prism only works with code elements, and that with this pattern the pre element automatically gets the language-xxxx class if it does not already have it.

Keep the first line and the characters intact

In the HTML syntax, a leading newline character immediately following the pre start tag is stripped (HTML Standard on pre). MDN describes the same exception: when one or more newlines follow the opening tag, the HTML parser strips the first one, and the rule does not apply to XHTML (MDN on pre).

The text inside pre is parsed as HTML, and characters such as < may need to be escaped with character references. MDN's rule of thumb: write the content as it should appear, replace every & with its character reference first, then replace every < with its character reference. Prism gives the same warning for code elements: escape all < and & characters, or else the browser might interpret them as an HTML tag or entity.

Describe diagrams drawn with characters

The standard encourages authors to consider how preformatted text will be experienced when the formatting is lost, as for users of speech synthesizers and braille displays. For ASCII art, it says an alternative presentation such as a textual description is likely to be more universally accessible.

MDN asks for an alternate description of any image or diagram made from preformatted text. Wrap the pre in figure with a figcaption, and add a role and an aria-label to the pre element; per MDN, that combination lets the ASCII art be announced as an image with alternative text, with the figcaption as its caption. MDN's example sets role="img" and aria-label="ASCII COW" on the pre.

Carry the language into the markdown twin

The llms.txt proposal asks that pages with information agents might need provide a clean markdown version at the same URL as the original page, with .md appended or with the extension replaced by .md (llms.txt proposal).

Related: How to serve markdown on request on each host

Inside that twin, write each sample as a fenced code block. In CommonMark, the text after the opening fence, trimmed of leading and trailing spaces or tabs, is the info string. Its first word is typically used to specify the language and rendered in the class attribute of the code tag, but the spec does not mandate any particular treatment of the info string (CommonMark 0.31.2). In HTML output the language is normally indicated by a class on the code element made of language- followed by the language name. The spec's example turns a fence whose info string is ruby into <pre><code class="language-ruby">.

An indented code block, made of lines preceded by four or more spaces of indentation, has no info string, so it has nowhere to put a language. After a backtick fence, the info string may not contain backtick characters. The GitHub Flavored Markdown spec also trims the info string of leading and trailing whitespace and bars backtick characters in it after a backtick fence (GFM spec).

Related: Fenced code block (glossary)

Set the converter to fenced blocks

Turndown, an HTML to Markdown converter written in JavaScript, has a codeBlockStyle option whose valid values are indented or fenced, and the default is indented (Turndown README). Options are passed to the constructor on instantiation, for example new TurndownService({ codeBlockStyle: 'fenced' }).

Turndown escapes Markdown characters with backslashes, and the README notes that text in code elements is never passed to escape. If another tool writes your twins, check its equivalent setting before you publish.

Put extra metadata after the language word

Mintlify says you must specify a programming language for a code block before adding any other meta options, and options such as a title or an icon go after the language (Mintlify's code page).

Extra words do not change the language class in CommonMark: the spec's fence ~~~~ ruby startline=3 $%@#$ still renders class="language-ruby". Keep the language as the first word and put every other option after it.

Code groups shown as tabs

Mintlify displays several code blocks together as a set of tabs when you wrap them in its CodeGroup component, and each code block's title becomes its tab label. Inside a CodeGroup, the visibility of the copy button can be set for each tab. Give each block in a group its own language word and its own title.

Related: Tabs and accordions: what an agent reads

Compare one sample in both versions

Fetch the HTML page and its markdown twin, pick one sample, and compare it character by character. In the HTML, confirm that the code element carries the language- class and that the sample's first line is present after the pre start tag, where the parser strips a leading newline. In the twin, confirm that the sample sits in a fenced block rather than an indented one and that the first word of its info string names the same language as the class.

Sources

  1. WHATWG: HTML Standard: Text-level semantics (the code element) https://html.spec.whatwg.org/multipage/text-level-semantics.html, read 22 November 2026
  2. WHATWG: HTML Standard: Grouping content (the pre element) https://html.spec.whatwg.org/multipage/grouping-content.html, read 22 November 2026
  3. MDN: <pre>: The Preformatted Text element https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/pre, read 22 November 2026
  4. MDN: <code>: The Inline Code element https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/code, read 22 November 2026
  5. Prism https://prismjs.com/, read 22 November 2026
  6. CommonMark Spec 0.31.2 https://spec.commonmark.org/0.31.2/, read 22 November 2026
  7. GitHub Flavored Markdown Spec https://github.github.com/gfm/, read 22 November 2026
  8. mixmark-io (Turndown): Turndown README https://github.com/mixmark-io/turndown, read 22 November 2026
  9. Docusaurus: Code blocks https://docusaurus.io/docs/markdown-features/code-blocks, read 22 November 2026
  10. Mintlify: Format code https://www.mintlify.com/docs/create/code, read 22 November 2026
  11. llmstxt.org: The /llms.txt file https://llmstxt.org/, read 22 November 2026

Last reviewed 22 November 2026