Table of contents | |
Introduction | |
Adding Images | |
Embedding Videos | |
Adding Audio Files | |
Specifying Width and Height | |
Sample Problems |
When creating a website, it's important to engage your visitors with various forms of media such as images, videos, and audio files. In this article, we will explore how to add media to a website using HTML. We will cover the basic HTML tags and attributes required to display media elements on a webpage, and provide examples and code explanations to make it easy for beginners to understand.
Images are a great way to enhance the visual appeal of your website. To add an image, follow these steps:
Code Example:
<img src="https://edurev.gumlet.io/mage.jpg" alt="Description of the image">
Explanation:
Videos can be used to showcase product demos, tutorials, or promotional content on your website. To embed a video, you can use the '<video>' tag as shown below:
<video src="https://edurev.gumlet.io/ideo.mp4" controls></video>
Explanation:
If you want to include audio files, such as background music or podcast episodes, you can use the '<audio>' tag:
Code Example:
<audio src="https://edurev.gumlet.io/udio.mp3" controls></audio>
Explanation:
You can adjust the width and height of media elements to control their display size on the webpage. Here's how:
Code Example:
<img src="https://edurev.gumlet.io/mage.jpg" alt="Description of the image" width="300" height="200">
Explanation:
Problem 1: Create an HTML page with an image that is centered on the page and has a width of 500 pixels.
<!DOCTYPE html>
<html>
<head>
<title>Centered Image</title>
<style>
img {
display: block;
margin: 0 auto;
width: 500px;
}
</style>
</head>
<body>
<img src="https://edurev.gumlet.io/mage.jpg" alt="Centered Image">
</body>
</html>
Problem 2: Embed a YouTube video on your webpage and set its width to 800 pixels.
<!DOCTYPE html>
<html>
<head>
<title>Embedded Video</title>
</head>
<body>
<iframe width="800" height="450" src="https://www.youtube.com/embed/VIDEO_ID" frameborder="0" allowfullscreen></iframe>
</body>
</html>
Replace '"VIDEO_ID"' with the actual ID of the YouTube video you want to embed.
By following these examples and explanations, you can easily add images, videos, and audio files to your website using HTML. Experiment with different attributes and CSS styles to customize the media elements according to your design preferences.
20 videos|15 docs|2 tests
|
|
Explore Courses for Software Development exam
|