HTML <a> href属性

❮HTML<a>タグ

href属性は、リンクの宛先を指定します。

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

以下の「自分で試してみてください」の例をもっと見てください。


定義と使用法

このhref属性は、リンク先のページのURLを指定します。

href属性が存在しない場合、 <a>タグはハイパーリンクにはなりません。

ヒント: href="#top"またはを使用href="#" して、現在のページの上部にリンクできます。


ブラウザのサポート

Attribute
href Yes Yes Yes Yes Yes

構文

<a href="URL">

属性値

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


その他の例

画像をリンクとして使用する方法:

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

メールアドレスにリンクする方法:

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

電話番号にリンクする方法:

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

同じページの別のセクションにリンクする方法:

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

JavaScriptにリンクする方法:

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

❮HTML<a>タグ