|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: How to embed YouTube Shorts |
| 4 | +date: 2026-08-26 13:46:10 |
| 5 | +excerpt: This post goes over how to embed YouTube Shorts using an iframe. |
| 6 | +categories: youtube shorts embed iframe |
| 7 | +--- |
| 8 | + |
| 9 | +This post goes over to how to embed a YouTube Short using an [iframe](https://developer.mozilla.org/docs/Web/HTML/Reference/Elements/iframe). |
| 10 | + |
| 11 | +## Video ID |
| 12 | + |
| 13 | +Copy the video ID from the URL. For example, the video ID is `abc123` for the link below: |
| 14 | + |
| 15 | +``` |
| 16 | +https://youtube.com/shorts/abc123 |
| 17 | +``` |
| 18 | + |
| 19 | +Also, make sure to copy the ID between the last `/` and `?`: |
| 20 | + |
| 21 | +``` |
| 22 | +https://youtube.com/shorts/abc123?si=def456 |
| 23 | +``` |
| 24 | + |
| 25 | +## Embed |
| 26 | + |
| 27 | +Now replace `<VIDEO_ID>` with the video ID: |
| 28 | + |
| 29 | +```html |
| 30 | +<iframe |
| 31 | + width="360" |
| 32 | + height="640" |
| 33 | + src="https://www.youtube.com/embed/<VIDEO_ID>" |
| 34 | + title="YouTube Short" |
| 35 | + frameborder="0" |
| 36 | + allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" |
| 37 | + referrerpolicy="strict-origin-when-cross-origin" |
| 38 | + allowfullscreen |
| 39 | +></iframe> |
| 40 | +``` |
| 41 | + |
| 42 | +For a bigger 16:9 player, you can replace the `width` and `height` with 405×720 or 450×800. For example: |
| 43 | + |
| 44 | +```diff |
| 45 | + <iframe |
| 46 | +- width="360" |
| 47 | +- height="640" |
| 48 | ++ width="450" |
| 49 | ++ height="800" |
| 50 | + src="https://www.youtube.com/embed/<VIDEO_ID>" |
| 51 | + title="YouTube Short" |
| 52 | + frameborder="0" |
| 53 | + allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" |
| 54 | + referrerpolicy="strict-origin-when-cross-origin" |
| 55 | + allowfullscreen |
| 56 | + ></iframe> |
| 57 | +``` |
| 58 | + |
| 59 | +If you want to center the video player horizontally, then add the attribute `style="display: block; margin: 0 auto;"`: |
| 60 | + |
| 61 | +```diff |
| 62 | + <iframe |
| 63 | + width="360" |
| 64 | + height="640" |
| 65 | ++ style="display: block; margin: 0 auto;" |
| 66 | + src="https://www.youtube.com/embed/<VIDEO_ID>" |
| 67 | + title="YouTube Short" |
| 68 | + frameborder="0" |
| 69 | + allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" |
| 70 | + referrerpolicy="strict-origin-when-cross-origin" |
| 71 | + allowfullscreen |
| 72 | + ></iframe> |
| 73 | +``` |
| 74 | + |
| 75 | +## Demo |
| 76 | + |
| 77 | +Here's an example of an embedded YouTube Short: |
| 78 | + |
| 79 | +```html |
| 80 | +<iframe |
| 81 | + width="405" |
| 82 | + height="720" |
| 83 | + style="display: block; margin: 0 auto;" |
| 84 | + src="https://www.youtube.com/embed/chYGYjH2E2c" |
| 85 | + title="YouTube Short" |
| 86 | + frameborder="0" |
| 87 | + allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" |
| 88 | + referrerpolicy="strict-origin-when-cross-origin" |
| 89 | + allowfullscreen |
| 90 | +></iframe> |
| 91 | +``` |
| 92 | + |
| 93 | +<iframe width="405" height="720" style="display: block; margin: 0 auto;" src="https://www.youtube.com/embed/chYGYjH2E2c" title="YouTube Short" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> |
0 commit comments