# Show triple backticks inside a Markdown code example

Canonical: https://githtml.com/guides/markdown-code-fence-inside-code-fence
Published: 2026-11-23
Publisher: WaveTech LLC / gitHtml

Wrap a Markdown example containing triple backticks in a longer outer fence, such as four backticks. The surrounding fence must not be accidentally closed by the text you are demonstrating. Label the outer example as Markdown when supported, then verify that copying the rendered sample preserves the inner fence characters.

## Recognize a delimiter collision

A guide about Markdown often needs to display the syntax that normally starts a code block. When author and example use identical fences, the parser can treat part of the lesson as document structure. The visible symptom may be a missing opening line, prose rendered as code, or unexpected highlighting far below the example. Inspect the opening and closing delimiters before changing CSS or escaping every character. The problem belongs to the source structure. Count the longest uninterrupted run of fence characters inside the sample and choose an outer delimiter long enough to remain distinguishable.

## Keep the demonstration honest and copyable

Use four backticks around a sample containing ordinary triple backticks, as shown below. An alternative is a tilde fence around a backtick example when the target parser supports it. Avoid replacing the real characters with typographic lookalikes or inserting invisible separators to make the page appear correct. Those tricks cause readers to paste broken source. Include the language label exactly where it belongs in the inner sample. If your lesson compares two examples, keep each one complete rather than sharing a closing fence between them. A learner should be able to copy one block independently.

`````markdown
````markdown
```json
{"mode":"preview"}
```
````
`````

## Verify boundaries after the example

Render the complete page and inspect the paragraph immediately before and after the demonstration. Both should remain ordinary prose. Copy the displayed sample into a separate scratch file and render that file too; this checks whether the guide teaches a working construct rather than merely displaying something plausible. Do not assume syntax coloring proves correctness, since a highlighter may color an incomplete block. If a publishing tool adds another wrapping layer, inspect its exported output as well. Preserve the longer-fence convention in the authoring style note for tutorials that routinely document Markdown itself. If an example contains four backticks itself, increase the outer delimiter again. The rule depends on the actual contents, not on a universal choice of four characters for every tutorial.

1. Count the longest inner backtick run and choose a strictly longer outer fence.
2. Copy only the rendered inner example into a new Markdown file and preview it.
3. Confirm that surrounding paragraphs and the next heading do not become part of the code block.

## Sources and further reading

- [GitHub Docs: Creating and highlighting code blocks](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks)

## Related guides

- [Use Markdown comments for author notes, never for secrets](https://githtml.com/guides/markdown-comments-not-secrets)
- [Choose CommonMark or GitHub-flavored Markdown deliberately](https://githtml.com/guides/markdown-commonmark-gfm-dialect-choice)
- [Prevent duplicate Markdown headings from breaking shared links](https://githtml.com/guides/markdown-duplicate-heading-links)
- [Keep underscores in Markdown identifiers from becoming emphasis](https://githtml.com/guides/markdown-emphasis-underscores-identifiers)

Editorial approach: https://githtml.com/guides/about
