My Learning Curve

Feed / Phil Nash

Making a responsive Twitch Embed

Monday, March 23, 2020

I've been trying out streaming live code on Twitch which is a lot of fun. I wanted to share on my own site that I was streaming so I have built a page dedicated to it. The page will evolve, but one of the first things I wanted to include on it was an embed of my Twitch stream and chat.

Twitch makes it easy to embed your stream but the less obvious part is how to make that embed responsive across any browser size. So here's how to create a responsive Twitch embedded stream.

The HTML

There are 3 ways you can embed Twitch on your site, embedding everything, which involves loading the Twitch Embed JavaScript that creates an

The layout

The video is in 16:9 aspect ratio. On mobile I want the chat to sit below the video and then when the screen becomes wide enough on the right hand side of the video. When side-by-side, the chat and video should be the same height.

The tricky part here is the aspect ratio. CSS doesn't have a native way to accomplish aspect ratios yet. For now the way to force an aspect ratio in an element is unintuitive, but at least it works. You can apply this to any HTML you need to maintain a height that is relative to its width, things like elements, or