HTML Links

HTML Links
  • HTML Links are found in nearly all web pages. Links allow users to click their way from page to page.
  • The HTML <a> tag defines a hyperlink, The most important attribute of the <a> element is the href attribute, which indicates the link's destination. The link text is the part that will be visible to the reader.Clicking on the link text, will send the reader to the specified URL address.
  • Syntax
  • <a href="url">link text</a>

  • Example
  • <a href="https://phpcoderspoint.com">phpcoderspoint.com</a>

    Output:

  • links will appear as follows in all browsers.
  • An unvisited link is underlined and blue
  • A visited link is underlined and purple
  • An active link is underlined and red
HTML Links - The target Attribute
  • By default, the linked page will be displayed in the current browser window. To change this, you must specify another target for the link.
  • The target attribute specifies where to open the linked document.
    • _self - Default. Opens the document in the same window/tab as it was clicked
    • _blank - Opens the document in a new window or tab
    • _parent - Opens the document in the parent frame
    • _top - Opens the document in the full body of the window
  • Example

<a href="https://phpcoderspoint.com" target="_blank">Visit phpcoderspoint</a>

Output:

Absolute URL
  • Absolute URL (a full web address) in the href attribute.
  • Example

<a href="https://www.google.com/" target="_blank">Google</a>

Output:

Relative URL
  • A local link (a link to a page within the same website) is specified with a relative URL (without the "https://www" part).
  • Example

<a href="/html/introduction_of_html.php">Introduction of HTML</a>
<a href="html_text_editor.php">HTML Editor</a>

Output:


Give a link to Button
  • To use an HTML button as a link, you have to add some JavaScript code, JavaScript allows you to specify what happens at certain events.
  • Example

<button onclick="document.location='index.php'">HTML Tutorial</button>

Output:

Give Titles to Link
  • The title attribute specifies extra information about an element. The information is most often shown as a tooltip text when the mouse moves over the element.
  • Example

<a href="https://phpcoderspoint.com/html/" title="Go to HTML Tutorial">HTML Tutorial</a>

Output:


Link to an Email Address
  • Use mailto inside the href attribute to create a link that opens the user's email program.
  • Example

<a href="mailto:name@example.com">Send email</a>

Output:

Links - Use an Image as a Link
  • To use an image as a link, just put the <img> tag inside the <a> tag.
  • Example

<a href="index.php"><img src="my_img.jpg" alt="HTML tutorial"></a>

Output:

HTML tutorial
Related Posts :