0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【HTML】リンク(aタグ)を入れてみましょう

0
Last updated at Posted at 2026-04-11

今日はHTMLで他のページに移動するときに使う『リンク(anchorタグ』についてです。

1. リンクとは?

HTMLのリンクは、別のページやファイル、または同じページ内の特定の場所にユーザを誘導するために使います。
基本的には<a>タグ(アンカータグ)を使用します。
よく使う属性(Attribute):

  • href :リンク先の URL (パス)を指定します。
  • taget :リンクをどの画面で開くか(現在のタブが、新しいタブか)を決めます。
  • ale :画像をリンクにする際、その画像の内容を説明するために使います。

2. よく使う4つのパターン

1. 外部サイトへの遷移 (External Link)
Googleなどの外部ドキュメントやサイトへ飛ばすときに使います。

<a href="http://www.google.com">Googleへ移動</a>

2.内部リンク(Internal Link)
プロジェクト内の別のファイルへ(html)移動します。

<a href="01_intro.html">トップページへ</a>

<a href="http://localhost:8080/Web01_HTML_CSS/01_html/01_intro.html">詳細ページへ</a> 

3.画像リンクと別タブで開く方法
バナー画像などをクリックさせるリンクです。target="_blank" は、現場で「別タブで開く」と言いたい時に必ず出てくるキーワードです。

<a href="https://www.youtube.com/@jaerong" target="_blank">
  <img src="../images/dog1.jpg" alt="チャンネルアイコン" width="50">
</a>

4.ページ内リンク (Anchor Link / Scroll)
LP(ランディングページ)などでよく使われる、同じページ内の特定の場所へジャンプする機能です。id を使って場所を指定します。

<h2 id="section1">セクション1</h2>

<a href="#section1">セクション1へスクロール</a>

まとめ

  • パスの書き方:外部『絶対パス』と『相対パス』の使い分ける。
  • アクセシビリティ:画像リンクには必ず<alt>属性を入れて、何についてのリンクか分かるようにする。

これからも学んだ内容をアウトプットしていきます!

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?