Links (or Hyperlinks) are HTML elements by which we can open other pages, jump from one document to another or to another point on the same page. They are very important in creating web pages.

  - General Syntax:
<a href="url" title="Link title">Link text</a>
- "a" - is the HTML element to create links
- "href" - specifies the destination of a link
- "url" - (Uniform Resource Locator) is the address of the link (the page that will be open).
            For example:
- "title" - specifies a title for the hyperlink (a hidden text that only appears when the mouse is positioned over the link)
- "Link text" - is the text that appears in the web page, which must be clicked on. This text can be replaced with an image:
<a href="url" title="Link title"><img src="image_address" alt="Title" /></a>
When you move the cursor over a link in a Web page, the arrow will turn into a little hand.

You can create two types of hyperlinks:

1. Hyperlink to another document (called external links).
2. A bookmark inside a document, by using the "name" attribute (called internal links).

External Links

These type of links open external documents. The URL address added at the "href" attribute can be of two types:
  1) Absolute path - the URL contains the domain name too.
<a href="" title="Free courses">Vist</a>

  2) Relative path - the URL contains only the name of the document (and the path to the folder if the document is in another directory).
<!-- The index.php page is in the same folder -->
<a href="index.php" title="Free courses">Home</a>

<!-- The page.html is up one directory -->
<a href="../page.html" title="Free courses">Text</a>

<!-- The page.html is in a sub-directory -->
<a href="folder/page.html" title="Free courses">Text</a>
- Relative path is used only with documents which are on the same server.

Internal Links

An internal link allows you to jump to another section on the same web page, so it basically scrolls the page up or down to the desired location.
    To create an internal link you must follow these steps:
  1. Write the following code to the target, a bookmark which marks the location where you jump and is on the same web page.
    • <a name="word"> </a>
      - the "name" attribute indicates the target for the link
      - the "word" can be any word, will be used in the "href" attribute
  2. Create the link, anywhere in the page, using for "href" attribute the same "word" specified in the "name" attribute.
    • <a href="#word">Link text</a>

<a href="#next1">Next section</a>
<p>Lots of paragraphs<br />

<a name="next1"> </a>
<p>Here is the next section.</p>

Bookmarks are not displayed, they are invisible to the reader.
The HTML5 standard suggest using the "id" attribute instead of the "name" attribute for specifying the name of an anchor.

• You can combine the external hyperlinks with internal links, to jump to a certain section of another document, where you have added the bookmark.
<a href="page_url#bookmark" title="A title">Link text</a>

• The <a> tag can have a target attribute, which specifies where to open the linked document.
There are 4 special "target" values:
The next example will open the linked document in a new browser window or a new tab:
<a href="" title="Free courses" target="_blank">Free courses</a>

Daily Test with Code Example

Which tag is a block element?
<div> <img> <span>
<div>Web Programming and Development</div>
Which CSS code displays the text underlined?
font-style: italic; text-decoration: underline; font-weight: 500;
h2 {
  text-decoration: underline;
Click on the JavaScript function that can access other function after a specified time.
insertBefore() setTimeout() querySelector()
function someFunction() { alert(""); }
setTimeout("someFunction()", 2000);
Click on the instruction that returns the number of items of a multidimensional array in PHP.
count($array) count($array, 1) strlen()
$food = array("fruits" => array("banana", "apple"), "veggie" => array("collard", "pea"));
$nr_food = count($food, 1);
echo $nr_food;       // 6
Hyperlinks - Links

Last accessed pages

  1. innerHTML and outerHTML to Get and Replace HTML content (10944)
  2. Convert JSON in JavaScript (4542)
  3. Upload Script for Gallery of Images and Audio files (6282)
  4. Drag Racer V3 (2302)
  5. Butterfly Kyodai (13820)

Top accessed pages

  1. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (50906)
  2. Read Excel file data in PHP - PhpExcelReader (39764)
  3. PHP-MySQL free course, online tutorials PHP MySQL code (37936)
  4. Get Attribute (ID, Class, Name, Title, Src) with jQuery (34200)
  5. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (31686)