Markdown Cheatsheet

Links and Images

Use this Markdown reference while you build software engineering projects, review code, or refresh the syntax you reach for most.

Getting Started -> #getting-started

API: v2 notes -> #api-v2-notes

What's new? -> #whats-new

markdown jump jump to a duplicate heading jump in another file

Because slugging is not standardized, an anchor that works on GitHub can 404 in a static-site generator that slugs differently. Verify anchors after changing renderers.

Images

An image is a link with a leading !. The bracketed text is the alt text, not a caption.

![alt text](./diagram.png)
![alt text](./diagram.png "Optional title")
![](./decorative.png)
![alt text][img-ref]

[img-ref]: https://example.com/diagram.png
  • Alt text is for screen readers and for when the image fails to load. Describe the content, do not write "image of".
  • An empty alt is correct for a purely decorative image.
  • Markdown has no caption syntax. A caption is either a paragraph below the image or raw HTML <figure>.
  • Markdown has no width, height, or alignment syntax either.

A linked image nests an image inside a link, and the order matters: the image goes inside the square brackets.

[![build status](./badge.svg)](https://ci.example.com/build)
[![alt](./thumb.png)](./full-size.png)

That pattern is what every README badge is.

Sizing and Alignment on GitHub

Since Markdown itself has no sizing syntax, GitHub supports two extensions.

![alt](./diagram.png#gh-dark-mode-only)
![alt](./diagram-light.png#gh-light-mode-only)

For dimensions, GitHub allows a raw <img> tag with width and height, and accepts pixels or a percentage.

<img src="./diagram.png" alt="architecture" width="400">
<img src="./logo.png" alt="logo" width="50%">
<p align="center">
  <img src="./hero.png" alt="hero" width="600">
</p>

Neither is portable. The #gh-*-mode-only fragment is GitHub-specific, and the <img> tag depends on the renderer permitting raw HTML, which many sanitizers and CommonMark-only pipelines do not. For a doc that must render everywhere, ship a correctly sized image instead.

Safe Hrefs and Escaping

Renderers sanitize link destinations, and most strip javascript:, data:, and vbscript: schemes, rendering the link as plain text instead.

[blocked by most renderers](javascript:alert(1))

To write literal brackets, escape them.

\[not a link\]
\!\[not an image\]
This is a literal \[bracketed\] word.

And to show link syntax without it being a link, use a code span.

The syntax is `[text](url)`.