HTMLタグ <div> は、それ自体には何の意味も効果もありません。 開始タグと終了タグに挟まれたテキストやHTML要素に任意の属性を指定したいときに指定します。<span> タグと異なり、ブロック要素となります。
| 要素 | 説明 |
|---|---|
| address | 連絡先 |
| article | 独立した記事 |
| aside | コンテンツとは無関係なもの(広告等) |
| div | 意味的ではなく視覚的な区切り |
| figure | 図とキャプション |
| footer | フッター |
| header | ヘッダー |
| hgroup | 見出し、サブタイトル及びリード文 |
| main | メインコンテンツ |
| nav | ナビゲーション |
| section | 意味的な区切り |
HTMLはタグ名、属性名及び属性値の大文字と小文字を区別しない。
<div>
<!-- flow content -->
</div>
<div class="container>
<!-- flow content -->
</div>
属性は全て省略可能です。
div要素の内容にはフローコンテンツを含めることができる。具体的には次の要素である。
<a><abbr><address><aside><audio><b><bdo><bdi><blockquote><br><button><canvas><cite><code><datalist><del><details><dfn><div><dl><em><embed><fieldset><figure><footer><form><h1><header><hgroup><hr><i><iframe><img><input><ins><kbd><label><main><map><mark><math><menu><meter><nav><noscript><object><ol><p><picture><pre><progress><q><ruby><s><samp><script><section><select><small><span><strong><sub><sup><svg><table><template><textarea><ul><var><video><wbr>div要素を中央寄せにするには、次のようにする。
<div style="width: 200px; margin: 0 auto">
The quick brown fox jumps over the lazy dog.
</div>
div要素を右寄せにするには、次のようにする。
<div style="width: 200px; margin-left: auto">
The quick brown fox jumps over the lazy dog.
</div>
div要素を横並びにするには、次のようにする。
<div style="width: 100px; float: left;">#1</div>
<div style="width: 100px; float: left;">#2</div>
<div style="width: 100px; clear: both;">#3</div>
非表示にしたうえで余白も残さない場合は、displayをnoneにする。
<div style="display: none;">
非表示
</div>
非表示にしたうえで余白を残す場合は、visibilityをhiddenにする。
<div style="visibility: hidden;">
非表示
</div>
<div style="border-right: medium solid gray">
The quick brown fox jumps over the lazy dog.
</div>
Web Hypertext Application Technology Working Group (2022) "Grouping content" HTML Living Standard