YouTube shortcode
Embed a YouTube video in your content using the youtube shortcode.
To override Hugo’s embedded youtube shortcode, copy the source code to a file with the same name in the layouts/_shortcodes directory.
Example
To display a YouTube video with this URL:
https://www.youtube.com/watch?v=0RKpf3rK57IInclude this in your Markdown:
{{< youtube 0RKpf3rK57I >}}Hugo renders this to:
Arguments
- id
- (
string) The videoid. Optional if theidis the first and only positional argument. - allowFullScreen
- New in v0.125.0
- (
bool) Whether theiframeelement can activate full screen mode. Default istrue. - autoplay
- New in v0.125.0
- (
bool) Whether to automatically play the video. Forcesmutetotrue. Default isfalse. - class
- (
string) Theclassattribute of the wrappingdivelement. When specified, removes thestyleattributes from theiframeelement and its wrappingdivelement. - controls
- New in v0.125.0
- (
bool) Whether to display the video controls. Default istrue. - end
- New in v0.125.0
- (
int) The time, measured in seconds from the start of the video, when the player should stop playing the video. - loading
- New in v0.125.0
- (
string) The loading attribute of theiframeelement, eithereagerorlazy. Default iseager. - loop
- New in v0.125.0
- (
bool) Whether to indefinitely repeat the video. Ignores thestartandendarguments after the first play. Default isfalse. - mute
- New in v0.125.0
- (
bool) Whether to mute the video. Alwaystruewhenautoplayistrue. Default isfalse. - start
- New in v0.125.0
- (
int) The time, measured in seconds from the start of the video, when the player should start playing the video. - title
- (
string) Thetitleattribute of theiframeelement. Defaults to “YouTube video”.
Here’s an example using some of the available arguments:
{{< youtube id=0RKpf3rK57I start=30 end=60 loading=lazy >}}Privacy
Adjust the relevant privacy settings in your site configuration.
privacy:
youTube:
disable: false
privacyEnhanced: false
[privacy]
[privacy.youTube]
disable = false
privacyEnhanced = false
{
"privacy": {
"youTube": {
"disable": false,
"privacyEnhanced": false
}
}
}
- disable
- (
bool) Whether to disable the shortcode. Default isfalse. - privacyEnhanced
- (
bool) Whether to block YouTube from storing information about visitors on your website unless the user plays the embedded video. Default isfalse.
Last updated:
June 15, 2025
:
content: Update to align with v0.146.0 template system (phase 1) (0015e7a9b)
Improve this page