How to add images in Markdown files
Summary
This guide explains how to embed images in Markdown files, covering paths, alt text, title text, sizing (height and width), and HTML fallback option. Learn best practices for including images in Markdown documentation and Git repositories.
Introduction #
Adding images in Markdown is simple. This guide explains how to add images with various attributes, manage image files, and use Hypertext Markup Language (HTML) as a fallback for advanced control.
Basic image syntax in Markdown #
To insert an image in Markdown, use the following syntax:

![Alt text]defines the alternative text for the image.(path/to/image.jpg)specifies the path to the image file.
The image path can be relative or absolute, depending on where your image is stored in relation to your Markdown file.
Adding alt attribute information #
The alternative text, or alt attribute, improves accessibility and searchability. As you can see in the previous section, the alt attribute is written directly inside the square brackets in the Markdown image syntax:

This text is shown when the image fails to load or is read by screen readers.
Best practices for alt text #
Use an empty alt attribute for decorative images like backgrounds. For informative images, describe the image.
<!-- Empty alt for decorative images -->

<!-- Descriptive for informative images -->

Adding title attribute information #
To add a tooltip or additional context, include a title in quotes directly after the image path:

When a user hovers over the image, the title appears as a tooltip.
Not all Markdown processors support the title attribute. See the Markdown parser feature comparison.
Adding height and width information #
Standard Markdown does not support image sizing, but some processors support extended syntax:
{width=200px}
Not all Markdown processors support height and width attributes. See the Markdown parser feature comparison.
Alternatively, to define height and width, use the HTML <img> tag inside your Markdown file. This approach gives you more control over how your image appears in rendered documents:
<img src="chart.svg" alt="Sales chart" width="400" height="300">
Adding images with a CSS class #
Several Markdown renderers support adding CSS classes to images, typically through extended syntax or plugins. Here are the most notable ones:
Markdown-it #
Markdown-it, CommonMark-compatible, supports adding classes via attributes syntax:
{.my-class}
Requires the markdown-it-attrs plugin.
Pandoc #
Pandoc supports attribute syntax for classes:
{.class .another-class key=val}
Works natively without plugins.
Kramdown #
Kramdown, used by Jekyll, supports inline attribute lists (IALs):
{: .my-class}
MultiMarkdown #
MultiMarkdown allows classes via:
![alt][img-id]
[img-id]: image.png "title" {.class}
Not all Markdown processors support class attributes. See the Markdown parser feature comparison.
In most other cases, to style your image using Cascading Style Sheets (CSS), you must also fall back to using HTML.
Fallback: Using HTML for full control #
Markdown is designed to be simple, so it does not support advanced formatting features out of the box. When you need full control, use raw HTML:
<img src="./images/architecture.svg"
alt="Architecture Diagram"
title="Click to enlarge"
width="600"
height="400"
class="img-border img-center">
This gives you the ability to define classes, dimensions, alt text, and title attributes all at once.
Images in Git repositories #
If you are working in a Git repository, place the image file within your project structure. Use relative paths to ensure portability:

Git-LFS #
Use Git LFS (Large File Storage) for binary files like images. It replaces the assets with pointers, preventing repository bloat and speeding up Git operations.
Unlike regular Git, which struggles with binary files, LFS stores them externally, reducing bandwidth and storage costs while maintaining seamless version control.
For binary image files (like GIF, PNG, JPG), use Git Large File Storage (Git-LFS) to avoid bloating your repository:
Install Git-LFS:
git lfs installTrack binary image files:
git lfs track "*.gif" git lfs track "*.png" git lfs track "*.jpg" ...Commit normally. Git-LFS will handle the large files.
SVG files do not need to be added to Git-LFS since they are text-based.
FAQ's #
Most common questions and brief, easy-to-understand answers on the topic:
How do I add an image to a Markdown file from a local directory?
Use the syntax  and place the image in the specified path relative to the Markdown file.
What is the purpose of the alt attribute in Markdown images?
The alt attribute provides alternative text for screen readers and is shown if the image fails to load.
Can you resize images in Markdown?
Yes, using HTML: <img src="image.png" width="200" height="100">. Some Markdown processors support {width=200}.
Can I use HTML inside a Markdown file to style images?
Yes, Markdown supports inline Hypertext Markup Language (HTML), so you can use HTML for advanced image formatting.
When should I use Git Large File Storage (Git LFS) for images?
Use Git LFS when storing large files or images in binary formats like PNG, JPG, GIF, etc. to avoid bloating your Git repository with non-code assets.
How can I add width and height to images in Markdown?
Use the HTML <img> tag with width and height attributes when Markdown syntax does not support this directly.
Further readings #
Sources and recommended, further resources on the topic:
License
How to add images in Markdown files by Jonas Jared Jacek is licensed under CC BY-SA 4.0.
This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. To give credit, provide a link back to the original source, the author, and the license e.g. like this:
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/how-to-add-images-to-markdown-files">How to add images in Markdown files</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0</a>.</p>For more information see the Ditig legal page.