How do I display local image in markdown?
Categories:
Displaying Local Images in Markdown: A Comprehensive Guide

Learn how to effectively embed local images in your Markdown documents for various platforms and use cases, ensuring proper rendering and portability.
Markdown is a lightweight markup language that allows for simple formatting of plain text. While it excels at text, embedding images, especially local ones, can sometimes be a point of confusion. This guide will walk you through the standard Markdown syntax for local images, discuss common pitfalls, and provide solutions for different environments like GitHub, local viewers, and static site generators. Understanding how relative paths work is crucial for successful image display.
Standard Markdown Syntax for Local Images
The basic Markdown syntax for embedding an image is 
. The alt text
is important for accessibility and is displayed if the image cannot be loaded. The path/to/image.jpg
is the crucial part for local images, as it specifies the location of the image file relative to your Markdown document.


Basic Markdown syntax for embedding local images using relative paths.
C:/Users/Me/Documents/image.png
or /home/user/image.png
) will break when the document is moved or viewed on a different system.Understanding Relative Paths
Relative paths describe the location of a file or directory in relation to the current document. This is fundamental for local image embedding. There are two main types of relative paths you'll use:
- Paths within the same directory or subdirectories: If your image is in a subdirectory, you simply specify the subdirectory name followed by the image filename.
- Paths to parent directories: If your image is in a directory above your current Markdown file, you use
../
to move up one directory level. You can chain../
to go up multiple levels (e.g.,../../images/image.png
).
graph TD A[Markdown File (document.md)] B[Images Folder (images/)] C[Assets Folder (assets/)] D[Parent Folder (../)] E[Image 1 (images/pic1.jpg)] F[Image 2 (assets/logo.png)] G[Image 3 (../shared/icon.svg)] A --> B A --> C A --> D B --> E C --> F D --> G subgraph Relative Paths from document.md A -- "images/pic1.jpg" --> E A -- "assets/logo.png" --> F A -- "../shared/icon.svg" --> G end
Visual representation of relative paths from a Markdown file to local images.
Common Scenarios and Best Practices
Different Markdown renderers and platforms might handle local images slightly differently. Here are some common scenarios and best practices to ensure your images display correctly.
1. Local Markdown Viewers
Most local Markdown viewers (like VS Code's Markdown preview, Typora, Obsidian) will correctly render local images as long as the relative paths are accurate and the image files exist on your system.
2. GitHub and GitLab
When pushing Markdown files with local images to GitHub or GitLab, the images will only display if they are also pushed to the repository and the relative paths are correct within the repository structure. It's common practice to create an images
or assets
folder at the root of your repository for this purpose.
3. Static Site Generators (e.g., Jekyll, Hugo, Next.js)
Static site generators often have specific configurations for handling assets like images. They typically copy these assets to the final build directory. You'll still use relative paths in your Markdown, but the generator's build process ensures they are correctly linked in the generated HTML. Consult your generator's documentation for specific asset handling rules.
4. HTML <img>
Tag
For more control or in cases where standard Markdown syntax isn't sufficient, you can embed images using raw HTML <img>
tags directly within your Markdown. This allows for attributes like width
, height
, class
, and id
.
<img src="images/my-image.png" alt="Descriptive Alt Text" width="200" height="150" />
Using an HTML <img>
tag for more control over image attributes.
<img>
tags offer more control, they reduce the portability and simplicity that Markdown aims for. Use them sparingly and only when necessary.Troubleshooting Common Issues
If your local images aren't displaying, consider these common issues:
- Incorrect Path: Double-check your relative path. Is the filename spelled correctly? Is the directory structure accurate? Remember that paths are case-sensitive on some operating systems (e.g., Linux).
- Missing Image File: Ensure the image file actually exists at the specified path.
- Permissions: Verify that the Markdown viewer or web server has permission to read the image file.
- Renderer Limitations: Some minimalist Markdown renderers might not support local images or specific path conventions. If possible, test with a different viewer.
- Caching: In web contexts, browser caching can sometimes prevent updated images from showing. Try clearing your browser cache or using a hard refresh.