Znacznik HTML <a>
Przykład
Utwórz link do W3Schools.com:
<a href="https://www.w3schools.com">Visit W3Schools.com!</a>
Więcej przykładów „Wypróbuj sam” poniżej.
Definicja i użycie
Tag <a>
definiuje hiperłącze, które służy do łączenia się z jednej strony na drugą.
Najważniejszym atrybutem <a>
elementu jest
href
atrybut, który wskazuje miejsce docelowe linku.
Domyślnie linki będą wyświetlane we wszystkich przeglądarkach w następujący sposób:
- Nieodwiedzony link jest podkreślony i niebieski
- Odwiedzony link jest podkreślony i fioletowy
- Aktywny link jest podkreślony i czerwony
Wskazówki i uwagi
Porada: Jeśli <a>
tag nie ma
href
atrybutu, jest tylko symbolem zastępczym hiperłącza.
Wskazówka: Połączona strona jest zwykle wyświetlana w bieżącym oknie przeglądarki, chyba że określisz inny cel.
Wskazówka: użyj CSS do stylizacji linków: CSS Links and CSS Buttons .
Obsługa przeglądarki
Element | |||||
---|---|---|---|---|---|
<a> | Yes | Yes | Yes | Yes | Yes |
Atrybuty
Attribute | Value | Description |
---|---|---|
download | filename | Specifies that the target will be downloaded when a user clicks on the hyperlink |
href | URL | Specifies the URL of the page the link goes to |
hreflang | language_code | Specifies the language of the linked document |
media | media_query | Specifies what media/device the linked document is optimized for |
ping | list_of_URLs | Specifies a space-separated list of URLs to which, when the link is followed, post requests with the body ping will be sent by the browser (in the background). Typically used for tracking. |
referrerpolicy | no-referrer no-referrer-when-downgrade origin origin-when-cross-origin same-origin strict-origin-when-cross-origin unsafe-url |
Specifies which referrer information to send with the link |
rel | alternate author bookmark external help license next nofollow noreferrer noopener prev search tag |
Specifies the relationship between the current document and the linked document |
target | _blank _parent _self _top |
Specifies where to open the linked document |
type | media_type | Specifies the media type of the linked document |
Atrybuty globalne
Znacznik <a>
obsługuje również atrybuty globalne w HTML .
Atrybuty wydarzenia
Tag <a>
obsługuje również Atrybuty Zdarzeń w HTML .
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 otworzyć link w nowym oknie przeglądarki:
<a href="https://www.w3schools.com" target="_blank">Visit W3Schools.com!</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>
Powiązane strony
Samouczek HTML: linki HTML
Odniesienie HTML DOM: Obiekt zakotwiczenia
Samouczek CSS: stylizowanie linków
Domyślne ustawienia CSS
Większość przeglądarek wyświetla <a>
element z następującymi wartościami domyślnymi:
a:link, a:visited {
color: (internal value);
text-decoration: underline;
cursor: auto;
}
a:link:active, a:visited:active {
color: (internal value);
}