Links

HTML links, created using the <a> tag, connect different web pages. The href attribute specifies the target URL. Links can include text, images, or other clickable elements.

Links in HTML are created using the <a> element, which allows users to navigate between different web pages or resources.

To create a clickable link with text, wrap the text in an <a> tag:

index.html
<a href="https://institute.qarpeo.com">Visit https://institute.qarpeo.com</a>

To create a clickable image link, wrap the image in an <a> tag:

index.html
<a href="https://institute.qarpeo.com">  
  <img src="image.jpg" alt="Example Image" />  
</a>

To create a link that opens the email client, use the mailto keyword in the href attribute:

index.html
<a href="mailto:[email protected]">Send an Email</a>

To open a link in a new tab, use target="_blank":

index.html
<a href="https://www.external-site.com" target="_blank">  
  Visit External Site  
</a>

For linking to pages within the same website, use relative URLs:

index.html
<a href="/about">Learn More About Us</a>
Links can be created with any HTML element, not just text! For example, images and buttons can be used as clickable links.

Key Attributes

  • href: Specifies the URL of the target link.
  • target: Defines how the link opens (_self, _blank).
  • rel: Used to improve security, e.g., rel="noopener" for links that open in new tabs.

SEO Tip

For better SEO, use descriptive anchor text:

index.html
<a href="/product123">Learn more about Product XYZ</a>

Colors and Styling

HTML links can be customized using CSS properties like color, text-decoration, and background-color. You can also style links based on their interaction state using pseudo-classes like :link, :visited, :hover, and :active. Links can also be styled to resemble buttons using CSS.

You can use style links to match your website's design preferences with CSS!

Key Points

  • Use pseudo-classes (:link, :visited, :hover, :active) to apply different styles depending on the link's state.
  • You can make links look like buttons with CSS properties such as background-color, padding, and text-align.

Bookmarks

Bookmarks allow users to quickly navigate to specific sections of a webpage. These are created using the id attribute and anchor <a> links.

Creating a Bookmark

  • Add an id to the target element.
  • Create a link that targets the specific id.

Example

Section 1

This is the content of section 1.

Go to Section 1
index.html
<!-- Target section with an id -->  
<h4 id="section1">Section 1</h4>  
<p>This is the content of section 1.</p>  
<!-- Link that jumps to the section -->  
<a href="#section1">Go to Section 1</a>

Key Points

  • The id attribute specifies the target location of the bookmark on the page.
  • Use href="#id" to link directly to a specific section. This is especially helpful for long pages where users want to navigate quickly to specific parts.

Conclusion

HTML links, created using the <a> tag, allow for easy navigation between different web pages and resources. Links can be made with text, images, or even buttons. Key attributes like href, target, and rel enhance link functionality and security.