Last updated: Apr 5, 2024
Reading time·5 min
To add a gif to a markdown file:
![alt text](my-file.gif)
..gif
file or an external URL that
points to a gif..gif
extension.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)
The examples work in vanilla markdown files and GitHub markdown.
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).
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:
.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.
You can also specify the title text for the GIF at the end, after the URL.
![color picker](https://bobbyhadz.com/images/blog/change-vscode-integrated-terminal-colors/hover-over-color.gif 'title text here')
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.
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.
Place it in the same directory as your .md
file and include it as follows.
![using a color picker](hover-over-color.gif)
The text between the square brackets []
is the alt text for the .gif
.
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.
![using a color picker](hover-over-color.gif 'title text here')
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.
my-project/ └── README.md └── hover-over-color.gif
If you have the following folder structure.
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.
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.
Shift
on your keyboard and hold it.I've written a detailed guide on how to add images and links to files in Markdown in VS Code.
If you need to resize the gif
, use an img
tag and set the width
and
height
attributes on the image.
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" />
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.
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" />
You can also add a GIF to your markdown file with a reference.
![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.
If you use VS Code as your IDE, check out the following article:
You can learn more about the related topics by checking out the following tutorials: