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

dir要素


1.仕様

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

DIR - - (LI)+ -(%block) -- directory lists. (Normal elements.) [Flow|Palpable] --

dir

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

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

種類

通常要素

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

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

コンテンツモデル
0個以上の<li>要素 (ブロック状の要素 を除く)

0個以上の<li>要素が配置できます。ですが、ブロック状の要素は子孫に持てません。

HTML4.01 Transitional の規則です。

タグの省略

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

コンテンツ属性
グローバル属性 他
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 {
  10. margin-block: 0;
  11. }
  12. :is(dir, menu, ol, ul) dir {
  13. list-style-type: circle;
  14. }
  15. :is(dir, menu, ol, ul) :is(dir, menu, ol, ul) dir {
  16. list-style-type: square;
  17. }

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

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

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

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  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": "2025-07-27",
  4. "group": "List",
  5. "element": "- - (LI)+ -(%block) -- 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)* -(%block)",
  25. "contentmodelsupplement": "HTML4.01 Transitional の規則です。",
  26. "tag": [
  27. "-",
  28. "-",
  29. ],
  30. "attributes": {"compact": "リストをコンパクトに表示"},
  31. "dominterface": "HTMLDirectoryElement",
  32. "rendering": [
  33. "Lists",
  34. "Bidirectional",
  35. ],
  36. "reference": [
  37. {
  38. "title": "HTML Living Standard. 16.2 Non-conforming features.",
  39. "href": "https://html.spec.whatwg.org/multipage/obsolete.html#non-conforming-features",
  40. "heading": "HTML Living Standard. 16.2 Non-conforming features",
  41. "sub": "Last Updated 27 August 2024",
  42. },
  43. {
  44. "title": "HTML Living Standard. 15 Rendering 15.3.7 Lists.",
  45. "href": "https://html.spec.whatwg.org/multipage/rendering.html#lists",
  46. "heading": "HTML Living Standard. 15 Rendering 15.3.7 Lists",
  47. "sub": "Last Updated 27 August 2024",
  48. },
  49. {
  50. "title": "HTML 4.01 Specification W3C Recommendation. 10.4 The DIR and MENU elements. W3C Recommendation 24 December 1999.",
  51. "href": "https://www.w3.org/TR/html401/struct/lists.html#h-10.4",
  52. "heading": "HTML 4.01 Specification W3C 勧告. 10.4 The DIR and MENU elements",
  53. "sub": "W3C勧告1999年12月24日",
  54. },
  55. {
  56. "title": "HTML 3.2 Reference Specification. W3C Recommendation 14-Jan-1997.",
  57. "href": "https://www.w3.org/TR/2018/SPSD-html32-20180315/#dir",
  58. "heading": "HTML 3.2 Reference Specification",
  59. "sub": "W3C勧告1997年1月14日",
  60. },
  61. {
  62. "title": "Hypertext Markup Language - 2.0. November 1995.",
  63. "href": "https://www.ietf.org/rfc/rfc1866.txt",
  64. "heading": "Hypertext Markup Language - 2.0",
  65. "sub": "November 1995",
  66. },
  67. {
  68. "title": "Hypertext Markup Language (HTML). June 1993.",
  69. "href": "https://www.w3.org/MarkUp/draft-ietf-iiir-html-01.txt",
  70. "heading": "Hypertext Markup Language (HTML)",
  71. "sub": "June 1993",
  72. },
  73. {
  74. "title": "MDN Web Docs. HTML <dir>: The Dir element.",
  75. "href": "https://developer.mozilla.org/ja/docs/Web/HTML/Element/dir",
  76. "heading": "<dir>: ディレクトリー要素 - HTML: ハイパーテキストマークアップ言語 | MDN",
  77. },
  78. ],
  79. "version": {
  80. "first": "HTML",
  81. "latest": "HTML4.01 Transitional",
  82. },
  83. "domsupplement": {"compact": "boolean"},
  84. }
  85. }

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

最終確認日

2025-07-27


2.使用できるコンテキスト

dir要素は、
フローコンテンツを
受け入れる要素に
使用できます。

<dir>要素が使用できるコンテキスト(Context文脈)は、フローコンテンツを受け入れる要素コンテンツとしてです。

ただし<dir>要素は、HTML5 で廃止された要素です。HTML4.01 でも非推奨です。<ul>要素を用いる事が推奨されます。

body
dir
  1. <body>
  2. <dir>
  3. <li>項目1</li>
  4. <li>項目2</li>
  5. </dir>
  6. </body>

<body>要素のコンテンツの一部として、フローコンテンツである<dir>要素を配置している例です。


3.コンテンツモデル

dir要素は、
li要素を
配置できます。

<dir>要素子や子孫としてどのようなコンテンツ(Content内容) が含まれなければならないかというと、0 以上の<li>要素です。 ただし、子孫にブロック状の要素があってはいけません。

ブロック状の要素は、HTML4.01 Transitional の規則です。

<!ENTITY % block
  "P | %heading; | %list; | %preformatted; | DL | DIV | CENTER |
    NOSCRIPT | NOFRAMES | BLOCKQUOTE | FORM | ISINDEX | HR |
    TABLE | FIELDSET | ADDRESS"	>
<!ENTITY % heading "H1|H2|H3|H4|H5|H6">
<!ENTITY % list "UL | OL |  DIR | MENU">
<!ENTITY % preformatted "PRE">
dir
li
Phrasing
content
  1. <dir>
  2. <li><span>項目1</span></li>
  3. <li><span>項目2</span></li>
  4. </dir>

<dir>要素のコンテンツの一部として、<li>要素を配置している例です。

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

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

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


4.コンテンツ属性

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

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

compact属性

  1. <dir >

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

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

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

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

  • 5.DOM インターフェイス

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

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


    6.アクセシビリティ

    dir要素は、
    ARIA in HTML に、
    記述はありません。

    <dir>要素は、HTML5 では廃止された機能です。ARIA in HTML に、この要素の記述はありません。<dir>要素を使用する時は、HTML5 以前の機能でアクセシビリティを意識する必要がある訳です。

    そもそも論として、<dir>要素を使用してリストを表して、それが使う側からしてがどうかという事です。 HTML文書の構成, 設計で、アクセシビリティを意識しているかという事です。 その上で、<dir>要素を使用する必要があるならば、何かしらのデメリットも認識しましょう。


    7.レンダリング

    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要素が関わる他の要素のレンダリングに関する部分は省いています。


    8.気を付ける点

    HTML5

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