The `<a>` tag is the fundamental building block of the World Wide Web. Without it, the web would just be a collection of isolated documents. By using anchors, we create the **hypertext** that allows users to navigate the global information network.
1The href Attribute
The href (Hypertext Reference) is mandatory for a functional link. It can point to:
- →Absolute URLs: Full web addresses (e.g.,
https://codesyllabus.com). - →Relative URLs: Paths within the same site (e.g.,
/about). - →Anchors: Internal locations (e.g.,
#section-1). - →Protocols: Such as
mailto:ortel:.
2Targeting & Security
The target attribute defines where the link opens. While _blank is popular for external sites, it can pose security risks.
Always use rel="noopener noreferrer" when using target="_blank" to prevent the new page from accessing your site's window object. This is a critical best practice for modern security.
3Accessibility & Titles
Links must be descriptive. Avoid 'click here'. Instead, use text that describes the destination, like 'Download our PDF Guide'.
Screen readers read link text out of context, so descriptive text is vital for users with visual impairments. The title attribute can provide extra info, but should never be a substitute for good link text.
