# Markdoc example tag

The `markdoc-example` tag enables you to display Markdoc syntax simultaneously with the rendered output, separated by introductory text that can be removed or customized.

## Syntax and usage

Use the `markdoc-example` tag to document how to use Markdoc tags in Markdown files.

```markdown
{% markdoc-example renderDemo=true %}
  ```markdown {% title="about.md" %}
  {% admonition type="warning" name="Important" %}
    This is an important message about this product.
  {% /admonition %}
  ```
{% /markdoc-example %}
```

### Display syntax that doesn't resolve in your project

The build validates the Markdoc tags in a `markdoc-example` code block, even when `renderDemo` is `false`.
If the code links to a file, image, or partial that doesn't exist in your project, or uses a tag that your project doesn't register, the build reports an error.

To display such syntax, add `{% process=false %}` to the code block, as in the following example:

```markdown
{% markdoc-example %}
  ```markdoc {% process=false %}
  {% partial file="/_partials/support-contacts.md" /%}
  ```
{% /markdoc-example %}
```

The build then doesn't validate the code.
Don't combine `process=false` with `renderDemo=true` for tags that the build resolves, such as `partial`, `code-snippet`, or `inline-svg`: their result renders empty.

Always add `{% process=false %}` to a code block that displays a `code-walkthrough` tag, and don't use `renderDemo=true` with this tag.
When the build processes a `code-walkthrough` tag, it renders the whole page in the code walkthrough layout, without the table of contents and the footer.

## Attributes

| Option | Type | Description |
| --- | --- | --- |
| renderDemo | boolean | Specifies if the introductory text, "Code:" and "Result:", and rendered output is included with Markdoc syntax. Default: `false` |
| withLabels | boolean | Specifies if the introductory text, "Code:" and "Result:", is included before the Markdoc syntax and rendered output. |
| codeLabel | string | Custom introductory text that displays before the Markdoc syntax. Default: "Code:" |
| resultLabel | string | Custom introductory text that displays before the rendered output. Default: "Result:" |

## Examples

### Markdoc example with custom text

```markdown
{% markdoc-example renderDemo=true codeLabel="Syntax:" resultLabel="Rendered example:" %}
  ```markdown {% title="about.md" %}
  {% admonition type="warning" name="Important" %}
    This is an important message about this product.
  {% /admonition %}
  ```
{% /markdoc-example %}
```

## Best practices

You might write your own Markdoc tags.
Then you need a good way to share the syntax, or no one will be able to use them.

**Contextual introduction**
Always include a brief explanation before the syntax example explaining the purpose and how any attributes you included may affect the output.
This information can help users to understand how to modify the example to fit their own needs.

**Avoid unnecessary complexity**
Keep your examples simple, with minor variations so users don't get too overwhelmed with the different ways to modify a Markdoc tag.

**Link to detailed reference documentation**
Include links to detailed reference documentation.
Users can then see all the options your examples do not include.

## Resources

- **[Markdoc overview for technical writers](https://redocly.com/learn/markdoc)** - Learn how to use Markdoc in your documentation
- **[Markdoc tags](/docs/platform/content/markdoc-tags)** - See the full list of supported Markdoc tags
