Tag HTML <a>


Contoh

Buat tautan ke W3Schools.com:

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

Lebih banyak contoh "Coba Sendiri" di bawah ini.


Definisi dan Penggunaan

Tag <a>mendefinisikan hyperlink, yang digunakan untuk menghubungkan dari satu halaman ke halaman lain.

Atribut terpenting dari <a>elemen adalah hrefatribut, yang menunjukkan tujuan tautan.

Secara default, tautan akan muncul sebagai berikut di semua browser:

  • Tautan yang belum dikunjungi digarisbawahi dan berwarna biru
  • Tautan yang dikunjungi digarisbawahi dan berwarna ungu
  • Tautan aktif digarisbawahi dan merah

Tips dan Catatan

Tip: Jika <a>tag tidak memiliki hrefatribut, itu hanya tempat untuk hyperlink.

Tip: Halaman tertaut biasanya ditampilkan di jendela browser saat ini, kecuali jika Anda menentukan target lain.

Tip: Gunakan CSS untuk menata tautan: Tautan CSS dan Tombol CSS .


Dukungan Peramban

Element
<a> Yes Yes Yes Yes Yes

Atribut

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

Atribut Global

Tag <a>juga mendukung Atribut Global dalam HTML .


Atribut Acara

Tag <a>juga mendukung Atribut Peristiwa dalam HTML .



Lebih Banyak Contoh

Contoh

Cara menggunakan gambar sebagai tautan:

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

Contoh

Cara membuka tautan di jendela browser baru:

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

Contoh

Cara menautkan ke alamat email:

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

Contoh

Cara menautkan ke nomor telepon:

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

Contoh

Cara menautkan ke bagian lain di halaman yang sama:

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

Contoh

Cara menautkan ke JavaScript:

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

Halaman Terkait

Tutorial HTML: Tautan HTML

Referensi DOM HTML: Objek Jangkar

Tutorial CSS: Menata Tautan


Pengaturan CSS Default

Sebagian besar browser akan menampilkan <a>elemen dengan nilai default berikut:

a:link, a:visited {
  color: (internal value);
  text-decoration: underline;
  cursor: auto;
}

a:link:active, a:visited:active {
  color: (internal value);
}