Skip to content

Commit 65c9618

Browse files
[Edit] HTML: src (#6613)
* [Edit] HTML: src * Add files via upload * fixed lint and format * Update content/html/concepts/attributes/terms/src/src.md * Update content/html/concepts/attributes/terms/src/src.md * Update content/html/concepts/attributes/terms/src/src.md * Format FIxes ---------
1 parent 7b12046 commit 65c9618

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

content/html/concepts/attributes/terms/src/src.md

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@ The **`src`** attribute specifies the location of a digital source, which is typ
1818
## Syntax
1919

2020
```pseudo
21-
<element src="url">
21+
<element src="URL_or_file_path">
2222
```
2323

24+
**Parameters:**
25+
26+
- `src`: Specifies the location of the resource. This can be a URL (absolute or relative) or a file path pointing to the resource.
27+
28+
**Return value:**
29+
30+
The `src` attribute doesn’t "return" anything as it's not a function or method but an attribute. Instead, it points to a digital source (e.g., image, video, audio, etc.) and instructs the browser to load that resource into the HTML element.
31+
2432
`src` can also be used in the following elements:
2533

2634
| HTML Tag | Description |
@@ -32,7 +40,7 @@ The **`src`** attribute specifies the location of a digital source, which is typ
3240
| [`<track>`](https://www.codecademy.com/resources/docs/html/elements/track) | Specifies the subtitles and closed captions for `<audio>` and `<video>` elements. |
3341
| [`<video>`](https://www.codecademy.com/resources/docs/html/elements/video) | Embeds movie clips or other video sources into an HTML file. |
3442

35-
## Example 1: Image
43+
## Example 1: Displaying an Image
3644

3745
The following code snippet below shows how the `<img>` element uses the `src` attribute to display an image called `logo.png`:
3846

@@ -46,9 +54,9 @@ This will display the following image:
4654

4755
> **Note:** When using online images or images from the folders in an IDE workspace, always add `alt` text at the end of the `<img>` element just in case the browser has trouble finding them.
4856
49-
## Example 2: Video
57+
## Example 2: Embedding an External Video
5058

51-
The example below shows how a [video](https://www.codecademy.com/resources/docs/html/videos) element uses the `src` attribute in an embedded `<source>` element to display a video called `codey.mp4`:
59+
The example below shows how a [video](https://www.codecademy.com/resources/docs/html/videos) element uses the `src` attribute in an embedded `<source>` element to display a video called `codey.mp4` from an external source:
5260

5361
```html
5462
<video controls autoplay muted width="560" height="315">
@@ -57,8 +65,44 @@ The example below shows how a [video](https://www.codecademy.com/resources/docs/
5765
</video>
5866
```
5967

60-
The gif below shows how the video would be displayed:
68+
The gif here shows how the video would be displayed:
6169

6270
![HTML src attribute gif](https://raw.githubusercontent.com/Codecademy/docs/main/media/html-src-attribute-video.gif)
6371

64-
> **Note:** This example demonstrates how to display a video from a local source. To display a video from an external source, such as YouTube, use the [`<iframe>`](https://www.codecademy.com/resources/docs/html/elements/iframe) element to embed videos from these platforms.
72+
## Example 3: YouTube Video Embedding using `iframe` element
73+
74+
Here’s an example of embedding a YouTube video using the [`iframe`](https://www.codecademy.com/resources/docs/html/elements/iframe) element:
75+
76+
```html
77+
<iframe
78+
width="560"
79+
height="315"
80+
src="https://www.youtube.com/embed/0QHaxrUkSEU?list=PLFzsFUO-y0HCyF0smKSi0WMhbMR2mqz2V"
81+
frameborder="0"
82+
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
83+
allowfullscreen
84+
></iframe>
85+
```
86+
87+
The following gif showcases how the output of this code would look like:
88+
89+
![HTML YouTube embedded video output gif](https://raw.githubusercontent.com/Codecademy/docs/main/media/youtube-embedded-video-output.gif)
90+
91+
In this example, an embedded YouTube video is added to the webpage using the `iframe` element. The `src` attribute in the `<iframe>` tag contains the YouTube video URL, which points to the embedded version of the video.
92+
93+
## Frequently Asked Questions
94+
95+
### 1. What is the difference between URL and `src` in HTML?
96+
97+
- **URL (Uniform Resource Locator)**: A URL is the address of a resource on the Internet. It specifies the location of a resource (like an image, video, or webpage) using a protocol (e.g., `http://`, `https://`, `ftp://`) followed by the resource's location.
98+
- **`src` (Source) Attribute**: The `src` attribute in HTML specifies the source location of embedded content (such as an image, video, or audio file). It points to a resource's URL or a local file path. The `src` attribute itself does not define a location on its own, but instead uses a URL to point to the location of an external or internal resource.
99+
100+
### 2. When to use `src` in HTML?
101+
102+
You use the `src` attribute when you want to embed external or internal content into an HTML page. Common scenarios include:
103+
104+
- **Images**: To display an image using the `<img>` tag.
105+
106+
```html
107+
<img src="image.jpg" alt="Image description" />
108+
```
5.63 MB
Loading

0 commit comments

Comments
 (0)