
Adding videos to your articles is a great way to engage your readers and convey messages more effectively. Hugo makes it incredibly simple to embed external content like YouTube videos, thanks to built-in shortcodes.
The YouTube Shortcode
You don’t need to copy-paste the complex <iframe> code provided by YouTube. Instead, you can use the youtube shortcode. All you need is the video’s ID.
For example, here is a video about web design principles:
This is the code used to embed the video above. It’s clean and simple!
{{< youtube id="YubP_p2hY-o" title="Principles of Web Design" >}}
Why Use Shortcodes?
- Simplicity: They keep your Markdown content clean and readable.
- Security: Hugo handles the safe generation of the
<iframe>. - Responsive: The embedded video is typically responsive and displays well on all devices.
- Performance: Some themes apply optimizations like lazy loading to the video, improving page load times.
Try embedding a video in your next post and see how it enhances your content!