Starting Now: iLoveCoding courses are completely FREE. No login or signup required.

Learn to link webpages via the anchor <a> element

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

FREELevel: Beginner4:04 mins
Course content
Lessons #1: Tools you need for the HTML/CSS course FREE
1:59 mins
Lessons #2: Overview of the VS Code Text Editor FREE
4:57 mins
Lessons #3: Code your first webpage FREE
3:59 mins
Lessons #4: What is HTML Really? FREE
3:16 mins
Lessons #5: What does HTML look like? FREE
2:46 mins
Lessons #6: HTML Elements FREE
7:20 mins
Lessons #7: HTML Elements - Continued FREE
3:36 mins
Lessons #8: Common HTML Elements (Cheatsheet included) FREE
3:26 mins
Lessons #9: HTML is a forgiving language FREE
3:47 mins
Lessons #10: Basic Markup of HTML FREE
5:18 mins
Lessons #11: The <h1>...<h6>, <i> and <strong> elements FREE
5:18 mins
Lessons #12: Learn to link webpages via the anchor <a> element FREE
4:04 mins
Lessons #13: Relative vs Absolute Paths - linking continued FREE
5:50 mins
Lessons #14: <div> and <span> elements FREE
6:36 mins
Lessons #15: Making lists in HTML via <ul>, <ol> and <li> elements FREE
5:36 mins
Lessons #16: Making nested lists + Homework FREE
4:31 mins
Lessons #17: Adding special characters in your webpage FREE
5:50 mins
Lessons #18: Emmet shortcuts and code comments FREE
3:37 mins
Lessons #19: <meta> elements and what they are about FREE
3:19 mins
Lessons #20: <meta> description and keyword elements for SEO FREE
3:33 mins
Lessons #21: <blockquote> and <pre> elements for special text formatting FREE
5:43 mins
Lessons #22: Adding images with the <img> element FREE
5:11 mins
Lessons #23: Using <video> and <audio> elements FREE
5:56 mins
Lessons #24: Semantic Elements + Homework FREE
4:26 mins
Lessons #25: Intro to CSS - Making the webpages beautiful FREE
4:22 mins
Lessons #26: Intro to CSS continued FREE
4:10 mins
Lessons #27: <style> element & using CSS selectors FREE
5:38 mins
Lessons #28: Organize your CSS is its own file FREE
4:55 mins
Lessons #29: CSS id selector (# hash sign) FREE
4:20 mins
Lessons #30: CSS class selector (. dot sign) FREE
3:52 mins
Lessons #31: Select all elements with asterisk (*) selector FREE
0:58 mins
Lessons #32: Using multiple selectors together (using comma and more) FREE
4:40 mins
Lessons #33: CSS Combinators selectors (~ + > etc.) FREE
7:50 mins
Lessons #34: Pseudo Selectors (:visited: :hover :active :focus) FREE
6:04 mins
Lessons #35: Chrome Developer Tools - Intro FREE
6:43 mins
Lessons #36: Colors in CSS FREE
3:19 mins
Lessons #37: Apply multiple CSS classes + write notes with code comments FREE
2:59 mins
Lessons #38: Fonts: Change & add custom fonts FREE
6:20 mins
Lessons #39: Background CSS Property. Change color, images and more FREE
7:39 mins
Lessons #40: Common CSS Units - (px, em, rem, %) FREE
7:01 mins
Lessons #41: Common CSS Units - (rem) FREE
2:39 mins
Lessons #42: CSS Margin and Padding FREE
9:49 mins
Lessons #43: CSS border property FREE
4:00 mins
Lessons #44: CSS border style FREE
2:05 mins
Lessons #45: Size elements with 'width' and 'height' property FREE
3:21 mins
Lessons #46: Use 'box-sizing' for more control on element sizing FREE
3:43 mins
Lessons #47: 'border-radius' Curve borders and make custom shapes. FREE
7:58 mins
Lessons #48: <div> vs <span> the real difference FREE
4:36 mins
Lessons #49: Using 'display' property of CSS & 'inline-block' FREE
3:19 mins
Lessons #50: 'float' & 'clear' property - Moving elements around. FREE
4:38 mins
Lessons #51: Hide content with `overflow`, `visibility` and `display` property FREE
3:36 mins
Lessons #52: Clearfix: Hack to fix webpage spacing issue FREE
3:51 mins
Lessons #53: Project: Blog Design - Create beautiful looking website FREE
5:20 mins
Lessons #54: Project: Blog Design (Part 2/7) - Layout the HTML FREE
9:09 mins
Lessons #55: Project: Blog Design (Part 3/7) - Styling the header FREE
4:01 mins
Lessons #56: Project: Blog Design (Part 4/7) - Styling main and footer area FREE
4:02 mins
Lessons #57: Project: Blog Design (Part 5/7) - Styling sidebar FREE
3:10 mins
Lessons #58: Project: Blog Design (Part 6/7) - Styling articles FREE
2:17 mins
Lessons #59: Project: Blog Design (Part 7/7) - Additional Pages FREE
5:13 mins
Lessons #60: 'position' - Control element position within your page FREE
8:10 mins
Lessons #61: Project: Coupon (using `absolute` & `relative` position) FREE
5:21 mins
Lessons #62: CSS Flexbox & CSS Grid - More layout methods FREE
3:02 mins
Lessons #63: CSS Priority Order FREE
6:04 mins
Lessons #64: Additional Resources - Codepen + HTML Cheatsheet FREE
5:18 mins
Lessons #65: <table> Making tables in HTML FREE
5:32 mins
Lessons #66: <table> Making tables in HTML continued FREE
2:41 mins
Lessons #67: <iframe> Embedding other webpages in your webpage FREE
4:16 mins
Lessons #68: Creating forms and understanding how they work FREE
11:17 mins
Lessons #69: Creating form - continued FREE
6:41 mins
Lessons #70: Using external CSS libraries in your projects FREE
6:42 mins
Lessons #71: Conclusion and next steps FREE
3:28 mins
πŸ˜‡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.

Become a confident software developer with mentor support!
Get Started
Already have an account? Please Login