Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this chapter we are talking about hyperlinks but I'm going to start out by talking about the anchor tag which is a, and you will see it right here. This is how we create a hyperlink in HTML. Something else is different about this chapter and I want to talk about this really briefly here while I've got your attention. And that is that the files in the Exercise Files folder or for this chapter, I have got them loaded up on my web server and because we are going to be talking about URLs, I would like to show you how the URLs work in the browser.
That way we get live URLs, real URLs, and you can actually run the examples off of the files in my server. They have been up there for years and they will continue to be up there, since the last time that I did a course of this title and this is a refresh of that course. So, I have refreshed that files and they are all still up there and they will continue to be up there. And the files are also included in the Exercise Files folders that came with this course. So, you have got it both ways and you can follow along in your text editor. And so we'll start talking about the anchor tag at this point.
So, the Anchor tag, which is spelled a, is a inline tag and you will see that it's here inline in a paragraph, we've got a paragraph tag wrapped around it, and it ends over here. So, we have got a begin tag and an end tag and we have got two attributes in this one. The first attribute is the href attribute, spelled href, and that contains the URL that you are linking to. And then I have got title attribute here also, which works just like other title attributes when you hover your mouse over the link, it will give you a little of a text tip which will say More about Bill here.
And then the content of the a tag is the text that will be used as the link and normally on a web browser it's underlined, of course, you can change that with CSS, but we'll be using it in a normal mode here so that we can see how this works so. This file is loaded up on my web server and it's at this URL here, so you can type that into your browser to follow along. Now I'm going to switch over to the browser right now, so we can see what this link looks like. So here is that page in the browser and there is the link that we are looking at and you will notice when I hover the mouse over it, it says More about Bill and if you look down at the bottom of the screen, you will see there is the URL that was loaded up in the link in the a tag.
So I'm going to go ahead and click on this link and you will see that the browser loads up my homepage and there's the URL that we clicked on. That's the URL that was in the a tag and so it loaded up this webpage which is my homepage what it looks like today. It will probably be different by the time you look at it because I change it a lot and I'll go ahead and I'll click on the Back link there in the browser and you will see that we are back at the page. Now you will notice something else here, the link has changed color, this means that I have already looked at this pages.
It's the same URL with a different attribute we'll look at that a little bit later. But you will see that the link has changed color because I have already visited that particular URL. These other links are still the other color because we haven't visited those yet and so the link changes color. That's called the visited color and when you look at the attributes in CSS, when we cover CSS you will see that the anchor tag has options for changing the attributes of visited and unvisited links and things like that. So, this is the visited color and it's the unvisited color.
So switching back to the text editor, you will see that this here is what's called a URL. URL stands Uniform Resource Locator and it's a mouthful and it doesn't really mean what it says but in any event, that's what it stands for. It's one of those old traditional Internet things that's just what it is. And so, let's take a look at the parts of a URL, so we can understand how a URL works. The first part of the URL is called the scheme and it's the part to the left of the colon and in the case of webpage URLs, that will always be http.
You will see also, sometimes if you are looking at files on your local computer, you will say file: but usually the ones that we are interested in for the purposes of XHTML and web pages we are going to say http. The next part of the URL after the two slashes is the host name and so this would be something like bw.org for my webpage or lynda.com for hers. It will often have www before it or something else, but that's the host name and that follows the rules of Internet address. It can be an IP address, it can be a DNS name, but that follows those rules and that's what goes in the host part.
And then sometimes you will see a colon and a number and that's a port number, you don't see that very often anymore. And then after all of that, you will see a slash and that's where the path goes and so if we look at this webpage here, you will see up here in the URL we have the scheme which is http and the :// and then we have the host name which bw.org. On my website I don't put the www before it. It was just a choice I made a long time ago and it's always worked for me. I don't have a port number because that's just rare to see anymore, but I do have the slash and then the path.
And so this path, misc/xhtml-links/ hyperlinks.html, that's the path to the file that has the XHTML code in it, and so that is called the file path. After the path, there can be a colon followed by parameters, you don't see that very often. There can be a question mark followed by a query that you do see often for interactive sites. That has to do with the CGI spec and how CGI parameters are passed on a URL. And often times you will see the # sign and a fragment, which takes you to a portion of the page, we'll look at those in a little bit of detail in a later lesson in this chapter.
So those are parts of the URL and that's what a URL is made of. There are actually a few other little parts that you never even see anymore and so we didn't bother to cover those, but it's a pretty complicated spec. But mostly what you see is the scheme, the host, and the path and sometimes you will see query and sometimes you will see a fragment. But for the most part that's all that you will see. So we look at this URL, we now know what these parts are, we have the scheme and we have the host name and we have the path to the file and those are the parts that we'll be concerned about for this lesson.
One other thing that I would like to show you about the anchor tag, before we move on to the next lesson, you will see we have the bw.org link twice and the other one has the target=_blank attribute and so here it is with the target=_blank attribute. What this does is it targets a blank page. When we cover frames we'll see some other uses for the target attribute, but this special word _blank, that creates a blank page for the link. So let's look at how that is used. This is the regular link that we clicked on before and that just takes us to the webpage and it loads it in exactly the same browser window, but when I click on this one and I'm in Firefox, so it will make the new window in tab.
But sometimes in some browsers, it will launch an entirely separate browser window and you will see that it's loaded up the page here in a blank Window. You see we still have the hyperlinks page loaded in the other Window and so in Firefox it does them in tabs and in other browsers, it may just open an entirely separate window. So, that's an option that you will often see. A lot of links on my page I tend to do that with because I want people to come back to this page without having to use their Back button. So, I can just close this tab and that other page is still there.
It's never gone away. So that's the target=_blank attribute and you will see that a lot in anchor tags. So that's how the anchor element works, the a element that's the parts of the URL and you have seen how the link changes on the page when it's been visited and you have seen the target=_blank attribute.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 104735 Viewers
56 Video lessons · 116619 Viewers
71 Video lessons · 85809 Viewers
131 Video lessons · 41055 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.