Quick tip: embedding YouTube Videos in GitHub pages

GitHub Pages is a great way to host some of your content online. All you need to do is to write some markdown files and tell GitHub to create it as a page. The problem is that you can’t just add some HTML into your markdown to – for example – embed a YouTube video. […]

A youtube video embedded into a markdown file showing up on GitHub pages

GitHub Pages is a great way to host some of your content online. All you need to do is to write some markdown files and tell GitHub to create it as a page.

The problem is that you can’t just add some HTML into your markdown to – for example – embed a YouTube video. It does work if all you include is the YouTube iframe, but when you work with professional markdown repos, this will be flagged up as an error or security problem.

A workaround that many people use is to embed a linked preview of the video :

If your YouTube URL is https://www.youtube.com/watch?v=JLMbpiywVxQ the important part is the ID after the `v=`, in this case `JLMbpiywVxQ`.

You can then use the following markdown to embed a link to the video with a preview image of it. YouTube automatically creates these preview images.


[![Final video of fixing issues in your code in VS Code]
(https://img.youtube.com/vi/JLMbpiywVxQ/maxresdefault.jpg)]
(https://www.youtube.com/watch?v=JLMbpiywVxQ)

Final video of fixing issues in your code in VS Code

If, however, you want to embed the video in markdown files, you need to do a bit more.

1. Go to the root of your GitHub repo with the markdown files and create a folder called `_includes`.
2. In this folder, create a file called `youtube.html`. Paste this HTML and CSS and save it.






Now you can embed any YouTube video in your markdown files using the following:


{% include youtube.html id=”JLMbpiywVxQ” %}

With the ID being the YouTube ID.

You can see this in action and fork the youtube embed demo repository if you don’t want to do it by hand.


Print Share Comment Cite Upload Translate Updates
APA

Chris Heilmann | Sciencx (2022-09-14T09:49:23+00:00) Quick tip: embedding YouTube Videos in GitHub pages. Retrieved from https://www.scien.cx/2022/09/14/quick-tip-embedding-youtube-videos-in-github-pages/

MLA
" » Quick tip: embedding YouTube Videos in GitHub pages." Chris Heilmann | Sciencx - Wednesday September 14, 2022, https://www.scien.cx/2022/09/14/quick-tip-embedding-youtube-videos-in-github-pages/
HARVARD
Chris Heilmann | Sciencx Wednesday September 14, 2022 » Quick tip: embedding YouTube Videos in GitHub pages., viewed ,<https://www.scien.cx/2022/09/14/quick-tip-embedding-youtube-videos-in-github-pages/>
VANCOUVER
Chris Heilmann | Sciencx - » Quick tip: embedding YouTube Videos in GitHub pages. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/09/14/quick-tip-embedding-youtube-videos-in-github-pages/
CHICAGO
" » Quick tip: embedding YouTube Videos in GitHub pages." Chris Heilmann | Sciencx - Accessed . https://www.scien.cx/2022/09/14/quick-tip-embedding-youtube-videos-in-github-pages/
IEEE
" » Quick tip: embedding YouTube Videos in GitHub pages." Chris Heilmann | Sciencx [Online]. Available: https://www.scien.cx/2022/09/14/quick-tip-embedding-youtube-videos-in-github-pages/. [Accessed: ]
rf:citation
» Quick tip: embedding YouTube Videos in GitHub pages | Chris Heilmann | Sciencx | https://www.scien.cx/2022/09/14/quick-tip-embedding-youtube-videos-in-github-pages/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.