Skip to content

Commit a3ef097

Browse files
committed
HTML Media content started
1 parent ac381ef commit a3ef097

File tree

7 files changed

+282
-0
lines changed

7 files changed

+282
-0
lines changed

docs/html-media/_category_.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "👩🏻‍💻 HTML Media",
3+
"position": 6,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "Learn the basics of HTML media elements and how to embed audio and video content."
7+
}
8+
}

docs/html-media/audio.mdx

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
id: audio
3+
title: HTML Audio Element
4+
sidebar_label: 🙋🏻 Audio
5+
description: HTML Audio Element is used to embed sound content in a document.
6+
tags: ['html', 'audio']
7+
keywords: ['html', 'audio', 'audio element', 'html audio element']
8+
sidebar_position: 2
9+
---
10+
11+
Audio element is used to embed sound content in a document. It may contain one or more audio sources, represented using the src attribute or the source element: the browser will choose the most suitable one.
12+
13+
## Syntax
14+
15+
```html title="Syntax"
16+
<audio controls>
17+
<source src="audio.mp3" type="audio/mpeg">
18+
<source src="audio.ogg" type="audio/ogg">
19+
Your browser does not support the audio element.
20+
</audio>
21+
```
22+
23+
## Attributes
24+
25+
- **autoplay**: It is a boolean attribute. If specified, the audio will automatically begin playback as soon as it can do so, without waiting for the entire audio file to finish downloading.
26+
- **controls**: It is a boolean attribute. If specified, the browser will display controls to allow the user to control audio playback, including volume, seeking, and pause/resume playback.
27+
- **loop**: It is a boolean attribute. If specified, the audio player will automatically seek back to the start upon reaching the end of the audio.
28+
- **muted**: It is a boolean attribute. If specified, the audio will be initially silenced.
29+
30+
## Example
31+
32+
```html title="index.html"
33+
<!DOCTYPE html>
34+
<html lang="en">
35+
<head>
36+
<meta charset="UTF-8">
37+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
38+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
39+
<title>Audio Element Example</title>
40+
</head>
41+
<body>
42+
<h1>Audio Element Example</h1>
43+
<audio controls>
44+
<source src="audio.mp3" type="audio/mpeg">
45+
<source src="audio.ogg" type="audio/ogg">
46+
Your browser does not support the audio element.
47+
</audio>
48+
</body>
49+
</html>
50+
```
51+
52+
<BrowserWindow url="https://.../index.html">
53+
<>
54+
<h1>Audio Element Example</h1>
55+
<audio controls>
56+
<source src="/audio/audio.mp3" type="audio/mpeg" />
57+
<source src="audio.ogg" type="audio/ogg" />
58+
Your browser does not support the audio element.
59+
</audio>
60+
</>
61+
</BrowserWindow>
62+
63+
In the above example, the audio element is used to embed sound content in the document. The audio element contains two source elements, one for the MP3 file and another for the OGG file. If the browser does not support the audio element, it will display the message "Your browser does not support the audio element."
64+
65+
## Browser Support
66+
67+
The audio element is supported in all major browsers, including Chrome, Firefox, Safari, and Edge.
68+
69+
## Accessibility
70+
71+
When using the audio element, it is important to provide alternative text or a message for users who cannot access the audio content. This can be done by including text content inside the audio element, as shown in the example above.
72+
73+
## Best Practices
74+
75+
- Provide multiple audio sources in different formats to ensure compatibility with a wide range of browsers.
76+
- Use the controls attribute to allow users to control audio playback.
77+
- Provide alternative text or a message for users who cannot access the audio content.
78+
79+
## Conclusion
80+
81+
The audio element is a powerful tool for embedding sound content in a document. By providing multiple audio sources and using the controls attribute, you can create a rich audio experience for your users. Remember to provide alternative text or a message for users who cannot access the audio content, and test your audio content in different browsers to ensure compatibility.

docs/html-media/canvas.mdx

Whitespace-only changes.

docs/html-media/image.mdx

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
---
2+
id: image
3+
title: "HTML Images Guide"
4+
description: "Learn how to use images in HTML, including syntax, attributes, formats, responsive design, accessibility, and SEO best practices."
5+
sidebar_label: "🙋🏻 Images"
6+
keywords: [HTML images, HTML img tag, HTML picture element, responsive images, image formats, image optimization, image accessibility, SEO images]
7+
tags: [HTML, Images, Responsive Design, Accessibility, SEO]
8+
sidebar_position: 1
9+
---
10+
11+
Images are an essential part of web design and play a crucial role in enhancing the visual appeal of a website. In HTML, you can add images to your web pages using the `<img>` tag. This guide will teach you how to use images in HTML, including syntax, attributes, formats, responsive design, accessibility, and SEO best practices.
12+
13+
## HTML Image Syntax
14+
15+
To add an image to an HTML page, you use the `<img>` tag. The `<img>` tag is an empty element, which means it does not have a closing tag. Here's the basic syntax for adding an image to an HTML page:
16+
17+
```html title="index.html"
18+
<!DOCTYPE html>
19+
<html>
20+
<head>
21+
<title>HTML Images</title>
22+
</head>
23+
<body>
24+
<h1>My Image</h1>
25+
<img src="image.jpg" alt="My Image">
26+
</body>
27+
</html>
28+
```
29+
30+
<BrowserWindow url="https://.../index.html">
31+
<>
32+
<h1>My Image</h1>
33+
<img src="/img/image.jpg" alt="My Image" />
34+
</>
35+
</BrowserWindow>
36+
37+
In the example above, we've used the `<img>` tag to display an image named `image.jpg`. The `src` attribute specifies the URL of the image file, and the `alt` attribute provides alternative text for the image. The `alt` attribute is essential for accessibility and SEO purposes.
38+
39+
## HTML Image Attributes
40+
41+
The `<img>` tag supports several attributes that allow you to customize the appearance and behavior of the image. Here are some common attributes used with the `<img>` tag:
42+
43+
- `src`: Specifies the URL of the image file.
44+
- `alt`: Provides alternative text for the image.
45+
- `width`: Sets the width of the image in pixels.
46+
- `height`: Sets the height of the image in pixels.
47+
- `title`: Specifies the title of the image (displayed as a tooltip).
48+
- `loading`: Indicates how the image should be loaded.
49+
- `decoding`: Specifies the decoding method for the image.
50+
- `sizes`: Defines the sizes of the image for different viewports.
51+
- `srcset`: Specifies multiple image sources for responsive images.
52+
53+
Here's an example that demonstrates the use of some of these attributes:
54+
55+
```html title="image-attributes.html"
56+
<!DOCTYPE html>
57+
<html>
58+
<head>
59+
<title>Image Attributes</title>
60+
</head>
61+
<body>
62+
<h1>Image Attributes</h1>
63+
<img src="image.jpg" alt="My Image" width="300" height="200" title="My Image" loading="lazy">
64+
</body>
65+
</html>
66+
```
67+
68+
<BrowserWindow url="https://.../image-attributes.html">
69+
<>
70+
<h1>Image Attributes</h1>
71+
<img src="/img/image.jpg" alt="My Image" width="300" height="200" title="My Image" loading="lazy" />
72+
</>
73+
</BrowserWindow>
74+
75+
In this example, we've set the width and height of the image to `300` and `200` pixels, respectively. We've also specified a title for the image and set the `loading` attribute to `lazy` to improve page loading performance.
76+
77+
## HTML Picture Element
78+
79+
The `<picture>` element is used to provide multiple sources for an image based on different conditions, such as screen size, resolution, or image format. This allows you to deliver the most appropriate image to the user's device, improving performance and user experience.
80+
81+
Here's an example of using the `<picture>` element to provide different image sources for different screen sizes:
82+
83+
```html title="picture-element.html"
84+
<!DOCTYPE html>
85+
<html>
86+
<head>
87+
<title>Picture Element</title>
88+
</head>
89+
90+
<body>
91+
<h1>Picture Element</h1>
92+
<picture>
93+
<source media="(min-width: 768px)" srcset="large.jpg">
94+
<source media="(min-width: 480px)" srcset="medium.jpg">
95+
<img src="small.jpg" alt="My Image">
96+
</picture>
97+
</body>
98+
</html>
99+
```
100+
101+
<BrowserWindow url="https://.../picture-element.html">
102+
<>
103+
<h1>Picture Element</h1>
104+
<picture>
105+
<source media="(min-width: 768px)" srcset="/img/large.jpg" />
106+
<source media="(min-width: 480px)" srcset="/img/medium.jpg" />
107+
<img src="/img/small.jpg" alt="My Image" />
108+
</picture>
109+
</>
110+
</BrowserWindow>
111+
112+
In this example, we've used the `<picture>` element to provide three different image sources: `small.jpg`, `medium.jpg`, and `large.jpg`. The browser will choose the most appropriate image based on the screen size of the device.
113+
114+
## Responsive Images
115+
116+
Responsive images are images that adapt to different screen sizes and resolutions, providing an optimal viewing experience on various devices. To create responsive images, you can use the `srcset` and `sizes` attributes with the `<img>` tag or the `<picture>` element.
117+
118+
Here's an example of using the `srcset` and `sizes` attributes to create a responsive image:
119+
120+
```html title="responsive-image.html"
121+
<!DOCTYPE html>
122+
<html>
123+
<head>
124+
<title>Responsive Image</title>
125+
</head>
126+
127+
<body>
128+
<h1>Responsive Image</h1>
129+
<img src="image.jpg" alt="My Image" srcset="image-2x.jpg 2x, image-3x.jpg 3x" sizes="(max-width: 600px) 100vw, 50vw">
130+
</body>
131+
</html>
132+
```
133+
134+
<BrowserWindow url="https://.../responsive-image.html">
135+
<>
136+
<h1>Responsive Image</h1>
137+
<img src="/img/image.jpg" alt="My Image" srcset="/img/image-2x.jpg 2x, /img/image-3x.jpg 3x" sizes="(max-width: 600px) 100vw, 50vw" />
138+
</>
139+
</BrowserWindow>
140+
141+
In this example, we've specified three different image sources (`image.jpg`, `image-2x.jpg`, and `image-3x.jpg`) using the `srcset` attribute. We've also defined the sizes of the image for different viewports using the `sizes` attribute.
142+
143+
## Image Formats
144+
145+
When adding images to your website, it's essential to choose the right image format to ensure optimal performance and quality. The most common image formats used on the web are JPEG, PNG, GIF, and SVG. Each format has its advantages and use cases:
146+
147+
- **JPEG (Joint Photographic Experts Group)**: Ideal for photographs and images with complex colors. JPEG images are compressed, which reduces file size but may result in some loss of quality.
148+
- **PNG (Portable Network Graphics)**: Suitable for images with transparency or sharp edges, such as logos and icons. PNG images support lossless compression, preserving image quality.
149+
- **GIF (Graphics Interchange Format)**: Used for simple animations and images with a limited color palette. GIF images support animation and transparency but have limited color depth.
150+
- **SVG (Scalable Vector Graphics)**: Ideal for logos, icons, and illustrations. SVG images are vector-based, which means they can be scaled to any size without losing quality.
151+
152+
When choosing an image format, consider factors such as image content, file size, transparency, and browser support to ensure the best performance and user experience.
153+
154+
## Image Optimization
155+
156+
Image optimization is the process of reducing the file size of images without compromising quality. Optimized images load faster, consume less bandwidth, and improve page loading performance. Here are some tips for optimizing images on your website:
157+
158+
- **Choose the right image format**: Select the appropriate image format based on the content and requirements of the image.
159+
- **Resize images**: Scale images to the correct dimensions to avoid unnecessary file size.
160+
- **Compress images**: Use image compression tools to reduce file size without losing quality.
161+
- **Optimize alt text**: Provide descriptive and concise alternative text for images to improve accessibility and SEO.
162+
- **Lazy loading**: Load images only when they enter the viewport to reduce initial page load time.
163+
- **CDN**: Use a content delivery network (CDN) to cache and deliver images faster to users around the world.
164+
165+
By optimizing images on your website, you can enhance performance, improve user experience, and boost search engine rankings.
166+
167+
## Image Accessibility
168+
169+
Accessibility is an essential aspect of web design that ensures all users, including those with disabilities, can access and interact with your content. When adding images to your website, it's crucial to consider accessibility best practices to make images accessible to everyone. Here are some tips for creating accessible images:
170+
171+
- **Use descriptive alt text**: Provide meaningful alternative text that describes the content or purpose of the image.
172+
- **Avoid decorative images**: If an image is purely decorative and adds no value to the content, use an empty alt attribute (`alt=""`) to indicate that the image is decorative.
173+
- **Use descriptive filenames**: Choose descriptive filenames for images to provide context and improve accessibility.
174+
- **Provide captions and descriptions**: Include captions or descriptions for images when necessary to provide additional context.
175+
- **Use ARIA attributes**: Use ARIA attributes such as `role="img"` and `aria-label` to enhance the accessibility of images for screen reader users.
176+
177+
By following these accessibility best practices, you can ensure that images on your website are accessible to all users, regardless of their abilities.
178+
179+
## SEO Best Practices for Images
180+
181+
Search engine optimization (SEO) is essential for improving the visibility of your website in search engine results. When adding images to your web pages, it's important to follow SEO best practices to optimize images for search engines. Here are some tips for optimizing images for SEO:
182+
183+
- **Use descriptive filenames**: Choose descriptive filenames that include relevant keywords to improve image search rankings.
184+
- **Optimize alt text**: Provide descriptive and keyword-rich alternative text for images to help search engines understand the content of the image.
185+
- **Add image captions**: Include captions or descriptions for images to provide additional context and improve SEO.
186+
- **Use structured data**: Use structured data markup such as Schema.org to provide search engines with additional information about the image.
187+
- **Optimize image size**: Compress images to reduce file size and improve page loading speed, which can positively impact SEO.
188+
189+
By optimizing images for SEO, you can increase the visibility of your website in image search results and drive more organic traffic to your site.
190+
191+
## Conclusion
192+
193+
Images are a powerful visual element that can enhance the design and user experience of your website. By following best practices for using images in HTML, such as choosing the right image format, optimizing images for performance, and ensuring accessibility and SEO, you can create visually appealing and user-friendly web pages that engage and delight your audience.

docs/html-media/plug-ins.mdx

Whitespace-only changes.

docs/html-media/svg.mdx

Whitespace-only changes.

docs/html-media/video.mdx

Whitespace-only changes.

0 commit comments

Comments
 (0)