Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,460 --> 00:00:03,960
One of the fundamental building blocks
2
00:00:03,960 --> 00:00:06,870
of the internet are hyperlinks
3
00:00:06,870 --> 00:00:09,330
or for short, just links.
4
00:00:09,330 --> 00:00:12,680
So links are what actually enables the internet
5
00:00:12,680 --> 00:00:15,160
to be a worldwide web.
6
00:00:15,160 --> 00:00:17,340
So without links between pages,
7
00:00:17,340 --> 00:00:19,280
there would be no web.
8
00:00:19,280 --> 00:00:20,710
And so let's now learn
9
00:00:20,710 --> 00:00:23,883
how to place links on our own webpages.
10
00:00:25,320 --> 00:00:29,290
Now, we can place links into two big categories.
11
00:00:29,290 --> 00:00:31,360
The first category is links
12
00:00:31,360 --> 00:00:35,740
that point to other pages within our own website.
13
00:00:35,740 --> 00:00:38,400
So let's say that here in our website,
14
00:00:38,400 --> 00:00:39,720
The Code Magazine,
15
00:00:39,720 --> 00:00:41,580
we had another blog post.
16
00:00:41,580 --> 00:00:44,400
So we could then create a link from this page
17
00:00:44,400 --> 00:00:47,080
to that other page, right?
18
00:00:47,080 --> 00:00:49,700
Now, on the other hand, the other category
19
00:00:49,700 --> 00:00:53,920
is links that point to outside of our website.
20
00:00:53,920 --> 00:00:58,090
So for example, if I placed a link to udemy.com here
21
00:00:58,090 --> 00:01:00,670
on this page, then that, of course,
22
00:01:00,670 --> 00:01:03,130
would be a link to the outside
23
00:01:03,130 --> 00:01:05,540
of our website, right?
24
00:01:05,540 --> 00:01:08,090
Now, we do create these two types of links
25
00:01:08,090 --> 00:01:11,100
in the exact same way in HTML
26
00:01:11,100 --> 00:01:14,330
but there's still some kinds of particularities
27
00:01:14,330 --> 00:01:16,140
that we need to be aware of
28
00:01:16,140 --> 00:01:18,860
and so let's now actually start with the second kind
29
00:01:18,860 --> 00:01:21,170
of link that I was describing,
30
00:01:21,170 --> 00:01:24,053
which point outwards of our own website.
31
00:01:25,150 --> 00:01:26,854
So what I have here in the demo
32
00:01:26,854 --> 00:01:30,840
is that here at the end of this part,
33
00:01:30,840 --> 00:01:33,300
so of this what is HTML section,
34
00:01:33,300 --> 00:01:36,323
I have a link to the MDN Web Docs.
35
00:01:37,160 --> 00:01:39,270
So this is basically a website
36
00:01:39,270 --> 00:01:41,550
where you can learn all about HTML
37
00:01:41,550 --> 00:01:43,963
and also CSS and JavaScript.
38
00:01:45,190 --> 00:01:48,225
And actually, I will show you this site a little bit better
39
00:01:48,225 --> 00:01:49,760
in the next section
40
00:01:49,760 --> 00:01:52,340
because it's important as a web developer
41
00:01:52,340 --> 00:01:53,830
to know how to use
42
00:01:53,830 --> 00:01:58,193
and find information here in this web documentations page.
43
00:01:59,380 --> 00:02:03,210
So what we want is to grab the link of that
44
00:02:03,210 --> 00:02:04,630
and so to do that,
45
00:02:04,630 --> 00:02:09,630
just google MDN, which stands for Mozilla Developer Network
46
00:02:10,170 --> 00:02:12,850
and then just HTML.
47
00:02:12,850 --> 00:02:15,620
And the exact URL that we're gonna use here
48
00:02:15,620 --> 00:02:16,764
doesn't really matter.
49
00:02:16,764 --> 00:02:19,640
All we want is to have some URL
50
00:02:19,640 --> 00:02:22,153
that points outside of our own page.
51
00:02:23,260 --> 00:02:24,230
Right?
52
00:02:24,230 --> 00:02:26,350
So let's just grab this one here,
53
00:02:26,350 --> 00:02:28,760
which was the first Google result.
54
00:02:28,760 --> 00:02:31,470
So I'm copying it and again,
55
00:02:31,470 --> 00:02:33,420
keep in mind that this is called a URL.
56
00:02:34,550 --> 00:02:35,410
So as you know,
57
00:02:35,410 --> 00:02:38,010
every single website on the internet
58
00:02:38,010 --> 00:02:39,710
has its own URL
59
00:02:39,710 --> 00:02:41,650
and so that is what we need in order
60
00:02:41,650 --> 00:02:43,893
to create a link to that page.
61
00:02:45,890 --> 00:02:47,270
Okay?
62
00:02:47,270 --> 00:02:50,203
So let's see.
63
00:02:51,740 --> 00:02:56,420
Yeah, we want to put that right here
64
00:02:56,420 --> 00:02:58,783
after this unordered list.
65
00:02:59,760 --> 00:03:00,700
Right?
66
00:03:00,700 --> 00:03:01,833
Let's see in the demo.
67
00:03:02,850 --> 00:03:05,503
Yeah, so right here after the ordered list.
68
00:03:07,030 --> 00:03:07,863
So that's here.
69
00:03:08,862 --> 00:03:12,050
So to create a link in HTML,
70
00:03:12,050 --> 00:03:15,870
we use the a element, which stands for anchor.
71
00:03:15,870 --> 00:03:18,110
So technically, a hyperlink
72
00:03:18,110 --> 00:03:22,570
or a link is actually called anchor in HTML.
73
00:03:22,570 --> 00:03:25,350
So it is an anchor element.
74
00:03:25,350 --> 00:03:26,640
We can close it.
75
00:03:26,640 --> 00:03:28,740
Then we can specify some content
76
00:03:28,740 --> 00:03:32,300
and then we can, or we have to actually close it.
77
00:03:32,300 --> 00:03:34,700
So let's start by doing that.
78
00:03:34,700 --> 00:03:37,400
Now, as for the content of the link,
79
00:03:37,400 --> 00:03:39,920
what we specify here is actually the text
80
00:03:39,920 --> 00:03:42,820
that we want to be displayed on the page.
81
00:03:42,820 --> 00:03:44,663
So the text of the link.
82
00:03:45,590 --> 00:03:48,883
So in this case, that is this MDN Web Docs.
83
00:03:50,170 --> 00:03:51,003
All right?
84
00:03:51,003 --> 00:03:55,730
So MDN Web Docs.
85
00:03:55,730 --> 00:03:58,090
But now, what about the URL
86
00:03:58,090 --> 00:04:00,850
where we want this link to point to?
87
00:04:00,850 --> 00:04:04,623
Well, for that, we need to once again use an attribute.
88
00:04:05,860 --> 00:04:10,860
So in this case, it is the href attribute.
89
00:04:11,270 --> 00:04:13,560
Then equal, double quotes
90
00:04:13,560 --> 00:04:15,730
and then we can simply paste that URL
91
00:04:15,730 --> 00:04:18,210
that we copied right here
92
00:04:18,210 --> 00:04:20,400
and that's actually it.
93
00:04:20,400 --> 00:04:22,023
So if I give it a save now,
94
00:04:22,870 --> 00:04:25,893
and then reload our page here,
95
00:04:27,460 --> 00:04:29,533
then here is our link.
96
00:04:30,660 --> 00:04:32,190
And you see down there,
97
00:04:32,190 --> 00:04:33,690
so here in this corner
98
00:04:33,690 --> 00:04:36,707
that when I hover it, it actually shows me the URL
99
00:04:36,707 --> 00:04:38,530
and then when I click it,
100
00:04:38,530 --> 00:04:40,163
our page goes there.
101
00:04:42,230 --> 00:04:45,820
Great, and so that is actually already the basics
102
00:04:45,820 --> 00:04:48,130
of creating a link.
103
00:04:48,130 --> 00:04:49,943
Very simple, right?
104
00:04:50,980 --> 00:04:52,850
Now, we want this link here
105
00:04:52,850 --> 00:04:56,940
to actually be like inside of this text.
106
00:04:56,940 --> 00:04:59,673
So inside of one more paragraph here.
107
00:05:01,610 --> 00:05:02,600
Right?
108
00:05:02,600 --> 00:05:05,573
So let's create that paragraph.
109
00:05:06,840 --> 00:05:11,193
So you can learn more at,
110
00:05:12,910 --> 00:05:15,710
and then this link here
111
00:05:15,710 --> 00:05:20,680
is basically just a continuation of the text in here.
112
00:05:20,680 --> 00:05:23,380
So inside of this paragraph.
113
00:05:23,380 --> 00:05:25,760
So we can finish our sentence here
114
00:05:25,760 --> 00:05:29,783
and then close up our paragraph as usual.
115
00:05:31,630 --> 00:05:36,490
And so now that looks just like in the original one.
116
00:05:36,490 --> 00:05:37,470
Right?
117
00:05:37,470 --> 00:05:39,580
Now, notice what happens here once again
118
00:05:39,580 --> 00:05:40,783
when I click it.
119
00:05:41,780 --> 00:05:43,940
So you see that we navigated directly
120
00:05:43,940 --> 00:05:47,970
to this page and now our own page disappeared.
121
00:05:47,970 --> 00:05:50,020
So of course, we can go back here
122
00:05:50,020 --> 00:05:51,870
but sometimes what we want to do
123
00:05:51,870 --> 00:05:54,470
is to open a link in a new tab.
124
00:05:54,470 --> 00:05:56,853
So let me also show you how we can do that.
125
00:05:57,861 --> 00:06:00,430
And of course, we don't always want that.
126
00:06:00,430 --> 00:06:02,930
So many times, we actually want the page
127
00:06:02,930 --> 00:06:07,530
to really move to the URL that we specified here
128
00:06:07,530 --> 00:06:09,710
but also sometimes it's useful
129
00:06:09,710 --> 00:06:12,830
to keep the page open and simply open the URL
130
00:06:12,830 --> 00:06:15,380
in a new tab, and we can do that
131
00:06:15,380 --> 00:06:17,683
by specifying the target attribute,
132
00:06:18,940 --> 00:06:20,530
then the quotes as always
133
00:06:20,530 --> 00:06:22,740
and then this one looks a bit weird,
134
00:06:22,740 --> 00:06:26,803
so it's underscore and then blank.
135
00:06:28,490 --> 00:06:30,850
So give that a save
136
00:06:30,850 --> 00:06:33,440
and when we reload, it will look the same
137
00:06:33,440 --> 00:06:36,330
but the behavior should have changed.
138
00:06:36,330 --> 00:06:39,620
And indeed, notice how it opened a new tab
139
00:06:39,620 --> 00:06:42,653
and our original one is still open.
140
00:06:44,170 --> 00:06:45,100
Great.
141
00:06:45,100 --> 00:06:48,450
So that worked and so we have now a link
142
00:06:48,450 --> 00:06:51,510
that points to a URL that is outside
143
00:06:51,510 --> 00:06:53,520
of our own website.
144
00:06:53,520 --> 00:06:55,860
But now about that first scenario
145
00:06:55,860 --> 00:07:00,520
where we want to link to an internal page basically.
146
00:07:00,520 --> 00:07:01,693
Let's do that now.
147
00:07:02,530 --> 00:07:04,310
And going back again to our demo,
148
00:07:04,310 --> 00:07:05,776
we have here this example.
149
00:07:05,776 --> 00:07:09,530
So in the very beginning, right after the main heading,
150
00:07:09,530 --> 00:07:11,677
we have these links here
151
00:07:11,677 --> 00:07:14,680
and so these are supposed to be links
152
00:07:14,680 --> 00:07:18,250
that point to pages that are part of this blog.
153
00:07:18,250 --> 00:07:20,720
So let's now create this first link here,
154
00:07:20,720 --> 00:07:23,570
so blog, and also create a new page
155
00:07:23,570 --> 00:07:25,913
where we can actually link to.
156
00:07:27,230 --> 00:07:28,150
Okay?
157
00:07:28,150 --> 00:07:31,160
And so creating a new page is as simple
158
00:07:31,160 --> 00:07:34,960
as creating a new HTML document.
159
00:07:34,960 --> 00:07:36,960
So let's open up again our sidebar
160
00:07:36,960 --> 00:07:41,190
by clicking here and then we see our explorer here basically
161
00:07:41,190 --> 00:07:42,370
with all the files
162
00:07:43,320 --> 00:07:47,130
and then again, we create a new file in this icon here
163
00:07:47,130 --> 00:07:52,130
and let's call it blog.html this time.
164
00:07:52,300 --> 00:07:55,330
And now we could use this cheat here
165
00:07:55,330 --> 00:07:57,950
to create the HTML structure
166
00:07:57,950 --> 00:08:01,520
but actually, let's practice a little bit here again.
167
00:08:01,520 --> 00:08:03,860
And if you want, you can even pause the video
168
00:08:03,860 --> 00:08:06,370
and type it out on your own
169
00:08:06,370 --> 00:08:08,473
but I will just do it here very fast now.
170
00:08:09,490 --> 00:08:10,323
So html.
171
00:08:11,290 --> 00:08:13,173
Then we need to close it, of course.
172
00:08:18,180 --> 00:08:19,540
Now, inside of the html,
173
00:08:19,540 --> 00:08:22,203
remember, we have the head.
174
00:08:23,810 --> 00:08:26,623
Inside of the head, we have a title usually.
175
00:08:27,690 --> 00:08:32,230
And this one, let's just call it like this, BLOG.
176
00:08:32,230 --> 00:08:36,150
So just uppercase to make it really obvious
177
00:08:38,020 --> 00:08:39,170
and you see that this is really
178
00:08:39,170 --> 00:08:41,800
just a very bare bones structure,
179
00:08:41,800 --> 00:08:43,583
just a head with a title.
180
00:08:45,050 --> 00:08:47,190
And actually, the same for the body,
181
00:08:47,190 --> 00:08:48,840
which remember is the part
182
00:08:48,840 --> 00:08:51,693
that is going to be visible in the browser.
183
00:08:52,970 --> 00:08:55,820
So here I will simply specify an h2 element
184
00:08:57,720 --> 00:08:59,980
and close it also here
185
00:08:59,980 --> 00:09:03,850
and let's call this one BLOG as well.
186
00:09:03,850 --> 00:09:07,253
Okay, ah, we still need to close the body, of course.
187
00:09:11,100 --> 00:09:12,300
And that's it.
188
00:09:12,300 --> 00:09:13,810
Let's give it a save.
189
00:09:13,810 --> 00:09:15,770
And so here we have a very simple,
190
00:09:15,770 --> 00:09:20,550
very bare bones blog HTML document.
191
00:09:20,550 --> 00:09:22,530
But now with that in place,
192
00:09:22,530 --> 00:09:27,180
we can create a hyperlink or a link right here
193
00:09:27,180 --> 00:09:32,180
in this index.html, which will point to that blog.html.
194
00:09:32,530 --> 00:09:35,833
And so the browser will then navigate to that page.
195
00:09:37,300 --> 00:09:39,613
So let's do it right here after the h1.
196
00:09:40,770 --> 00:09:43,623
And so the anchor element.
197
00:09:44,480 --> 00:09:45,877
Then we need the href
198
00:09:48,560 --> 00:09:50,600
and so now what we do here instead
199
00:09:50,600 --> 00:09:52,690
of specifying a URL
200
00:09:52,690 --> 00:09:55,970
is to specify the name of the HTML file
201
00:09:55,970 --> 00:09:57,740
that we want to go to
202
00:09:57,740 --> 00:09:59,780
and so in this case, it is, of course,
203
00:09:59,780 --> 00:10:03,473
this blog.html that we just created.
204
00:10:04,400 --> 00:10:07,270
Then here as the content of the element,
205
00:10:07,270 --> 00:10:08,940
let's just write blog again
206
00:10:09,800 --> 00:10:13,730
and then close it as always.
207
00:10:13,730 --> 00:10:15,340
Give it a save.
208
00:10:15,340 --> 00:10:17,720
Here is our beautiful link
209
00:10:17,720 --> 00:10:21,060
and now watch what happens as I click it.
210
00:10:21,060 --> 00:10:23,640
Bam, we are now at blog
211
00:10:23,640 --> 00:10:27,470
and you can see that also here in the URL bar.
212
00:10:27,470 --> 00:10:30,090
So which is now all of this file.
213
00:10:30,090 --> 00:10:31,830
And so all of this path
214
00:10:31,830 --> 00:10:34,403
and then at the end, blog.html.
215
00:10:35,350 --> 00:10:36,690
Right?
216
00:10:36,690 --> 00:10:39,750
Now, to go back, we could, of course, click here
217
00:10:39,750 --> 00:10:42,950
on this back button but what we could also do
218
00:10:42,950 --> 00:10:44,750
is to add a link here,
219
00:10:44,750 --> 00:10:48,770
which simply points back to index.html.
220
00:10:48,770 --> 00:10:49,603
Right?
221
00:10:49,603 --> 00:10:51,923
That sounds like a nice idea, doesn't it?
222
00:10:53,290 --> 00:10:56,580
So let's come back here to blog.html
223
00:10:56,580 --> 00:10:59,020
and as yet another challenge,
224
00:10:59,020 --> 00:11:03,300
now I want you to actually create this link on your own.
225
00:11:03,300 --> 00:11:06,110 line:15%
So pause the video here and create a link
226
00:11:06,110 --> 00:11:09,483 line:15%
that points back to index.html.
227
00:11:11,630 --> 00:11:14,760 line:15%
So did you manage to do that?
228
00:11:14,760 --> 00:11:16,850
Or at least try it?
229
00:11:16,850 --> 00:11:18,433
Well, I sure hope so.
230
00:11:19,400 --> 00:11:21,310
But anyway, of course,
231
00:11:21,310 --> 00:11:23,350
we use the a element again.
232
00:11:23,350 --> 00:11:25,610
Then we specify href
233
00:11:25,610 --> 00:11:29,560
and well, to go back, we just say index.html.
234
00:11:32,296 --> 00:11:34,680
And then here we can specify any text,
235
00:11:34,680 --> 00:11:36,570
which I didn't tell you which one
236
00:11:36,570 --> 00:11:38,493
because it doesn't really matter.
237
00:11:39,400 --> 00:11:42,860
Let's just say back to home
238
00:11:42,860 --> 00:11:44,650
or something like that.
239
00:11:44,650 --> 00:11:46,093
Give it a save.
240
00:11:47,230 --> 00:11:49,330
And now once we reload it,
241
00:11:49,330 --> 00:11:51,640
we have our link, we can click it
242
00:11:51,640 --> 00:11:54,120
and so now we can basically go back
243
00:11:54,120 --> 00:11:56,270
and forth between these two pages
244
00:11:56,270 --> 00:11:58,803
because they're now connected through these links.
245
00:11:59,690 --> 00:12:01,010
So we can go to the blog,
246
00:12:01,010 --> 00:12:05,750
we can go back and forth and so on and so forth.
247
00:12:05,750 --> 00:12:08,840
All right, so let's close up this one here.
248
00:12:08,840 --> 00:12:10,890
We don't need it anymore.
249
00:12:10,890 --> 00:12:12,770
And just to finish,
250
00:12:12,770 --> 00:12:15,280
we can also actually specify a link
251
00:12:15,280 --> 00:12:17,260
that doesn't go anywhere.
252
00:12:17,260 --> 00:12:19,010
So let me show that to you as well.
253
00:12:22,220 --> 00:12:25,060
So let's just write the content first
254
00:12:25,060 --> 00:12:28,700
and here I have Challenges I think
255
00:12:30,770 --> 00:12:31,830
in the demo.
256
00:12:31,830 --> 00:12:35,063
So we have Challenges Flexbox and CSS Grid.
257
00:12:37,020 --> 00:12:38,680
So that's Challenges
258
00:12:38,680 --> 00:12:40,467
but watch what happens now
259
00:12:40,467 --> 00:12:43,483
when I reload the page like this.
260
00:12:45,090 --> 00:12:48,570
So you see that it only says challenge
261
00:12:48,570 --> 00:12:51,260
but notice how it's just normal text.
262
00:12:51,260 --> 00:12:53,800
It's not blue and not underlined,
263
00:12:53,800 --> 00:12:56,980
so it's clearly not a link, right?
264
00:12:56,980 --> 00:13:00,190
So even though it is actually an anchor element
265
00:13:00,190 --> 00:13:03,190
but what makes an anchor element really a link
266
00:13:03,190 --> 00:13:05,800
is the href property.
267
00:13:05,800 --> 00:13:08,130
And so we really need to specify it,
268
00:13:08,130 --> 00:13:10,350
otherwise it is not a link at all.
269
00:13:10,350 --> 00:13:12,178
It is then just an anchor,
270
00:13:12,178 --> 00:13:14,423
which is not really useful.
271
00:13:16,140 --> 00:13:19,510
But what if we don't want this to point anywhere
272
00:13:19,510 --> 00:13:21,200
as I was saying?
273
00:13:21,200 --> 00:13:22,880
Well, the solution to that
274
00:13:22,880 --> 00:13:26,930
is to specify this hash symbol right here.
275
00:13:26,930 --> 00:13:28,370
Right?
276
00:13:28,370 --> 00:13:30,800
So if I now save it and reload,
277
00:13:30,800 --> 00:13:34,610
then we are back to this being a link actually.
278
00:13:34,610 --> 00:13:36,280
It just doesn't point anywhere.
279
00:13:36,280 --> 00:13:39,190
What happens when you click on this link
280
00:13:39,190 --> 00:13:41,790
is that basically it goes back to the top
281
00:13:41,790 --> 00:13:44,740
of this current page, okay?
282
00:13:44,740 --> 00:13:46,460
And a little bit later in the course,
283
00:13:46,460 --> 00:13:48,153
we will actually make use
284
00:13:48,153 --> 00:13:50,770
of this behavior but for now,
285
00:13:50,770 --> 00:13:51,940
I just want you to know
286
00:13:51,940 --> 00:13:54,350
that this is how we can specify links
287
00:13:54,350 --> 00:13:57,470
when we don't have any URL yet for them
288
00:13:57,470 --> 00:13:59,180
or don't have any page.
289
00:13:59,180 --> 00:14:01,793
So basically, this is like a placeholder link.
290
00:14:03,290 --> 00:14:04,123
Okay?
291
00:14:04,123 --> 00:14:06,380
And so let's just copy this here twice.
292
00:14:06,380 --> 00:14:08,360
There's no need to write it again.
293
00:14:08,360 --> 00:14:09,470
But of course, if you want,
294
00:14:09,470 --> 00:14:10,773
you can write it again.
295
00:14:11,810 --> 00:14:15,323
So just for this Flexbox and CSS Grid.
296
00:14:16,170 --> 00:14:18,090
So just to make that navigation look
297
00:14:18,090 --> 00:14:20,683
a bit more like complete.
298
00:14:22,240 --> 00:14:23,450
But all of these link,
299
00:14:23,450 --> 00:14:25,263
they should not point anywhere.
300
00:14:27,280 --> 00:14:30,410
Okay, and this is how you specify links
301
00:14:30,410 --> 00:14:35,410
or hyperlinks or anchors as we can also call them in HTML.
302
00:14:36,140 --> 00:14:38,240
So this is a really important part
303
00:14:38,240 --> 00:14:41,040
of the web as I said in the very beginning
304
00:14:41,040 --> 00:14:44,100
and so make sure that you understand how they work
305
00:14:44,100 --> 00:14:47,283
and how we place them inside our own webpages.
20826
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.