A link in a website is an element that you can click on that will take you to another page or file. Most of the time you will link a bit of text to another web page. By default, these links are blue, underlined text – I’m sure that you’ve seen them. Let’s create our own!
First, you will need to create an HTML page that you will be adding your link into. If you don’t know how to do this, see the HTML Basic lesson.
Now, where are you supposed to add all of the content for your page? That’s right, between the body tags. Here is the code to add:
<a href="http://www.webdesign-lessons.com">Web Design Lessons!</a>
Output:
When you click your link it should take you to the homepage of this website. Now, let’s break it down. This element is called a link element or an anchor element (hence the ‘a’). Most web designers will simply refer to this as an ‘a’ element, though. This, like almost all other elements, requires an opening tag (<a href="http://www.webdesign-lessons.com">), and a closing tag (</a>). The content between the two tags is what will appear on the page, which you can click to navigate to the link.
href is what is called an attribute. Different elements have different attributes depending on their functions. Since an anchor element needs to take the user somewhere, we need to tell it where to go. We put that URL in between the quotes after href=. The URL is the value of the attribute. It is important to put your attribute values in quotes, so that the browser doesn’t think that you’re trying to create another attribute.
That’s it! Congratulations, you can now create multiple pages and allow your users to move between them!