How to Add Images in Markdown: Local Files, URLs and GitHub
To add an image in Markdown, write an exclamation mark, the alt text in square brackets, and the image path or URL in parentheses:

The syntax is the easy part. Most problems come from the path: Markdown stores a reference to the image, not the image itself, so the path has to resolve from wherever the file is being read. This guide shows which path to write, how to set up a GitHub README, and how to fix an image that will not load.
For titles and reference-style images, see the full image syntax reference. You can also check any example below in a live preview.
Which path should I write?#
Relative paths are measured from the Markdown file itself, not from the repository root.
| Where is the image? | Write |
|---|---|
| Same folder as the Markdown file |  |
| In a subfolder next to it |  |
In a folder above (README is in docs/) |
 |
| Anywhere in the repo, from the repo root (GitHub) |  |
| On another website |  |
| In a GitHub repo, linked from outside it | Use the raw file URL (https://raw.githubusercontent.com/user/repo/main/images/logo.png), not the page URL |
On GitHub, a leading / means the repository root, and ./ and ../ work as in file paths. GitHub also rewrites relative paths for whichever branch you are viewing, so they keep working across branches.
Prefer file names without spaces, such as login-page.png. A space breaks the path unless you encode it as %20.
Adding images to a GitHub README#
1. Put images in a folder such as assets/ or images/, not in the repo root.
project/
├── README.md
└── assets/
├── logo.png
└── screenshot.png
2. Reference them with relative paths from the README:

3. Commit and push the image together with the README. A path that works on your computer will show a broken icon on GitHub if the file was never pushed.
GitHub recommends relative paths over absolute ones because they keep working when someone clones the repository. For what a README should contain, see the README.md file example.
When to use an absolute URL instead#
Relative paths are resolved by the site showing your README. If the same README is shown somewhere else, such as a package registry page or a documentation site, the relative path can break. In that case use the full raw URL of the image on GitHub.
No need to commit the image first#
In GitHub's web editor and in issue or pull request comments, you can drag an image in and GitHub inserts a hosted link for you. For long-lived docs, committing the file is safer, because a hosted link sits outside your repo's history.
In VS Code#
Hold Shift while you drag an image from the Explorer into a Markdown file, and VS Code inserts the path relative to that file. More editor tips are in the VS Code guide.
Resize an image#
Markdown has no size syntax. Use an HTML <img> tag with a width:
<img src="assets/screenshot.png" alt="App screenshot" width="400">
Set only width and the height scales with it. This works on GitHub. Other renderers may strip HTML, so if your Markdown must stay pure, resize the file itself before you add it.
Need to center it, or show a different image in dark mode? Those need more HTML tags and have their own steps in HTML in Markdown.
Add a caption#
Standard Markdown has no caption syntax. You have two options.
Plain Markdown (works everywhere): put the caption on the line below.

*Figure 1: Monthly sales dashboard*
HTML (only where the renderer allows it):
<figure>
<img src="assets/dashboard.png" alt="Sales dashboard with monthly report" width="500">
<figcaption>Figure 1: Monthly sales dashboard</figcaption>
</figure>
The title in  only appears as a hover tooltip. It is not a caption.
Make an image clickable#
Put the image syntax inside a link:
[](https://example.com/docs)
The inner part is the image and the outer part is the link. For link details, see Markdown Links.
Write useful alt text#
Alt text is read aloud by screen readers and shown when the image fails to load. Describe what the image shows, not what it is.
| Instead of | Write |
|---|---|
![Screenshot] |
![Login screen with email and password fields] |
![Image 1] |
![Network diagram: client, API gateway, database] |
Keep it short. For a purely decorative image, leave the brackets empty: .
Why your Markdown image isn't showing#
Check these in order. The syntax is rarely the problem.
| What you see | Cause | Fix |
|---|---|---|
| Broken icon and alt text | Path is wrong for where the Markdown file sits | Count the folders. A README in docs/ needs ../images/..., not images/.... |
| Works on your computer, broken on GitHub | Image was never committed or pushed | Commit and push the image file. |
| Works locally, breaks on Linux or GitHub | File name capitalization differs (Logo.png versus logo.png) |
Match the exact name. Many systems treat the two as different files. |
| The URL text shows up, or you get a "not found" page | You used the GitHub page URL (.../blob/...) for the image |
Use the raw file URL, or a relative path. |
| Image shows as a code block | The line is indented by 4 or more spaces | Remove the leading spaces. |
| Image works on GitHub, breaks on another site | Relative path resolved by a different site | Use an absolute raw URL there. |
| External image disappeared | The remote file was deleted, moved or made private | Host a copy in your repo. |
| Path has spaces | Space in the file name | Rename the file with hyphens, or use %20. |
| Still nothing | Extension does not match the real format | Check .png, .jpg, .gif, .svg or .webp against the actual file. |
Keep images light#
- Compress large screenshots before you commit them. Big files slow every clone and every page load.
- Use SVG for simple logos and icons where your platform supports it.
- For long demos, link to a video instead of embedding a large GIF.
Frequently asked questions
- 1
What path do I use when my README is inside a docs folder?
Paths are relative to the Markdown file, so go up a level first:
../images/logo.png. On GitHub you can also start with/to mean the repository root, for example/images/logo.png. - 2
How do I use an image from a GitHub repo as a link?
Do not use the normal file page URL, which opens a viewer page rather than the image. Use the raw file URL (
raw.githubusercontent.com/...) instead, or copy the image into your own repo and use a relative path. - 3
Why does my README image show on GitHub but not on another site?
Relative paths are resolved by whichever site renders your README, and some sites cannot resolve them back to your repository. Use an absolute raw URL when the README is published elsewhere.
- 4
Can I add an image to a GitHub README without committing a file?
Yes, by dragging it into a GitHub comment box or the web editor, which gives you a hosted link. Committing the file is safer for long-lived docs, because a hosted link is outside your repo's history.
- 5
How do I add a caption to a Markdown image?
Markdown has no caption syntax. Put italic text on the line below the image, or use an HTML
<figure>with<figcaption>where the renderer allows it. The image title only shows as a hover tooltip.
