Basic Hyperlinks:
Syntax:<a href="url">Link Text</a>
<a>
: The anchor element.- href: Attribute specifying the URL of the destination page.
- Link Text: Text displayed as the hyperlink.
Example:
<a href="https://www.example.com">Visit Example Website</a>
- This creates a hyperlink that, when clicked, takes the user to the "https://www.example.com" website.
Relative URLs:
Relative URLs are URLs that are relative to the current page's URL. They are useful when linking to pages within the same website.
Example:
<a href="about.html">About Us</a>
This creates a link to the "about.html" page within the same directory as the current page.
Anchor Links (Internal Page Links):
Anchor links are used to navigate within the same page or to specific sections within a page.
Syntax:
<a href="#section-id">Link Text</a>
Example:
<a href="#contact">Contact Us</a>
This creates a link that, when clicked, scrolls the page to the element with the id "contact."
Opening Links in New Windows or Tabs:
Syntax:
<a href="url" target="_blank">Link Text</a>
The target="_blank" attribute-value pair opens the linked document in a new window or tab.
Example:
<a href="https://www.example.com" target="_blank">Visit Example Website</a>
Best Practices for Hyperlinks:
- Use Descriptive Text: Make hyperlink text descriptive and indicative of the linked content. Avoid generic phrases like "click here."
- Ensure Readability: Ensure that hyperlink text is easily readable and distinguishable from surrounding text.
- Use Proper Formatting: Style hyperlinks with CSS to make them visually distinguishable (e.g., change color or underline).
- Test Links: Regularly test hyperlinks to ensure they lead to the intended destinations and are functioning correctly.
- Provide Feedback: If possible, provide visual or auditory feedback when a hyperlink is clicked to indicate that the action has been successful.
Practice Excercise Practice now