Atrybut HTML <a> href

❮ Znacznik HTML <a>

Przykład

Atrybut href określa miejsce docelowe linku:

<a href="https://www.w3schools.com">Visit W3Schools</a>

Więcej przykładów „Wypróbuj sam” poniżej.


Definicja i użycie

hrefAtrybut określa adres URL strony, do której prowadzi łącze .

Jeśli hrefatrybut nie jest obecny, <a>tag nie będzie hiperłączem.

Wskazówka: możesz użyć href="#top"lub href="#" , aby połączyć się z górą bieżącej strony!


Obsługa przeglądarki

Attribute
href Yes Yes Yes Yes Yes

Składnia

<a href="URL">

Wartości atrybutów

Value Description
URL The URL of the link.

Possible values:

  • An absolute URL - points to another web site (like href="http://www.example.com/default.htm")
  • A relative URL - points to a file within a web site (like href="default.htm")
  • Link to an element with a specified id within the page (like href="#section2")
  • Other protocols (like https://, ftp://, mailto:, file:, etc..)
  • A script (like href="javascript:alert('Hello');")


Więcej przykładów

Przykład

Jak użyć obrazu jako linku:

<a href="https://www.w3schools.com">
<img border="0" alt="W3Schools" src="logo_w3s.gif" width="100" height="100">
</a>

Przykład

Jak połączyć się z adresem e-mail:

<a href="mailto:[email protected]">Send email</a>

Przykład

Jak połączyć się z numerem telefonu:

<a href="tel:+4733378901">+47 333 78 901</a>

Przykład

Jak połączyć się z inną sekcją na tej samej stronie:

<a href="#section2">Go to Section 2</a>

Przykład

Jak połączyć się z JavaScriptem:

<a href="javascript:alert('Hello World!');">Execute JavaScript</a>

❮ Znacznik HTML <a>