|
Search This Site
|
Creating and Using Links in HTML
If you were navigating by use of the blue underlined text at the bottom of each lesson, or the text to your left then you were using a link. Other links can be found in the top navigation of the page. A link leads ( or re-directs ) you from one location to a next. Links are classified as being either internal or external.
Before each type is explained in more detail, lets be clear on what a link looks like. A link typically looks like this:
Click Here To Go To New2HTML
The Anchor Tag Links are created by using the anchor, <a> tag. The example below shows its use. Example: <a> Click Here To Go To New2HTML </a>
Text placed between the opening and closing anchor tag will appear normal.
This is because the link is incomplete and thus clicking it will not give a result.
In order for the link to work we need to specify a direction ( where it should lead to ).
Continue reading to find out more about this. The href AttributeAnchor tags have a number of attributes including the href (hypertext reference) attribute.
This attribute specifies where clicking the link should carry us.
When you click on a link, the browser redirects the webpage to the location pinpointed by the href attribute.
Without the href attribute the link is basically useless. Following up on the example above we want the link to go to the home page of this website (www.new2html.com):
<a href="http://www.new2html.com"> Click Here To Go To New2HTML </a>
The title Attribute The title attribute allows you to provide a title/description of a link. This title is seen whenever the mouse is placed over the link.
If you scroll up to link examples given above you will have an idea. The title for each of these links is "new2HTML website." Applying the title attribute to our code we get:
<a href="http://www.new2html.com" title="new2HTML website"> Click Here To Go To
New2HTML </a>
The target Attribute The target attribute is used to specify where the link should be opened. The values for the target attribute are, _self and
_blank. The _self value opens the link within the same browser window. The _blank
value opens a completely new browser window. By default, if no target value is specified, links will open within the same browser window. Here's an example:
<a href="http://www.new2html.com" title="new2HTML website" target="_blank">
Click Here To Go To New2HTML </a>
Now that we have an understanding of the anchor tag, the href attribute, the title attribute and the target attribute lets go a bit further and examine
the two type of links that exist, Internal and External links. Internal LinksFrom one location to the next on the same pageOne of the most important aspects of any website is ease of navigation. This is allowing your visitors to have easy access to information.
When a visitor is on your site the primary objective of that visitor is to find what they want and fast.
Links can be provided which "jump" to a specific location on a web page. If you have alot of information on a single web page a link can
go straight to the section that is of interest to the visitor. To produce such a link is a two step process. This is the first step: <a href="#Title1" title="Click to go to Title 1"> Birds </a> <a href="#Title2" title="Click to go to Title 2"> Trees </a> <a href="#Title3" title="Click to go to Title 3"> Flowers </a>
After setting the unique id, the second step involves assigning that id to the precise location on the page that we want the link to go to when it
is clicked. Like this: <h4 id="Title1"> Birds </h4> <h4 id="Title2"> Trees </h4> <h4 id="Title3"> Flowers </h4> Take note of the id attribute used in the above code snippet. It has the value of the id previously created without
the number sign ( # ). Link from page to pageA link may redirect you to a different location on the same website but not on the same webpage.
An example would be the navigation from one page to the next on this website via the "Next Lesson" or the "Previous Lesson" links below
( at the bottom of the page ).
<a href="Page2.html"> Page 2 </a>
If you have an html page contained in a separate folders (sub folders) from the one to which you are working in then you need to specify the name
of that folder before the name of the html file.
Example:
<a href="Folder1/page7.html"> Page 7 </a>
<a href="../page3.html"> Page 3 </a>
../ tells the browser to search the previous folder for the page. It is important to always spell the file names exactly as they appear when
writing them as your href value. External LinksLinks to a next website Sometimes you may want to link to a next website separate from your own. To do this the href attribute is given the value of the web address
you want to go to.
If there was such a website as www.nuffmoney123z.com we could provide a link to that site. When the link is clicked the website would come up.
For such links the href value would become:
<a href="http://www.nuffmoney123z.com"> </a>
Links for email Links can be used to send emails. For example if there existed an email such as youremail@whatevever.com, then a link could be provided.
Observe the example below:
<a href="mailto: youremail@whatever.com"> Send Me An Email! </a>
Clicking the link in the example should have opened your default email service (such as Outlook Express).
Note that this type of link only works if you have a default email program
already installed on your computer.
The mailto attribute is used to specify the recipients email.
Previous Lesson - Lists
Next Lesson - Images
|
|
© Copyright 2010 | All Rights Reserved
|