How to add a GIF to a Markdown file (Github and Vanilla)

avatar
Borislav Hadzhiev

Last updated: Apr 5, 2024
5 min

banner

# Table of Contents

  1. How to add a GIF to a Markdown file (Github and Vanilla)
  2. Adding a GIF from a URL to a markdown file
  3. Adding a local GIF to a markdown file
  4. Resizing the GIF in your markdown file
  5. Adding a GIF to your markdown file with a reference

# How to add a GIF to a Markdown file (Github and Vanilla)

To add a gif to a markdown file:

  1. Use the following format ![alt text](my-file.gif).
  2. You can either specify a path to a local .gif file or an external URL that points to a gif.
  3. Make sure the file or URL has a .gif extension.
README.md
1. Adding a GIF from an external URL to markdown. ![color picker](https://bobbyhadz.com/images/blog/change-vscode-integrated-terminal-colors/hover-over-color.gif) 2. Adding a local GIF file to markdown. ![using a color picker](hover-over-color.gif)

add gif to markdown

The examples work in vanilla markdown files and GitHub markdown.

# Adding a GIF from a URL to a markdown file

The first example shows how to add a GIF from an external URL to a markdown file.

You simply have to specify the complete URL that points to the file, including the file's extension (.gif).

README.md
1. Adding a GIF from an external URL to markdown. ![color picker](https://bobbyhadz.com/images/blog/change-vscode-integrated-terminal-colors/hover-over-color.gif)

If you click on the URL, you should be able to load the GIF in your browser.

Note that the protocol has to be included (https:// or http://) for the GIF to load properly.

The most common reasons for GIFs from remote URLs to not load in markdown are:

  1. Forgetting to specify the protocol in the URL.
  2. Forgetting to specify the .gif extension.

The easiest way to copy a URL that points to a GIF is to right-click on the GIF and select Copy image address.

right click copy image address

You can also specify the title text for the GIF at the end, after the URL.

README.md
![color picker](https://bobbyhadz.com/images/blog/change-vscode-integrated-terminal-colors/hover-over-color.gif 'title text here')

show title text of external gif

If you scroll to the right, you will see the title text string after the URL.

If you hover over the GIF, the title text is shown.

# Adding a local GIF to a markdown file

The second example shows how to add a local GIF file to a markdown file.

It assumes that you have a GIF file named hover-over-color.gif in the same directory as your markdown file.

You can download the following GIF file for testing purposes.

Right-click on the GIF and select Save image as... to download it.

hover over color

Place it in the same directory as your .md file and include it as follows.

README.md
![using a color picker](hover-over-color.gif)

The text between the square brackets [] is the alt text for the .gif.

The alt text is shown if your GIF cannot be loaded for one reason or another (e.g. specifying an incorrect path or the GIF has been deleted).

The test between the parentheses () specifies the path to the .gif file.

You can also specify the title text that is shown when the user hovers over the GIF.

README.md
![using a color picker](hover-over-color.gif 'title text here')

show title text of external gif

The title text is specified after the path to the GIF.

The example above assumes that your .gif file is located in the same directory as your README.md file.

shell
my-project/ └── README.md └── hover-over-color.gif

gif in same directory as markdown file

If you have the following folder structure.

shell
my-project/ └── README.md └── my-gifs/ └── hover-over-color.gif

You would have to specify the complete path to the .gif file in order to add it to your markdown file.

README.md
2. Adding a local GIF file to markdown. ![using a color picker](my-gifs/hover-over-color.gif)

Notice that we specified the complete path to the file, including the directory and the file's extension (.gif).

Specifying the path to the GIF is quite easy if you use VS Code as your code editor.

  1. Select the file in explorer (the left sidebar) and drag it to your markdown file.
  2. Press Shift on your keyboard and hold it.
  3. Drop the file where you want to insert the GIF.

add gif to markdown in vscode editor

I've written a detailed guide on how to add images and links to files in Markdown in VS Code.

# Resizing the GIF in your markdown file

If you need to resize the gif, use an img tag and set the width and height attributes on the image.

README.md
1. Adding a GIF from an external URL to markdown. <img width="400" height="250" alt="color picker" src="https://bobbyhadz.com/images/blog/change-vscode-integrated-terminal-colors/hover-over-color.gif" /> 2. Adding a local GIF file to markdown. <img width="400" height="250" src="hover-over-color.gif" alt="color picker" />

resize gif in markdown file

This approach works in both vanilla and GitHub markdown files.

The width and height attributes are used to set the width and height of the GIF.

You can use an img tag to add a GIF to your markdown file even without adjusting the GIF's width or height.

README.md
1. Adding a GIF from an external URL to markdown. <img alt="color picker" src="https://bobbyhadz.com/images/blog/change-vscode-integrated-terminal-colors/hover-over-color.gif" /> 2. Adding a local GIF file to markdown. <img src="hover-over-color.gif" alt="color picker" />

# Adding a GIF to your markdown file with a reference

You can also add a GIF to your markdown file with a reference.

README.md
![color picker][my-gif] [my-gif]: https://bobbyhadz.com/images/blog/change-vscode-integrated-terminal-colors/hover-over-color.gif

Notice that the first line uses 2 sets of square brackets [] and not square brackets [] and parentheses ().

The Last 2 lines set the name of the reference (my-gif) and the path to the GIF.

You can imagine that my-gif in the first line gets replaced with the URL that points to the external GIF.

This approach works in vanilla and GitHub markdown.

add gif to markdown using reference

If you use VS Code as your IDE, check out the following article:

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.