Learn to link webpages via the anchor <a> element

Link your webpages with internal and external pages - on the internet.

  • Beginner
  • 4 min

Course content

71 lessons
  1. 1Tools you need for the HTML/CSS course1:59
  2. 2Overview of the VS Code Text Editor4:57
  3. 3Code your first webpage3:59
  4. 4What is HTML Really?3:16
  5. 5What does HTML look like?2:46
  6. 6HTML Elements7:20
  7. 7HTML Elements - Continued3:36
  8. 8Common HTML Elements (Cheatsheet included)3:26
  9. 9HTML is a forgiving language3:47
  10. 10Basic Markup of HTML5:18
  11. 11The <h1>...<h6>, <i> and <strong> elements5:18
  12. 12Learn to link webpages via the anchor <a> element4:04
  13. 13Relative vs Absolute Paths - linking continued5:50
  14. 14<div> and <span> elements6:36
  15. 15Making lists in HTML via <ul>, <ol> and <li> elements5:36
  16. 16Making nested lists + Homework4:31
  17. 17Adding special characters in your webpage5:50
  18. 18Emmet shortcuts and code comments3:37
  19. 19<meta> elements and what they are about3:19
  20. 20<meta> description and keyword elements for SEO3:33
  21. 21<blockquote> and <pre> elements for special text formatting5:43
  22. 22Adding images with the <img> element5:11
  23. 23Using <video> and <audio> elements5:56
  24. 24Semantic Elements + Homework4:26
  25. 25Intro to CSS - Making the webpages beautiful4:22
  26. 26Intro to CSS continued4:10
  27. 27<style> element & using CSS selectors5:38
  28. 28Organize your CSS is its own file4:55
  29. 29CSS id selector (# hash sign)4:20
  30. 30CSS class selector (. dot sign)3:52
  31. 31Select all elements with asterisk (*) selector0:58
  32. 32Using multiple selectors together (using comma and more)4:40
  33. 33CSS Combinators selectors (~ + > etc.)7:50
  34. 34Pseudo Selectors (:visited: :hover :active :focus)6:04
  35. 35Chrome Developer Tools - Intro6:43
  36. 36Colors in CSS3:19
  37. 37Apply multiple CSS classes + write notes with code comments2:59
  38. 38Fonts: Change & add custom fonts6:20
  39. 39Background CSS Property. Change color, images and more7:39
  40. 40Common CSS Units - (px, em, rem, %)7:01
  41. 41Common CSS Units - (rem)2:39
  42. 42CSS Margin and Padding9:49
  43. 43CSS border property4:00
  44. 44CSS border style2:05
  45. 45Size elements with 'width' and 'height' property3:21
  46. 46Use 'box-sizing' for more control on element sizing3:43
  47. 47'border-radius' Curve borders and make custom shapes.7:58
  48. 48<div> vs <span> the real difference4:36
  49. 49Using 'display' property of CSS & 'inline-block'3:19
  50. 50'float' & 'clear' property - Moving elements around.4:38
  51. 51Hide content with `overflow`, `visibility` and `display` property3:36
  52. 52Clearfix: Hack to fix webpage spacing issue3:51
  53. 53Project: Blog Design - Create beautiful looking website5:20
  54. 54Project: Blog Design (Part 2/7) - Layout the HTML9:09
  55. 55Project: Blog Design (Part 3/7) - Styling the header4:01
  56. 56Project: Blog Design (Part 4/7) - Styling main and footer area4:02
  57. 57Project: Blog Design (Part 5/7) - Styling sidebar3:10
  58. 58Project: Blog Design (Part 6/7) - Styling articles2:17
  59. 59Project: Blog Design (Part 7/7) - Additional Pages5:13
  60. 60'position' - Control element position within your page8:10
  61. 61Project: Coupon (using `absolute` & `relative` position)5:21
  62. 62CSS Flexbox & CSS Grid - More layout methods3:02
  63. 63CSS Priority Order6:04
  64. 64Additional Resources - Codepen + HTML Cheatsheet5:18
  65. 65<table> Making tables in HTML5:32
  66. 66<table> Making tables in HTML continued2:41
  67. 67<iframe> Embedding other webpages in your webpage4:16
  68. 68Creating forms and understanding how they work11:17
  69. 69Creating form - continued6:41
  70. 70Using external CSS libraries in your projects6:42
  71. 71Conclusion and next steps3:28
πŸ˜‡Important: This course is FREE and always will be πŸ™Œ. Feel free to share it with friends. 🎁

HTML Cheatsheet

CSS Cheatsheet

HTML CSS Cheatsheet thumb

Video Lesson Transcript

All right, now we are going to learn about a new element, called <a> element or anchor element. This is used basically to link one page to another, so let's do that.

The <a> Anchor Element

So over here I am going to simply remove a lot of the previous code we did, so our page is simple. It's easier for us to read the code.

I am going to simply create an <a> element, and inside I am going to put some text as children. For the text I am gonna to say "Click me please".

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>
      This is my first page
    </title>
  </head>
  <body>
    <h1>Hi My name is Aziz</h1>
    <a href="">Click me please</a>
  </body>
</html>

Now you notice that when I created this element, VS Code automatically pre-populated this particular attribute called href.

Now basically what happens is that whenever some user clicks on this particular text, this page is going to go to whatever is mentioned in the href attribute.

So let's say if you want to go to Google.com, you are going to simply put "https://www.google.com" as a value of the href attributre like such:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>
      This is my first page
    </title>
  </head>
  <body>
    <h1>Hi My name is Aziz</h1>
    <a href="https://www.google.com">Click me please</a>
  </body>
</html>

Save, refresh, and you see that the link is over here.

Example of usage of the <a> element

Now if I hover over the text, I will see on my footer that it says the link, which is google.com. When you click the link, you will see the loading sign, and now it goes to google.com.

Result after clicking the <a> element

Simple as that.

The target Attribute

Now this element has multiple options; let's say if I want to open this particular URL a new tab or a new window, not the same page. There is an option for that, which is called target.

So I do target="", and the value you want to provide is _blank, like such:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>
      This is my first page
    </title>
  </head>
  <body>
    <h1>Hi My name is Aziz</h1>
    <a target="_blank" href="https://www.google.com">Click me please</a>
  </body>
</html>

Now when you do that you refresh, and when you click the link you will see that it opens in a new tab.

Result after clicking the <a> element with the '_blank' value for the target

This is very handy. Let's say if you have a web site, and you want to link to external pages for example Google.

So let's say you are on your home page which is your personal web site, and you want to link to an external page; that is when this thing comes handy, and you do not want people to leave your web site.

This is actually not a good practice to make all these links like that, but it's an option you have.

Internal Links

Now one more thing that I want to tell you, is that you cannot just link from the element to external pages, but it can also be internal pages of your web site.

So let's say I am going to create a new page inside our web site. I am going to just simply create an about page. I am going to simply write some basic HTML.

I am going to basically just copy the previous code from (index.html) and paste it in our about page. The title is going to be "about", and I am going to put an <h1> with the text "this is my about page".

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>
      About
    </title>
  </head>
  <body>
    <h1>This is my about page</h1>
  </body>
</html>

And now if I want to link from the home page to the about one, I can simply create another link.

I am going to mention the name of that location where this particular page lives. So since this page called about and it's in the same directory as the index page, I can simply put in about.html, and for the text I can say "Go to about".

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>
      About
    </title>
  </head>
  <body>
    <h1>This is my about page</h1>

    <a href="about.html">Go to about</a>
  </body>
</html>

Save, refresh, and now you see that link is over here.

Internally linking pages with the <a> element

Now, if I click this link it'll go to the About page, and from the About page we need to go back to the Home page.

So I am going to create a link that directs to "index.html", and for the text I am going to say "Go to home".

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>
      About
    </title>
  </head>
  <body>
    <h1>This is my about page</h1>
    <a href="index.html">Go to home</a> 
  </body>
</html>

Save, refresh, and now "Go to home" goes over here:

Anchor link from the 'about' to the 'home' page

So that's pretty much it for this video about linking via the <a> element, and now in the next video I am going to tell you a little bit more about this href linking strategy.

All right, I am going to talk to you in the next video.