---
title: "Element <preformat>"
source: https://dev.pageseeder.com/psml/elements/element-preformat.html
description: "PSML Element reference for <preformat>"
last_updated: 2026-08-07T17:09:54+10:00
tokens: ~542
---

# \<preformat\>

## Summary

Used for blocks of computer source code typically with a monospaced font.

> **Note:** This element replaces PS Standard’s block level `<code>` element to avoid confusion with HTML inline `<code>` elements.

## Usage context

| Element category | block |
| --- | --- |
| PSML level | portable |
| Permitted content | text only\* |
| Permitted parent | `<fragment> <item> <block> <cell>` |
| HTML equivalent | `<pre``>` |
| OpenXML equivalent |  |

> **Note:** \* This element can also contain character-style elements, however, if the content is edited in CK, extra line-breaks are often inserted before these elements. So it is safer to avoid them.

## Attributes

This element includes the following attributes:

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| role | [role](../datatypes/pageseeder_datatypes.md) | no | Custom value that can be used for formatting |

### `@role`

A role for the preformatted text which can be used for formatting.

## Examples

###  Plain text

Preformatted plain text to preserve whitespace.

```lang-xml

<preformat>            Yet do I fear thy nature;
It is too full o' the milk of human kindness
To catch the nearest way.</preformat>
```

### Code sample 

A preformatted code sample.

```lang-xml

<preformat role="lang-javascript">function () {
  return "Hello!";
}</preformat>
```

It is good practice to specify the language of code samples. Use the role attribute to specify the language. A common convention adopted by syntax highlighter is to prefix the language name by `lang-` or `language-`. In the preceding example, we've used `lang-javascript`.

## Schema

### XML Schema

```lang-xml

<xs:element name="preformat">
  <xs:complexType mixed="true">
    <xs:group ref="character-style-group"
              minOccurs="0" 
              maxOccurs="unbounded" />
    <xs:attribute name="role" type="role"/>
  </xs:complexType>
</xs:element>
```

### Relax Schema

```lang-relax

element preformat {
  attribute role { role }?,
  character-style
}
```

## Compatibility

This element was introduced in the first draft of PSML and is well-supported from PageSeeder 5.1.

