Markdown Image Syntax: READMEs and Docs
The Markdown image syntax with copy-ready examples, from alt text to sizing and GitHub README images, plus how to host the image file.
By Mudasir Ahsan (Founder) · · Updated · 7 min read
Facts checked against official sources on
On this page
A Markdown image is an exclamation mark, the alt text in square brackets and the image's address in round brackets: . The address can be a full URL or, inside a repository, a relative path to the file. Size is the one thing the syntax can't set. For that you fall back to an HTML img tag, on platforms that allow it.
The syntax
An image is written like a link with a ! in front.

That likeness is deliberate. The CommonMark specification, which most modern Markdown tools follow, says image syntax is like link syntax except that the description starts with 

Line one uses an absolute URL, which works anywhere as long as the image is publicly reachable. Line two uses a relative path. It only works where the image file travels with the Markdown file, as it does inside one repository.
Reference-style images
A long URL, or an image you use several times, can be defined once at the bottom of the file.
![Build status][status]
[status]: https://example.com/badges/build.svg
The spec's examples show that ![foo][bar], ![foo][] and ![foo] all work when a matching reference is defined.
Alt text and titles
Whatever sits in the square brackets becomes the image's alt text. Screen readers read it aloud, and it appears if the image fails to load. GitHub's documentation calls alt text "a short text equivalent of the information in the image". Write what the picture tells the reader, then. Naming the kind of file tells them nothing.
| Image | Weak alt text | Better alt text |
|---|---|---|
| Screenshot of a settings page | screenshot | Settings page with the API key field highlighted |
| Architecture diagram | diagram | Diagram: browser sends uploads to the API, which stores files in object storage |
| Logo at the top of a README | logo.png | Acme CLI logo |
A purely decorative image can have empty alt text (). In documentation most images carry information, so describe them.
PictureToLink's "Markdown" copy format gives you  with the brackets empty, because only you know what the image shows. Type your description between the square brackets before you publish.
Titles are a separate thing, and people mix the two up. A title goes in quotes after the address, and browsers usually show it as a tooltip on hover.

CommonMark renders that as an img element with both alt and title attributes. The title is optional and never replaces alt text. Nobody on a touch screen or a screen reader ever sees the tooltip.
Making the image clickable
Put the whole image code inside the square brackets of a normal link. The image becomes the link text, so a click opens the destination. Most README badges work this way.
[](https://example.com/demo)
Read it from the inside out.  is the image, and the outer [...](https://example.com/demo) turns it into a link.
Outside Markdown the same trick takes different markup. Our guide to making a picture a clickable link covers each case, from HTML to email to documents.
How do I resize an image in Markdown?
You can't, in Markdown itself. CommonMark has no syntax for width or height. Some tools add their own extensions, but those don't carry over to other tools. What works reliably is an HTML img tag with a width attribute, on platforms that allow HTML inside Markdown.
<img src="docs/images/screenshot.png" alt="Dashboard showing three charts" width="600">
Set only the width. Height then scales by itself and the image keeps its proportions.
On GitHub, size the image with attributes and leave CSS out. GitHub sanitizes HTML in Markdown. A port of its sanitizer rules, marked-sanitizer-github, lists width and height as allowed attributes. style isn't on the list, so inline CSS sizes are stripped.
Neither attribute makes the page any lighter, and that's the common mistake. width="600" changes how large the image is drawn. Every reader still downloads the whole file, so a 4000-pixel screenshot displayed at 600 pixels wide costs as much as one shown at full size. Resize the file itself before you upload it. The image resizer does that in your browser.
Compression counts as much as pixel size. When we ran our test files through PictureToLink's upload pipeline, a 1366 × 900 PNG screenshot went from 2.38 MB to 730 KB with the format left as PNG (69.3% smaller). Saved as WebP, the same screenshot came to 108 KB.
Our guide to embedding an image in HTML has more on the img tag, including alt text and responsive sizing.
Images in a GitHub README
GitHub supports images in README files, other .md files, issues, pull requests, discussions and comments. Its basic writing and formatting guide says you can display an image from your repository, link to an online image, or upload one.
Images stored in the repository
GitHub recommends relative links here, and its docs give these examples.
| Where the Markdown is | Relative path example from GitHub's docs |
|---|---|
A .md file on the same branch | /assets/images/electrocat.png |
A .md file on another branch | /../main/assets/images/electrocat.png |
| Issues, pull requests and comments in the same repository | ../blob/main/assets/images/electrocat.png?raw=true |
GitHub explains that it transforms relative paths based on the branch you are viewing, and that paths starting with / are relative to the repository root. Relative paths also keep working when someone clones the repository.
A typical README setup looks like this.
my-project/
README.md
docs/
images/
screenshot.png

Uploading to issues and comments
In an issue, pull request or comment, you can drag and drop an image into the comment box, click to browse for a file, or paste an image in many browsers. GitHub's page on attaching files lists a 10 MB maximum for images and GIFs, and supported image types including PNG, GIF, JPEG and SVG.
One line on that page is easy to miss. In public repositories, uploaded files can be accessed without signing in. Don't attach a screenshot that shows something private.
Dark and light themes
GitHub's formatting guide states that the HTML picture element is supported. That's how you show a different image to readers using dark mode.
External images on GitHub
An image hosted elsewhere isn't loaded straight from its host. GitHub serves it through an anonymizing proxy called Camo, so it's GitHub's server that has to fetch your file, and the reader's browser only ever talks to GitHub.
That explains the two failures GitHub's page on anonymized URLs calls most common. Either the server returns a Content-Type that Camo doesn't support, or the image is on a private network or behind a login. An image that opens fine in your own browser can still be out of Camo's reach. If you updated an image and GitHub still shows the old one, the same page explains how caching headers affect it.
Where to host the image
For a project's permanent documentation, keep the images in the repository. That's the durable choice for READMEs and project docs, because the pictures live and move with the text. It has a cost. Large images make the repository bigger for everyone who clones it.
Uploading to an issue or comment suits bug reports and discussions. Remember that files in public repositories are publicly accessible.
An external image host fits Markdown that lives outside GitHub: docs sites, wikis, forums. It's faster for a quick picture in a forum post or chat. The weakness is that your image depends on the host staying online.
With an external host you need the direct link to the image file, the one ending in .png or .jpg. A link to a page that shows the image renders as a broken image, because the img element receives a web page where it expected a picture. Our explainer on direct links, viewer links and embed codes shows the difference.
Reddit is one place outside GitHub where this matters. Its text formatting is based on Markdown, and an image link that points to a page shows there as a link, not a picture. Our guide to posting images on Reddit covers uploading and linking.
On PictureToLink you paste or drop an image and copy the ready-made Markdown line, then add your alt text between the square brackets. Know its limits before you rely on it. We accept JPG, PNG, WebP, GIF and AVIF up to 25 MB. There is no SVG, and iPhone HEIC photos are converted to JPG in your browser first. Images are compressed and stripped of metadata. An image is removed after 12 months without views, so we're a poor fit for documentation that may sit unopened for a year.

Copy the direct link and drop it inside the brackets of your Markdown image.
Whichever you pick, preview the file before you commit.
