HTML <a> href Atribut

tag <a> HTML

Contoh

Atribut href menentukan tujuan tautan:

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

Lebih banyak contoh "Coba Sendiri" di bawah ini.


Definisi dan Penggunaan

Atribut hrefmenentukan URL halaman yang dituju tautan.

Jika hrefatribut tidak ada, <a>tag tidak akan menjadi hyperlink.

Tip: Anda dapat menggunakan href="#top"atau href="#" menautkan ke bagian atas halaman saat ini!


Dukungan Peramban

Attribute
href Yes Yes Yes Yes Yes

Sintaksis

<a href="URL">

Nilai Atribut

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');")


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 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>

tag <a> HTML