I have to take some web design classes for the project.
- CSS Essential Training



















“I’m going to add another paragraph. Then use another shortcut to add some dummy text. Lorem, L-O-R-E-M. Then press Tab. Now we have a block of text that wraps over multiple lines...”



























































video
– The introduction of video and audio elements was a big step forward in the development of HTML. The ability to easily embed video and audio directly into webpages, replaced older plugin based solutions like Flash and Silverlight, helping to drive the growth of streaming media online with platforms like YouTube and SoundCloud as some of the early adopters. Let’s explore how to implement the video element, its key features and syntax. There are several file formats that can be used with the video element. MP4 is supported across all major browsers and offers good compression and quality. WebM is an open source format that delivers high quality video and is optimized for web use. OGG is an older open source format that is still a viable option, but is less commonly used. MP4 provide the best browser compatibility, though any of these formats will work. You can use video editing software or conversion tools to switch between formats. All video elements start with an opening and closing tag. Just like the image element, the source attribute is used to link to the media file. It’s also recommended to include a fallback message for older browsers. This typically includes a message and a download link, so users can watch the video in a media player outside of the browser. You can add additional support by providing multiple video formats using the source element. It’s a void element, and instead of adding the source attribute to the video tag, it’s added to each source tag instead, along with a type attribute to specify the video format. Place these elements before the fallback message. The browser will use the first supported video format from the list. Let’s see how a basic video element looks. Using the 0601 start HTML file. There’s only one video file for the demonstration, so the source attribute is added directly to the video tag. To test your fallback message, just add a typo to the video tag so it won’t render properly on the page. This message will only display in older browsers that don’t support the video element. Let’s put it back to the correct syntax. Right now we can only see the video, but no player controls by default. Videos can be used to add visual interests. For example, a clothing store might use video to showcase their products or for ad campaigns. In this scenario, you may not need to include any playback controls, but most of the time they’re typically recommended for a better user experience. Back in the editor let’s add the controls boolean attribute to display the default browser controls. The media player varies across browsers. Firefox provides play pause buttons, volume control, full screen mode, and a pop-out option that appears when hovering over the video. Chrome offers some additional features, playback speed and picture in picture, which is basically the same as Firefox’s pop-out feature. For more advanced customization beyond the default controls, or to create browser specific features, JavaScript can be used. Let’s add a few more boolean attributes. Autoplaying can be used to set the video to automatically start when the page loads. This feature would be useful for the clothing store scenario, but it’s usually better to let users control playback. Just note that some browser settings can be set to block autoplay, and in those cases, this attribute may not override those settings. Loop automatically repeats the video playback after it ends. And muted, starts the video with the sound muted. When muted, the audio icon is shown with a line through it. Click it to turn the volume on and click it again to mute it. These attributes serve specific purposes, but before using them, consider your goals and how they will affect the user experience. To display a custom preview image for the video, use the poster attribute. This requires a value to specify the path to the image file, which is also included in the exercise folder. This image displays before your video starts, so the autoplay attribute must be removed to be able to see the preview image. Let’s save the file. By default, the videos display area matches the files dimensions, but when using the poster attribute, some browsers will default to the size of the image file instead. For example, Firefox maintains the video dimensions, while Chrome defaults to the image size. Like the image tag, the width and height attributes can be used to define the size. You can also use CSS as well, but for now, let’s use the attributes to set the width and height to match the video file dimensions 640 by 360. There’s no change in Firefox since it was already defaulted to the videos dimensions, but now we can see the change in Chrome. We’ve covered the basic usage of the video element and how to add extra features using attributes, but there are more attributes that can be used with the video element. The complete list is available in the MDN docs. Keep this example open. We’ll be using it again in the next video.

audio
The video element can be used to play audio files, but the audio element is a better choice. It’s specifically designed for audio and provides clear semantic meaning, making it more effective for both accessibility and search engines. Both elements share similar functionality, so the syntax is pretty much the same with a few differences. Let’s take a closer look. Like the video element, the audio element requires the source attribute to link to the audio file. The controls attribute must also be added to display the player controls. Without it, the audio element won’t display at all. Since it’s audio only, the controls are the only visual interface displayed in the browser. Also like the video element, audio should include fallback content as well. You can also include multiple audio formats by using the source element nested inside the audio text. The source attribute is also added here instead of the audio tag. There are three primary audio formats that can be used. MP3 is the most widely supported format and is compatible with all major browsers. It provides good audio quality while maintaining relatively small file sizes. The WAV format also offers high-quality audio, but tends to have larger file sizes than MP3s. It has widespread browser support, though some legacy browsers like Internet Explorer don’t support it. But IE usage is pretty low these days, so it’s not that much of an issue anymore. The OGG format is an older open-source option, but also provides good quality and smaller file sizes. Let’s look at an example using the 06_03_start HTML file. This shows the basic audio implementation using the source and controls attributes along with a fallback message. The styles of the default players vary across browsers, but they all have the same basic functions: play, pause, and volume control. Chrome has an additional feature: playback speed. The audio element supports the same attributes as the video element except for the width, height, and poster attributes since audio has no visual component beyond the control bar. You can add the autoplay and loop attributes to automatically play the audio on page load and loop the audio file when it reaches the end. But just like video, use these features thoughtfully to ensure the best user experience. The track element can also be used with audio, but its implementation requires additional scripting because the only visual interface is the control bar. Using the video element is the simplest solution, but if you want to use the audio element for better semantics, you’ll need JavaScript to display captions during playback, either through existing libraries or creating your own custom scripts.


iframe
Embedding media with iframes
Selecting transcript lines in this section will navigate to timestamp in the video
– If you’ve ever used the embed option on YouTube, Spotify, or some other media platform to add a video, song, or playlist to a webpage, you’ve likely encountered the iframe element. It’s an effective way to display content from another source. With iframe, you can embed content from one webpage into another webpage. Let’s look at the structure for a basic iframe setup. The syntax should look familiar by now since it uses many of the same attributes we’ve used for other media elements. An iframe requires an opening and closing tag. The source attribute points to the URL of the content you want to embed. The width and height attributes determine the size of the embedded content. And the title attribute provides a text description of the embedded content, which is helpful for accessibility. Let’s go to YouTube and take a look at what their embed code looks like. You can look at any video, but I’ll use the same one from the previous examples, except this time it’s the version uploaded to YouTube. To find the code, click the Share button, then click the Embed option. Here we can see the basic markup we just covered, the width, height, source, and title, but there are quite a few more attributes included to allow for additional controls, behaviors, or security settings. For the most part, it’s fine to use a third-party’s embed code as is, but understanding the basic structure means you can make your own edits, such as the width and the height. This is YouTube’s default size, but now you know where you can change it. If you’d like to know more about some of these other attributes, it’s all documented, of course. Check the Links PDF file for more resources. With iframe, you can embed any type of content from another website, not just audio and video platforms. Let’s say I have a website about tourist attractions in Toronto. I can go to Google Maps and search for an address or landmark to find its location. For example, let me look up the CN Tower. I can then embed a map of the CN Tower directly into my website, allowing visitors to view and interact with the map without leaving the page. Go to Share, Embed a Map. The code will appear here. The preview shown in this modal window represents what will be embedded on your website. There are many third-party services that let you embed content, like forms, calendars, and interactive widgets, into your webpage. While knowing how to write HTML from scratch is valuable, using existing tools can help you add more advanced features and simplify your workflow.
