メインコンテンツへスキップ

dir要素


1.仕様

DIR要素は、
複数列のディレクトリリストの
作成に使用するように
設計されています。

dir

ディレクトリリスト (directory lists)

HTML4.01 で非推奨, HTML5 で廃止の要素です。

種類

通常要素

カテゴリ
  • フローコンテンツ
  • パルパブルコンテンツ(条件付き)

要素の子に少なくとも1つの li要素が含まれる場合は、パルパブルコンテンツ。

使用できるコンテキスト
フローコンテンツを受け入れる要素

フローコンテンツを受け入れる要素のコンテンツとして、使用できます。

フローコンテンツを受け入れる要素は、body要素, section要素, nav要素, aside要素, article要素, header要素, footer要素, main要素, address要素, li要素, dt要素, dd要素, caption要素, th要素, td要素, form要素, fieldset要素, search要素, blockquote要素, figure要素, figcaption要素, div要素, dialog要素, details要素 です。

コンテンツモデル
0個以上のli要素 オプションでスクリプトをサポートする要素が混在

0個以上のli要素が配置できます。オプションで、スクリプトをサポートする要素を混在して配置できます。

スクリプトをサポートする要素に分類される要素は、script要素, template要素 です。

タグの省略

どちらのタグも省略できません。

コンテンツ属性
グローバル属性 他
compact属性
リストをコンパクトに表示
DOM インターフェイス
HTMLDirectoryElement
  1. [Exposed=Window]
  2. interface HTMLDirectoryElement : HTMLElement {
  3. [HTMLConstructor] constructor();
  4.  
  5. [CEReactions] attribute boolean compact;
  6. };
HTMLElement
  1. [Exposed=Window]
  2. interface HTMLElement : Element {
  3. [HTMLConstructor] constructor();
  4.  
  5. // metadata attributes
  6. [CEReactions] attribute DOMString title;
  7. [CEReactions] attribute DOMString lang;
  8. [CEReactions] attribute boolean translate;
  9. [CEReactions] attribute DOMString dir;
  10.  
  11. // user interaction
  12. [CEReactions] attribute (boolean or unrestricted double or DOMString)? hidden;
  13. [CEReactions] attribute DOMString inert;
  14. undefined click();
  15. [CEReactions] attribute DOMString accessKey;
  16. readonly attribute DOMString accessKeyLabel;
  17. [CEReactions] attribute boolean draggable;
  18. [CEReactions] attribute boolean spellcheck;
  19. [CEReactions] attribute DOMString writingSuggestions;
  20. [CEReactions] attribute DOMString autocapitalize;
  21.  
  22. [CEReactions] attribute [LegacyNullToEmptyString] DOMString innerText;
  23. [CEReactions] attribute [LegacyNullToEmptyString] DOMString outerText;
  24.  
  25. ElementInternals attachInternals();
  26.  
  27. // The popover API
  28. undefined showPopover();
  29. undefined hidePopover();
  30. boolean togglePopover(optional boolean force);
  31. [CEReactions] attribute DOMString? popover;
  32. };
  33.  
  34. HTMLElement includes GlobalEventHandlers;
  35. HTMLElement includes ElementContentEditable;
  36. HTMLElement includes HTMLOrSVGElement;
Element
  1. [Exposed=Window]
  2. interface Element : Node {
  3. readonly attribute DOMString? namespaceURI;
  4. readonly attribute DOMString? prefix;
  5. readonly attribute DOMString localName;
  6. readonly attribute DOMString tagName;
  7.  
  8. [CEReactions] attribute DOMString id;
  9. [CEReactions] attribute DOMString className;
  10. [SameObject, PutForwards=value] readonly attribute DOMTokenList classList;
  11. [CEReactions, Unscopable] attribute DOMString slot;
  12.  
  13. boolean hasAttributes();
  14. [SameObject] readonly attribute NamedNodeMap attributes;
  15. sequence<DOMString> getAttributeNames();
  16. DOMString? getAttribute(DOMString qualifiedName);
  17. DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
  18. [CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value);
  19. [CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value);
  20. [CEReactions] undefined removeAttribute(DOMString qualifiedName);
  21. [CEReactions] undefined removeAttributeNS(DOMString? namespace, DOMString localName);
  22. [CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
  23. boolean hasAttribute(DOMString qualifiedName);
  24. boolean hasAttributeNS(DOMString? namespace, DOMString localName);
  25.  
  26. Attr? getAttributeNode(DOMString qualifiedName);
  27. Attr? getAttributeNodeNS(DOMString? namespace, DOMString localName);
  28. [CEReactions] Attr? setAttributeNode(Attr attr);
  29. [CEReactions] Attr? setAttributeNodeNS(Attr attr);
  30. [CEReactions] Attr removeAttributeNode(Attr attr);
  31.  
  32. ShadowRoot attachShadow(ShadowRootInit init);
  33. readonly attribute ShadowRoot? shadowRoot;
  34.  
  35. Element? closest(DOMString selectors);
  36. boolean matches(DOMString selectors);
  37. boolean webkitMatchesSelector(DOMString selectors); // legacy alias of .matches
  38.  
  39. HTMLCollection getElementsByTagName(DOMString qualifiedName);
  40. HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
  41. HTMLCollection getElementsByClassName(DOMString classNames);
  42.  
  43. [CEReactions] Element? insertAdjacentElement(DOMString where, Element element); // legacy
  44. undefined insertAdjacentText(DOMString where, DOMString data); // legacy
  45. };
GlobalEventHandlers
  1. interface mixin GlobalEventHandlers {
  2. attribute EventHandler onabort;
  3. attribute EventHandler onauxclick;
  4. attribute EventHandler onbeforeinput;
  5. attribute EventHandler onbeforematch;
  6. attribute EventHandler onbeforetoggle;
  7. attribute EventHandler onblur;
  8. attribute EventHandler oncancel;
  9. attribute EventHandler oncanplay;
  10. attribute EventHandler oncanplaythrough;
  11. attribute EventHandler onchange;
  12. attribute EventHandler onclick;
  13. attribute EventHandler onclose;
  14. attribute EventHandler oncontextlost;
  15. attribute EventHandler oncontextmenu;
  16. attribute EventHandler oncontextrestored;
  17. attribute EventHandler oncopy;
  18. attribute EventHandler oncuechange;
  19. attribute EventHandler oncut;
  20. attribute EventHandler ondblclick;
  21. attribute EventHandler ondrag;
  22. attribute EventHandler ondragend;
  23. attribute EventHandler ondragenter;
  24. attribute EventHandler ondragleave;
  25. attribute EventHandler ondragover;
  26. attribute EventHandler ondragstart;
  27. attribute EventHandler ondrop;
  28. attribute EventHandler ondurationchange;
  29. attribute EventHandler onemptied;
  30. attribute EventHandler onended;
  31. attribute OnErrorEventHandler onerror;
  32. attribute EventHandler onfocus;
  33. attribute EventHandler onformdata;
  34. attribute EventHandler oninput;
  35. attribute EventHandler oninvalid;
  36. attribute EventHandler onkeydown;
  37. attribute EventHandler onkeypress;
  38. attribute EventHandler onkeyup;
  39. attribute EventHandler onload;
  40. attribute EventHandler onloadeddata;
  41. attribute EventHandler onloadedmetadata;
  42. attribute EventHandler onloadstart;
  43. attribute EventHandler onmousedown;
  44. [LegacyLenientThis] attribute EventHandler onmouseenter;
  45. [LegacyLenientThis] attribute EventHandler onmouseleave;
  46. attribute EventHandler onmousemove;
  47. attribute EventHandler onmouseout;
  48. attribute EventHandler onmouseover;
  49. attribute EventHandler onmouseup;
  50. attribute EventHandler onpaste;
  51. attribute EventHandler onpause;
  52. attribute EventHandler onplay;
  53. attribute EventHandler onplaying;
  54. attribute EventHandler onprogress;
  55. attribute EventHandler onratechange;
  56. attribute EventHandler onreset;
  57. attribute EventHandler onresize;
  58. attribute EventHandler onscroll;
  59. attribute EventHandler onscrollend;
  60. attribute EventHandler onsecuritypolicyviolation;
  61. attribute EventHandler onseeked;
  62. attribute EventHandler onseeking;
  63. attribute EventHandler onselect;
  64. attribute EventHandler onslotchange;
  65. attribute EventHandler onstalled;
  66. attribute EventHandler onsubmit;
  67. attribute EventHandler onsuspend;
  68. attribute EventHandler ontimeupdate;
  69. attribute EventHandler ontoggle;
  70. attribute EventHandler onvolumechange;
  71. attribute EventHandler onwaiting;
  72. attribute EventHandler onwebkitanimationend;
  73. attribute EventHandler onwebkitanimationiteration;
  74. attribute EventHandler onwebkitanimationstart;
  75. attribute EventHandler onwebkittransitionend;
  76. attribute EventHandler onwheel;
  77. };
ElementContentEditable
  1. interface mixin ElementContentEditable {
  2. [CEReactions] attribute DOMString contentEditable;
  3. [CEReactions] attribute DOMString enterKeyHint;
  4. readonly attribute boolean isContentEditable;
  5. [CEReactions] attribute DOMString inputMode;
  6. };
HTMLOrSVGElement
  1. interface mixin HTMLOrSVGElement {
  2. [SameObject] readonly attribute DOMStringMap dataset;
  3. attribute DOMString nonce; // intentionally no [CEReactions]
  4.  
  5. [CEReactions] attribute boolean autofocus;
  6. [CEReactions] attribute long tabIndex;
  7. undefined focus(optional FocusOptions options = {});
  8. undefined blur();
  9. };
ARIA in HTML

この要素は、HTML5 では廃止された機能です。ARIA in HTML に、この要素の記述はありません。

レンダリング
ブロックボックス
リスト
  1. dir {
  2. display: block;
  3. margin-block: 1em;
  4. padding-inline-start: 40px;
  5. counter-reset: list-item;
  6. list-style-type: disc;
  7. unicode-bidi: isolate;
  8. }
  9. :is(dir, dl, menu, ol, ul) dir { margin-block: 0; }
  10. :is(dir, menu, ol, ul) dir { list-style-type: circle; }
  11. :is(dir, menu, ol, ul) :is(dir, menu, ol, ul) dir { list-style-type: square; }

CSS を大雑把に読むと、 ブロックレベルのブロックコンテナボックス(ブロックボックス)を生成します。 などになります。

説明
dir要素は、複数列のディレクトリリストを作成するために使用されるように設計されました。

dir要素は、ディレクトリの一覧(リスト・list)を表します。ディレクトリの順序は重要ではありません。つまり、順序を変更しても文書(ドキュメント・document)の意味は大きく変わりません。とはいえ、ul要素に対するol要素のような要素は dir要素には見当たりません。順序に意味のあるディレクトリの一覧はどうするべきか悩みどころです。
リストの項目は、dir要素の li要素の子ノードで、ツリー順になっています。
HTML5 では廃止された要素です。ul要素を用いて代用できます。順序に意味のある場合は、ol要素を用いて代用できます。

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>dir要素の例 - (Example of dir element) | 離珠のHTMLでしぃ!</title>
  6. </head>
  7. <body>
  8. <h1>dir要素の例</h1>
  9. <dir>
  10. <li>ディレクトリリストアイテムA</li>
  11. <li>ディレクトリリストアイテムB</li>
  12. </dir>
  13. </body>
  14. </html>

このサンプルへのリンクです。
(./exdir.htm)

JSONデータ
JSON形式での、データのイメージです。
  1. {
  2. "dir": {
  3. "check": "2024-09-01",
  4. "group": "List",
  5. "element": "- - (li)+ +(%Scriptsupporting) -- directory lists. (Normal elements.) [Flow|Palpable] --",
  6. "attlist": {
  7. "%Global;": "",
  8. "compact": "(compact) #IMPLIED -- Compact list style --",
  9. },
  10. "comment": "ディレクトリリスト (directory lists)",
  11. "point": "複数列のディレクトリリストを作成するために使用されるように設計されました。",
  12. "description": [
  13. "ディレクトリの一覧(リスト・list)を表します。ディレクトリの順序は重要ではありません。つまり、順序を変更しても文書(ドキュメント・document)の意味は大きく変わりません。とはいえ、ul要素に対するol要素のような要素は dir要素には見当たりません。順序に意味のあるディレクトリの一覧はどうするべきか悩みどころです。",
  14. "リストの項目は、dir要素の li要素の子ノードで、ツリー順になっています。",
  15. "HTML5 では廃止された要素です。ul要素を用いて代用できます。順序に意味のある場合は、ol要素を用いて代用できます。",
  16. ],
  17. "kind": "Normal",
  18. "categories": [
  19. "Flow",
  20. "PalpableLimited",
  21. ],
  22. "categoriessupplement": "要素の子に少なくとも1つの li要素が含まれる場合は、パルパブルコンテンツ。",
  23. "used": "parent (%Flow)*",
  24. "contentmodel": "dir (li)* +(%Scriptsupporting)",
  25. "tag": [
  26. "-",
  27. "-",
  28. ],
  29. "attributes": {"compact": "リストをコンパクトに表示"},
  30. "dominterface": "HTMLDirectoryElement",
  31. "rendering": [
  32. "Lists",
  33. "Bidirectional",
  34. ],
  35. "reference": [
  36. {
  37. "title": "HTML Living Standard. 16.2 Non-conforming features.",
  38. "href": "https://html.spec.whatwg.org/multipage/obsolete.html#non-conforming-features",
  39. "heading": "HTML Living Standard. 16.2 Non-conforming features",
  40. "sub": "Last Updated 27 August 2024",
  41. },
  42. {
  43. "title": "HTML Living Standard. 15 Rendering 15.3.7 Lists.",
  44. "href": "https://html.spec.whatwg.org/multipage/rendering.html#lists",
  45. "heading": "HTML Living Standard. 15 Rendering 15.3.7 Lists",
  46. "sub": "Last Updated 27 August 2024",
  47. },
  48. {
  49. "title": "HTML 4.01 Specification W3C Recommendation. 10.4 The DIR and MENU elements. W3C Recommendation 24 December 1999.",
  50. "href": "https://www.w3.org/TR/html401/struct/lists.html#h-10.4",
  51. "heading": "HTML 4.01 Specification W3C 勧告. 10.4 The DIR and MENU elements",
  52. "sub": "W3C勧告1999年12月24日",
  53. },
  54. {
  55. "title": "HTML 3.2 Reference Specification. W3C Recommendation 14-Jan-1997.",
  56. "href": "https://www.w3.org/TR/2018/SPSD-html32-20180315/#dir",
  57. "heading": "HTML 3.2 Reference Specification",
  58. "sub": "W3C勧告1997年1月14日",
  59. },
  60. {
  61. "title": "Hypertext Markup Language - 2.0. November 1995.",
  62. "href": "https://www.ietf.org/rfc/rfc1866.txt",
  63. "heading": "Hypertext Markup Language - 2.0",
  64. "sub": "November 1995",
  65. },
  66. {
  67. "title": "Hypertext Markup Language (HTML). June 1993.",
  68. "href": "https://www.w3.org/MarkUp/draft-ietf-iiir-html-01.txt",
  69. "heading": "Hypertext Markup Language (HTML)",
  70. "sub": "June 1993",
  71. },
  72. {
  73. "title": "MDN Web Docs. HTML <dir>: The Dir element.",
  74. "href": "https://developer.mozilla.org/ja/docs/Web/HTML/Element/dir",
  75. "heading": "<dir>: ディレクトリー要素 - HTML: ハイパーテキストマークアップ言語 | MDN",
  76. },
  77. ],
  78. "version": {
  79. "first": "HTML",
  80. "latest": "HTML4.01 Transitional",
  81. },
  82. "domsupplement": {"compact": "boolean"},
  83. }
  84. }

注意: 簡易に描画する為に、各項目の後ろに , を付与しています。JSON の形式では、末尾の項目の後には , は付けません。

最終確認日

2024-09-01


2.使用可能な箇所

フローコンテンツ
受け入れる要素に
配置できます。

dir要素を使用できる状態(コンテキスト・Context)は、 フローコンテンツを受け入れる要素に配置できます。

フローコンテンツを受け入れる要素は、body要素, section要素, nav要素, aside要素, article要素, header要素, footer要素, main要素, address要素, li要素, dt要素, dd要素, caption要素, th要素, td要素, form要素, fieldset要素, search要素, blockquote要素, figure要素, figcaption要素, div要素, dialog要素, details要素 です。

dir要素は、HTML5 では廃止された要素です。つまり html4.01 で扱うなら、親の要素も html4.01 で扱える要素という事です。なので section要素などの HTML5 で新たに追加された要素は、現実問題として親の要素となる事はありません。


3.配置できるコンテンツ

li要素
配置できます。

dir要素(内容・コンテンツ・Content)として、0 以上の li要素 および scriptコンテンツを配置できます。

scriptコンテンツである要素は、script要素, template要素 です。

dir要素は、HTML5 では廃止された要素です。つまり html4.01 で扱うなら、子の要素も html4.01 で扱える要素という事です。なので template要素などの HTML5 で新たに追加された要素は、現実問題として子の要素となる事はありません。

dir
li
Flow
content
  1. <dir>
  2. <li>ディレクトリ</li>
  3. </dir>

dir要素のコンテンツの一部として、li要素を配置できます。li要素のコンテンツとしてフローコンテンツが配置できて、そのコンテンツがディレクトリを表します。

dir要素は、HTML5 では廃止された要素です。その上で HTML5 での概念で表しています。フローコンテンツとかのカテゴリは HTML5 のものです。dir要素の仕様を正確に学ぶという点では、この記述は不適切なのでご注意下さい。 HTML3.2 の DTD から読むとdir要素の子であるli要素のコンテンツとして配置できるのは、フレージングコンテンツではないかと思います。フレージングコンテンツである要素は、script要素, noscript要素, template要素, input要素, textarea要素, select要素, label要素, button要素, output要素, progress要素, meter要素, datalist要素, picture要素, object要素, img要素, iframe要素, embed要素, video要素, audio要素, canvas要素, map要素, area要素, a要素, ins要素, del要素, abbr要素, b要素, bdi要素, bdo要素, br要素, cite要素, code要素, data要素, dfn要素, em要素, i要素, kbd要素, mark要素, q要素, ruby要素, s要素, samp要素, small要素, span要素, strong要素, sub要素, sup要素, time要素, u要素, var要素, wbr要素, slot要素, text 条件付きで、mata要素, link要素 です。

ブロック
フォーマット
コンテキスト
ブロック
レベル
ボックス

ボックスで表すと、dir要素が存在して、その中に li要素があります。

dir要素は、ブロックレベルブロックコンテナであるボックスを生成します。dir要素を含むブロックフォーマットコンテキストがない場合は、新しいブロックフォーマットコンテキストを確立します。dir要素は、ブロックレベルのボックスを生成するli要素を配置します。なのでここでは、インラインフォーマットコンテキストは確立されません。
尚、この説明は各要素のレンダリングに関する指定が既定値での話で、個々にスタイルを指定した場合はこの限りではありません。


4.属性

グローバル属性と、
compact属性 を
設定できます。

dir要素は、グローバル属性compact属性 を設定できます。

compact属性

  1. <dir >

compact属性はブール属性で、存在する場合、リストをよりコンパクトな方法でレンダリングする為のヒントがビジュアルユーザーエージェントに与えられます。

一覧表(リスト)要素の compact属性は HTML5 で廃止された属性ですが、dir要素自体が HTML5 で廃止された要素なのでここに記述しています。

実際の処、コンパクトなレンダリングは違いがないと思います。 ユーザーエージェントによっては効果があるかもしれませんが、スタイルシートで確実にレンダリングを指定した方が良いと思います。

  • リスト1
  • リスト2
  • リスト3

  • 5.Web API

    id属性を用いて
    getElementById()メソッドで
    要素を取得する方法がお勧めです。

    dir要素を表すプロパティはないので、id属性を用いて documentgetElementById()メソッドで、要素を取得する方法がお勧めです。この時に取得できるのはHTMLDirectoryElement オブジェクトです。


    6.レンダリング

    1. dir {
    2. display: block;
    3. margin-block-start: 1em;
    4. margin-block-end: 1em;
    5. padding-inline-start: 40px;
    6. counter-reset: list-item;
    7. list-style-type: disc;
    8. unicode-bidi: isolate;
    9. }

    dir要素は、ブロックレベルのブロックコンテナであるボックスを生成します。

    ブロックフォーマットコンテキストに参加して、ブロックフォーマットコンテキストを継承, 確立します。もし、インラインフォーマットコンテキストに参加するコンテンツのみを含む場合は、新しいインラインフォーマットコンテキストを確立します。次に、すべてのインラインコンテンツをラップするルートインラインボックスも生成します。

    list-style-type は、リスト項目要素のマーカーを設定します。disc は、塗りつぶされた円形です。

    unicode-bidi は、置換されない要素のレンダリングでの Bidirectional text(双方向テキスト) に於いての期待される仕様の様です。

    1. :is(dir, dl, menu, ol, ul) dir {
    2. margin-block-start: 0;
    3. margin-block-end: 0;
    4. }
    5. :is(dir, menu, ol, ul) dir { list-style-type: circle; }
    6. :is(dir, menu, ol, ul) :is(dir, menu, ol, ul) dir { list-style-type: square; }

    dir要素のレンダリングに関する部分を抜粋したものです。dir要素が関わる他の要素のレンダリングに関する部分は省いています。


    7.気を付ける点

    HTML5

    HTML5 では廃止された要素です。html4.01 で記述するとしてもユーザーエージェントなどがどの様に扱ってくれるかが、作成者の意図と合うかどうかが問題かと思います。どうせなら dir要素という要素がないものとして、ul要素またはol要素から選んだ方が制作意図を表し易いかもしれません。


    8.付記