You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/html/concepts/attributes/terms/src/src.md
+50-6Lines changed: 50 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -18,9 +18,17 @@ The **`src`** attribute specifies the location of a digital source, which is typ
18
18
## Syntax
19
19
20
20
```pseudo
21
-
<element src="url">
21
+
<element src="URL_or_file_path">
22
22
```
23
23
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
+
24
32
`src` can also be used in the following elements:
25
33
26
34
| HTML Tag | Description |
@@ -32,7 +40,7 @@ The **`src`** attribute specifies the location of a digital source, which is typ
32
40
|[`<track>`](https://www.codecademy.com/resources/docs/html/elements/track)| Specifies the subtitles and closed captions for `<audio>` and `<video>` elements. |
33
41
|[`<video>`](https://www.codecademy.com/resources/docs/html/elements/video)| Embeds movie clips or other video sources into an HTML file. |
34
42
35
-
## Example 1: Image
43
+
## Example 1: Displaying an Image
36
44
37
45
The following code snippet below shows how the `<img>` element uses the `src` attribute to display an image called `logo.png`:
38
46
@@ -46,9 +54,9 @@ This will display the following image:
46
54
47
55
> **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.
48
56
49
-
## Example 2: Video
57
+
## Example 2: Embedding an External Video
50
58
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:
> **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:
The following gif showcases how the output of this code would look like:
88
+
89
+

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.
0 commit comments