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

# \<media-fragment\>

## Summary

The `<media-fragment>` element is used to include non-[PSML](../../reference/glossary/psml.md) content such as [MathML](../../reference/glossary/mathml.md), SVG or plain text.

Other fragment elements are the following:

- `<fragment>`
- `<properties-fragment>`
- `<xref-fragment>`

## Usage context

| Element category | structure |
| --- | --- |
| PSML level | portable |
| Permitted content | any |
| Permitted parent | `<section>` |
| HTML equivalent | no equivalent but similar to `CDATA` sections |
| OpenXML equivalent |  |

## Attributes

This element includes the following attributes:

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| id | [fragment-id](../datatypes/pageseeder_datatypes.md) | yes | The fragment ID |
| mediatype | [xs:string](../datatypes/xml_schema_datatypes.md) | yes | A [media type](../../reference/glossary/media_type.md) |
| type | [fragment-type](../datatypes/pageseeder_datatypes.md) | no | A template type |
| labels | [label-list](../datatypes/pageseeder_datatypes.md) | no | A list of fragment labels |

### `@id`

A fragment identifier that is unique within the [document](../../reference/glossary/document.md).

### `@mediatype`

The media type (MIME) of the content within the media fragment. 

It must not include character encoding (charset) as the encoding is defined at the PSML document level.

Media types referring to binary documents are acceptable, provided that they use an encoding that is compatible with the character encoding used at the PSML document level. In general, it is best to use base64.

### `@type`

If this fragment has a type or was created using a [document-template](../../guide/configuration/psml/psml_document_template.md).

## Examples

### Example 1: Plain text fragment

```lang-xml
<media-fragment id="1" mediatype="text/plain">
  Here is some plain text content
</media-fragment>
```

### Example 2: MathML fragment

Media fragments can be used to include [MathML](http://www.w3.org/TR/MathML) in PSML document.

```lang-xml
<media-fragment id="1" mediatype="application/mathml+xml">
  <mrow>
    <mfrac>
      <mrow>
        <mi>x</mi>
        <mo>+</mo>
        <msup>
          <mi>y</mi>
          <mn>2</mn>
        </msup>
      </mrow>
      <mrow>
        <mi>k</mi>
        <mo>+</mo>
        <mn>1</mn>
      </mrow>
    </mfrac>
  </mrow>
</media-fragment>
```

> **Note:** PSML does not recognise [MathML named entities](http://www.w3.org/TR/MathML2/chapter6.html), for example, `&InvisibleTimes;`, the corresponding numeric character entity must be used instead. Beware also, that some mathematical symbols do not belong to Basic Multilingual Plane (BMP). Ensure that PageSeeder is suitably configured to support Unicode characters outside the BMP. 

### Example 3: SVG

Media fragments can also be used to include [SVG](http://www.w3.org/Graphics/SVG) inside PSML.

```lang-xml
<media-fragment id="1" mediatype="image/svg+xml">
  <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
 
    <rect x="50" y="50" width="200" height="200" fill="lime" />
    <circle cx="125" cy="125" r="75" fill="orange" /> 
    <line x1="50"
          y1="50"
          x2="200"
          y2="200"
          stroke="blue"
          stroke-width="4"/>
  </svg>
</media-fragment>
```

## Schema

### XML Schema

```lang-xml

<xs:element name="media-fragment">
  <xs:complexType mixed="true">

    <xs:sequence>
      <xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>

    <xs:attribute name="id" type="fragment-id" use="required"/>
    <xs:attribute name="type" type="fragment-type"/>
    <xs:attribute name="mediatype" type="xs:string"/>
    <xs:attribute name="labels" type="label-list"/>
  </xs:complexType>
</xs:element>
```

### Relax Schema

```lang-relax

element media-fragment {
  attribute id { fragment-id } ,
  attribute type { fragment-type }?,
  attribute mediatype { text }?,
  attribute labels { label-list }?, 
  any
}
```

## Compatibility

This element was introduced in PSML Beta 4 as a replacement for the now defunct `<ext-fragment>` element.

It is supported from PageSeeder 5.3.

> **Warning:** Although it is possible to define media fragments with any media type, beware that using undocumented media type might cause your document to display incorrectly or to be handled incorrectly during publishing. Media types which are known to work are the following: - `text/plain` - `application/mathml+xml` - `image/svg+xml` - `application/xml`

