Adding Videos

27 Embedding YouTube Videos

Typically, the best way to add videos to a textbook is to host them on YouTube, and then embed them into the book afterwards. This section assumes that the videos to be embedded are already hosted on YouTube.

There are two main ways to embed a YouTube video into a Pressbooks chapter:

Automatic Embed

The easiest way to embed a video is to simply copy the video’s URL and paste it into either the Visual or Text view in the Pressbooks editor. Thus, the following code:

Opening paragraph here...
https://www.youtube.com/watch?v=5_t6lmKhBOI
Closing paragraph here...

Would yield the following:

Opening paragraph here…

Closing paragraph here…

Manual Embed

Another way to embed a video is to manually insert the embed code from the YouTube video. To do this, go to the YouTube video and right-click on the video, then select the “Copy embed code” option, and press Ctrl-C (PC) or Command-C (Mac) to copy the embed code. You can then paste the embed code into the Text view of the Pressbooks editor.

Right-click the image, then select "Copy embed code."

Right-click the image, then select “Copy embed code.”

Once the embed code is highlighted, use Ctrl-C (PC) or Command-C (Mac) to copy the embed code.

Once the embed code is highlighted, use Ctrl-C (PC) or Command-C (Mac) to copy the embed code.

The embed code likely makes the video display too large – the ideal size is 500 by 281 pixels. Go into the Text View to edit these dimensions:

The default embed code ought to look like this:

<iframe width="854" height="480" src="https://www.youtube.com/embed/oXOSDwVX0Dw" allowfullscreen>

Change that to:

<iframe width="500" height="281" src="https://www.youtube.com/embed/oXOSDwVX0Dw" allowfullscreen>

Thus, the following code:

Opening paragraph here...
<iframe width="500" height="281" src="https://www.youtube.com/embed/oXOSDwVX0Dw" allowfullscreen>
Closing paragraph here...

Would yield the following:

Opening paragraph here…

Closing paragraph here…