HTMLコピペ集(section・container・見出し・カード・リンク/ボタン・画像/figure・リスト・表・電話/メール/外部リンク・iframe・YouTube・地図)

要点

よく使うHTMLの型。見出しは順番どおり(H1は1つ)、画像にはalt、移動はa・操作はbutton、外部リンクの別タブには rel="noopener"、iframeにはtitle。YouTube・地図の詳しい注意は各ナレッジ。

セクションと箱

<section class="xx-section" aria-labelledby="xx-about">
  <div class="xx-inner">
    <h2 id="xx-about">サービスの特徴</h2>
    <p>本文</p>
  </div>
</section>

カード

<ul class="xx-cards">
  <li class="xx-card">
    <a href="/service/web/">
      <span class="xx-thumb"><img src="/img/web.webp" alt="" width="640" height="400" loading="lazy"></span>
      <span class="xx-card-title">ホームページ制作</span>
      <span class="xx-card-text">説明を1〜2行</span>
    </a>
  </li>
</ul>

カード全体がリンクで、画像が飾りなら alt=""(カードの文字が読み上げられるので二重にしない)。

リンクとボタン

<a href="/contact/" class="xx-btn">お問い合わせ</a>          <!-- ページ移動は a -->
<button type="button" class="xx-btn" aria-expanded="false">詳しく見る</button>  <!-- ページ内の操作は button -->
  • 見た目がボタンでも、別ページへ移動するなら a。href="#" のダミーリンクを残さない。
  • div や span にクリック処理を付けない(キーボードで押せない)。

画像・figure

<img src="/img/photo.webp" alt="店内のカウンター席" width="1200" height="800" loading="lazy">
<figure>
  <img src="/img/map.webp" alt="駅から店舗までの案内図" width="800" height="600" loading="lazy">
  <figcaption>JR○○駅 北口から徒歩5分</figcaption>
</figure>

ファーストビューのメイン画像には loading="lazy" を付けない。

リスト・表

<ul><li>項目</li><li>項目</li></ul>
<ol><li>手順1</li><li>手順2</li></ol>

<div class="xx-table-wrap">
  <table>
    <caption>料金表</caption>
    <thead><tr><th scope="col">プラン</th><th scope="col">料金(税込)</th></tr></thead>
    <tbody><tr><th scope="row">ベーシック</th><td>33,000円</td></tr></tbody>
  </table>
</div>

表は枠で包み、スマホでは枠の中だけ横スクロール(スマホ調整CSSコピペ集(media query・2列/1列切替・文字/余白・横スクロール防止・画像100%・ボタン幅100%・長いURLの折返し・配置変更))。

電話・メール・外部リンク

<a href="tel:0312345678">03-1234-5678</a>                   <!-- 番号はハイフンなし -->
<a href="mailto:info@example.com">info@example.com</a>
<a href="https://example.com/" target="_blank" rel="noopener noreferrer">外部サイト名(別タブで開きます)</a>
  • 別タブにするなら rel="noopener"(noreferrer は参照元も送らない。計測に影響するので必要に応じて)。
  • メールアドレスを直接載せると迷惑メールが増えることがある。お問い合わせフォームも検討。

iframe(共通)

<div class="xx-embed"><iframe src="..." title="何の埋め込みか" loading="lazy"></iframe></div>
.xx-embed{ aspect-ratio:16 / 9; }
.xx-embed iframe{ width:100%; height:100%; border:0; display:block; }

YouTube(レスポンシブ)

<div class="xx-embed"><iframe src="https://www.youtube.com/embed/動画ID" title="〇〇の紹介動画"
  loading="lazy" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>

複数置くとき・速度の注意は YouTube動画の埋め込み(レスポンシブ16:9・遅延読み込み・サムネイル方式)と自サーバー動画との違い。

Google Maps

<div class="xx-map"><iframe src="(Google Mapsの「地図を埋め込む」のURL)" title="〇〇へのアクセス地図"
  loading="lazy" referrerpolicy="no-referrer-when-downgrade" allowfullscreen></iframe></div>
<p><a href="(Google Mapsの共有URL)" target="_blank" rel="noopener">Google マップで開く</a></p>
.xx-map iframe{ width:100%; height:400px; border:0; display:block; }
@media (max-width:767px){ .xx-map iframe{ height:300px; } }

住所はテキストでも書く。使い分けは HPに地図を載せる方法の使い分け(Google Mapsリンク・埋め込みiframe・地図画像・独自案内図)。