href
href Attribute
The href
attribute in HTML specifies the destination URL of a hyperlink. It is a key component of the <a>
(anchor) tag, allowing users to navigate to different web pages, sections within the same page, or download files.
Syntax
<a href="URL">
Example
<a href="https://institute.qarpeo.com" target="_blank">Visit https://institute.qarpeo.com</a>
Using an Image as a Link
<a href="https://institute.qarpeo.com" target="_blank">
<img border="0" alt="Qarpeo" src="logo_w3s.gif" width="100" height="100">
</a>
Opening a Link in a New Window
<a href="https://institute.qarpeo.com" target="_blank">Visit https://institute.qarpeo.com</a>
Linking to an Email Address
<a href="mailto:[email protected]">Send email</a>
Linking to a Phone Number
<a href="tel:+4733378901">+47 333 78 901</a>
Linking to Another Section on the Same Page
<a href="#section2">Go to Section 2</a>
Linking to JavaScript
<a href="javascript:alert('Hello World!');">Execute JavaScript</a>
Definition and Usage
- The
href
attribute defines theURL
orpath
for a hyperlink. - If omitted, the
<a>
tag will not act as a clickable link.
href="#top"
or href="#"
creates a link that scrolls to the top of the current page.Values
- URL: Specifies the address of the destination resource.
href="#top"
or href="#"
helps create a quick scroll-to-top feature.Applies To
The href
attribute is applicable to the following elements:
Conclusion
The href
attribute is essential for defining hyperlinks in HTML, enabling seamless navigation between pages, sections, and downloadable resources. It applies to elements like <a>
, <area>
, <link>
, and <base>
. Proper use of href
ensures an efficient and user-friendly browsing experience.
hidden
The hidden attribute in HTML conceals an element from view and makes it inaccessible to users and assistive technologies, while still keeping it in the DOM.
hreflang
The hreflang attribute indicates the language and regional targeting of a linked document, helping search engines provide relevant content to users.