1.仕様
OL要素は、
順序付けられている
項目の一覧を
表します。
- ol
-
順序付き一覧 (ordered list)
- 種類
-
通常要素
- カテゴリ
-
- フロー
コンテンツ - パルパブル
コンテンツ (条件付き)
要素の子に少なくとも1つの li要素が含まれる場合は、パルパブルコンテンツ。
- フロー
- コンテンツモデル
-
0個以上のli
要素 オプションでスクリプトをサポートする要素 が混在0個以上のli
要素 が配置できます。オプションで、スクリプトをサポートする要素 を混在して配置できます。スクリプトを
サポートする要素 に分類される要素は、script要素 , template要素 です。 - タグの省略
-
どちらのタグも省略できません。
- コンテンツ属性
-
グローバル属性 他
- reversed
属性 - リストが降順
- start
属性 - マーカーの開始値
- type
属性 - マーカーの種類
- reversed
- DOM インターフェイス
-
HTMLOListElement
[Exposed=Window]
interface HTMLOListElement : HTMLElement {
[HTMLConstructor] constructor();
[CEReactions] attribute boolean reversed;
[CEReactions] attribute long start;
[CEReactions] attribute DOMString type;
// also has obsolete members
};
HTMLElement
[Exposed=Window]
interface HTMLElement : Element {
[HTMLConstructor] constructor();
// metadata attributes
[CEReactions] attribute DOMString title;
[CEReactions] attribute DOMString lang;
[CEReactions] attribute boolean translate;
[CEReactions] attribute DOMString dir;
// user interaction
[CEReactions] attribute (boolean or unrestricted double or DOMString)? hidden;
[CEReactions] attribute DOMString inert;
undefined click();
[CEReactions] attribute DOMString accessKey;
readonly attribute DOMString accessKeyLabel;
[CEReactions] attribute boolean draggable;
[CEReactions] attribute boolean spellcheck;
[CEReactions] attribute DOMString writingSuggestions;
[CEReactions] attribute DOMString autocapitalize;
[CEReactions] attribute [LegacyNullToEmptyString] DOMString innerText;
[CEReactions] attribute [LegacyNullToEmptyString] DOMString outerText;
ElementInternals attachInternals();
// The popover API
undefined showPopover();
undefined hidePopover();
boolean togglePopover(optional boolean force);
[CEReactions] attribute DOMString? popover;
};
HTMLElement includes GlobalEventHandlers;
HTMLElement includes ElementContentEditable;
HTMLElement includes HTMLOrSVGElement;
Element
[Exposed=Window]
interface Element : Node {
readonly attribute DOMString? namespaceURI;
readonly attribute DOMString? prefix;
readonly attribute DOMString localName;
readonly attribute DOMString tagName;
[CEReactions] attribute DOMString id;
[CEReactions] attribute DOMString className;
[SameObject, PutForwards=value] readonly attribute DOMTokenList classList;
[CEReactions, Unscopable] attribute DOMString slot;
boolean hasAttributes();
[SameObject] readonly attribute NamedNodeMap attributes;
sequence<DOMString> getAttributeNames();
DOMString? getAttribute(DOMString qualifiedName);
DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
[CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value);
[CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value);
[CEReactions] undefined removeAttribute(DOMString qualifiedName);
[CEReactions] undefined removeAttributeNS(DOMString? namespace, DOMString localName);
[CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
boolean hasAttribute(DOMString qualifiedName);
boolean hasAttributeNS(DOMString? namespace, DOMString localName);
Attr? getAttributeNode(DOMString qualifiedName);
Attr? getAttributeNodeNS(DOMString? namespace, DOMString localName);
[CEReactions] Attr? setAttributeNode(Attr attr);
[CEReactions] Attr? setAttributeNodeNS(Attr attr);
[CEReactions] Attr removeAttributeNode(Attr attr);
ShadowRoot attachShadow(ShadowRootInit init);
readonly attribute ShadowRoot? shadowRoot;
Element? closest(DOMString selectors);
boolean matches(DOMString selectors);
boolean webkitMatchesSelector(DOMString selectors); // legacy alias of .matches
HTMLCollection getElementsByTagName(DOMString qualifiedName);
HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
HTMLCollection getElementsByClassName(DOMString classNames);
[CEReactions] Element? insertAdjacentElement(DOMString where, Element element); // legacy
undefined insertAdjacentText(DOMString where, DOMString data); // legacy
};
GlobalEventHandlers
interface mixin GlobalEventHandlers {
attribute EventHandler onabort;
attribute EventHandler onauxclick;
attribute EventHandler onbeforeinput;
attribute EventHandler onbeforematch;
attribute EventHandler onbeforetoggle;
attribute EventHandler onblur;
attribute EventHandler oncancel;
attribute EventHandler oncanplay;
attribute EventHandler oncanplaythrough;
attribute EventHandler onchange;
attribute EventHandler onclick;
attribute EventHandler onclose;
attribute EventHandler oncontextlost;
attribute EventHandler oncontextmenu;
attribute EventHandler oncontextrestored;
attribute EventHandler oncopy;
attribute EventHandler oncuechange;
attribute EventHandler oncut;
attribute EventHandler ondblclick;
attribute EventHandler ondrag;
attribute EventHandler ondragend;
attribute EventHandler ondragenter;
attribute EventHandler ondragleave;
attribute EventHandler ondragover;
attribute EventHandler ondragstart;
attribute EventHandler ondrop;
attribute EventHandler ondurationchange;
attribute EventHandler onemptied;
attribute EventHandler onended;
attribute OnErrorEventHandler onerror;
attribute EventHandler onfocus;
attribute EventHandler onformdata;
attribute EventHandler oninput;
attribute EventHandler oninvalid;
attribute EventHandler onkeydown;
attribute EventHandler onkeypress;
attribute EventHandler onkeyup;
attribute EventHandler onload;
attribute EventHandler onloadeddata;
attribute EventHandler onloadedmetadata;
attribute EventHandler onloadstart;
attribute EventHandler onmousedown;
[LegacyLenientThis] attribute EventHandler onmouseenter;
[LegacyLenientThis] attribute EventHandler onmouseleave;
attribute EventHandler onmousemove;
attribute EventHandler onmouseout;
attribute EventHandler onmouseover;
attribute EventHandler onmouseup;
attribute EventHandler onpaste;
attribute EventHandler onpause;
attribute EventHandler onplay;
attribute EventHandler onplaying;
attribute EventHandler onprogress;
attribute EventHandler onratechange;
attribute EventHandler onreset;
attribute EventHandler onresize;
attribute EventHandler onscroll;
attribute EventHandler onscrollend;
attribute EventHandler onsecuritypolicyviolation;
attribute EventHandler onseeked;
attribute EventHandler onseeking;
attribute EventHandler onselect;
attribute EventHandler onslotchange;
attribute EventHandler onstalled;
attribute EventHandler onsubmit;
attribute EventHandler onsuspend;
attribute EventHandler ontimeupdate;
attribute EventHandler ontoggle;
attribute EventHandler onvolumechange;
attribute EventHandler onwaiting;
attribute EventHandler onwebkitanimationend;
attribute EventHandler onwebkitanimationiteration;
attribute EventHandler onwebkitanimationstart;
attribute EventHandler onwebkittransitionend;
attribute EventHandler onwheel;
};
ElementContentEditable
interface mixin ElementContentEditable {
[CEReactions] attribute DOMString contentEditable;
[CEReactions] attribute DOMString enterKeyHint;
readonly attribute boolean isContentEditable;
[CEReactions] attribute DOMString inputMode;
};
HTMLOrSVGElement
interface mixin HTMLOrSVGElement {
[SameObject] readonly attribute DOMStringMap dataset;
attribute DOMString nonce; // intentionally no [CEReactions]
[CEReactions] attribute boolean autofocus;
[CEReactions] attribute long tabIndex;
undefined focus(optional FocusOptions options = {});
undefined blur();
};
- ARIA in HTML
-
暗黙的="
list
" ARIAロール="あり" aria-* 属性="GlobalAny
"暗黙的な ARIAセマンティクスは、
role=list
です。作成者が要素に指定してもよい ARIAロール値は、 group, listbox, menu, menubar, none, presentation, radiogroup, tablist, toolbar, tree です。
グローバル aria-* 属性と、許可されたロールに適用される任意の aria-* 属性が記述できます。
- レンダリング
- ブロック
ボックス リスト
ol {
display: block;
margin-block: 1em;
padding-inline-start: 40px;
counter-reset: list-item;
list-style-type: decimal;
unicode-bidi: isolate;
}
:is(dir, dl, menu, ol, ul) ol { margin-block: 0; }
ol[type="1"] { list-style-type: decimal; }
ol[type=a s] { list-style-type: lower-alpha; }
ol[type=A s] { list-style-type: upper-alpha; }
ol[type=i s] { list-style-type: lower-roman; }
ol[type=I s] { list-style-type: upper-roman; }
CSS を大雑把に読むと、 ブロックレベルのブロックコンテナボックス(ブロックボックス)を生成します。 などになります。
- 説明
-
ol
要素 は、順序付けられている項目の一覧を表します。ol
要素 は、項目(アイテム・item)の一覧(リスト・list)を表します。項目が意図的に順序付けられている為、順序を変更すると文書(ドキュメント・document)の意味が変わります。項目の順序に意味がない場合は、ul要素を用います。
リストの項目は、ol要素の li要素の子ノードで、ツリー順になっています。<!DOCTYPE html>
<html lang=
"ja"> <head>
<meta charset=
"utf-8"> <title>ol要素の例 - (Example of ol element) | 離珠のHTMLでしぃ!</title>
</head>
<body>
<h1>ol要素の例</h1>
<ol>
<li>1番目のアイテム</li>
<li>2番目のアイテム</li>
</ol>
</body>
</html>
このサンプルへのリンクです。
(./exol.htm) - 参照元
-
参照元
- HTML Living Standard. 4.4.5 The ol element (Last Updated 27 August 2024)
- HTML Living Standard. 15 Rendering 15.3.7 Lists (Last Updated 27 August 2024)
- HTML 5.2 W3C 勧告. 4.4.6 The ol element (W3C勧告、2017年12月14日)
- HTML 5.2 W3C 勧告. 10.3.8. Lists (W3C勧告、2017年12月14日)
- HTML 5.1 W3C 勧告. 4.4.5 The ol element (W3C勧告、2016年11月1日)
- HTML 5.1 W3C 勧告. 10.3.8. Lists (W3C勧告、2016年11月1日)
- HTML 5 W3C 勧告. 4.4.5 The ol element (W3C勧告、2014年10月28日)
- HTML 5 W3C 勧告. 10.3.8 Lists (W3C勧告、2014年10月28日)
- HTML 4.01 Specification W3C 勧告. 10.2 Unordered lists (UL), ordered lists (OL), and list items (LI) (W3C勧告1999年12月24日)
- HTML 3.2 Reference Specification (W3C勧告1997年1月14日)
- Hypertext Markup Language - 2.0 (November 1995)
- Hypertext Markup Language (HTML) (June 1993)
- <ol>: 順序付きリスト要素 - HTML: ハイパーテキストマークアップ言語 | MDN
- JSONデータ
-
JSON形式での、データのイメージです。
{
"ol": {
"check": "2024-09-01",
"group": "List",
"element": "- - (li)* +(%Scriptsupporting) -- ordered list. (Normal elements.) [Flow|PalpableLimited] --",
"attlist": {
"%Global;": "",
"reversed": "(reversed) #IMPLIED -- Number the list backwards --",
"start": "NUMBER #IMPLIED -- Starting value of the list --",
"type": "CDATA #IMPLIED -- Kind of list marker --",
},
"comment": "順序付き一覧 (ordered list)",
"point": "順序付けられている項目の一覧を表します。",
"description": [
"項目(アイテム・item)の一覧(リスト・list)を表します。項目が意図的に順序付けられている為、順序を変更すると文書(ドキュメント・document)の意味が変わります。項目の順序に意味がない場合は、ul要素を用います。",
"リストの項目は、ol要素の li要素の子ノードで、ツリー順になっています。",
],
"kind": "Normal",
"categories": [
"Flow",
"PalpableLimited",
],
"categoriessupplement": "要素の子に少なくとも1つの li要素が含まれる場合は、パルパブルコンテンツ。",
"used": "parent (%Flow)*",
"contentmodel": "ol (li)* +(%Scriptsupporting)",
"tag": [
"-",
"-",
],
"attributes": {
"reversed": "リストが降順",
"start": "マーカーの開始値",
"type": "マーカーの種類",
},
"dominterface": "HTMLOListElement",
"rendering": [
"Lists",
"Bidirectional",
],
"reference": [
{
"title": "HTML Living Standard. 4.4.5 The ol element.",
"href": "https://html.spec.whatwg.org/multipage/grouping-content.html#the-ol-element",
"heading": "HTML Living Standard. 4.4.5 The ol element",
"sub": "Last Updated 27 August 2024",
},
{
"title": "HTML Living Standard. 15 Rendering 15.3.7 Lists.",
"href": "https://html.spec.whatwg.org/multipage/rendering.html#lists",
"heading": "HTML Living Standard. 15 Rendering 15.3.7 Lists",
"sub": "Last Updated 27 August 2024",
},
{
"title": "HTML 5.2 W3C Recommendation. 4.4.6 The ol element. W3C Recommendation, 14 December 2017.",
"href": "https://www.w3.org/TR/2017/REC-html52-20171214/grouping-content.html#the-ol-element",
"heading": "HTML 5.2 W3C 勧告. 4.4.6 The ol element",
"sub": "W3C勧告、2017年12月14日",
},
{
"title": "HTML 5.2 W3C Recommendation. 10.3.8. Lists.",
"href": "https://www.w3.org/TR/2017/REC-html52-20171214/rendering.html#section-lists",
"heading": "HTML 5.2 W3C 勧告. 10.3.8. Lists",
"sub": "W3C勧告、2017年12月14日",
},
{
"title": "HTML 5.1 W3C Recommendation. 4.4.5 The ol element. W3C Recommendation, 1 November 2016.",
"href": "https://www.w3.org/TR/2016/REC-html51-20161101/grouping-content.html#the-ol-element",
"heading": "HTML 5.1 W3C 勧告. 4.4.5 The ol element",
"sub": "W3C勧告、2016年11月1日",
},
{
"title": "HTML 5.1 W3C Recommendation. 10.3.8. Lists. W3C Recommendation, 1 November 2016.",
"href": "https://www.w3.org/TR/2016/REC-html51-20161101/rendering.html#section-lists",
"heading": "HTML 5.1 W3C 勧告. 10.3.8. Lists",
"sub": "W3C勧告、2016年11月1日",
},
{
"title": "HTML 5 W3C Recommendation. 4.4.5 The ol element. W3C Recommendation, 28 October 2014.",
"href": "https://www.w3.org/TR/2014/REC-html5-20141028/grouping-content.html#the-ol-element",
"heading": "HTML 5 W3C 勧告. 4.4.5 The ol element",
"sub": "W3C勧告、2014年10月28日",
},
{
"title": "HTML 5 W3C Recommendation. 10.3.8 Lists. W3C Recommendation, 28 October 2014.",
"href": "https://www.w3.org/TR/2014/REC-html5-20141028/rendering.html#lists",
"heading": "HTML 5 W3C 勧告. 10.3.8 Lists",
"sub": "W3C勧告、2014年10月28日",
},
{
"title": "HTML 4.01 Specification W3C Recommendation. 10.2 Unordered lists (UL), ordered lists (OL), and list items (LI). W3C Recommendation 24 December 1999.",
"href": "https://www.w3.org/TR/html401/struct/lists.html#h-10.2",
"heading": "HTML 4.01 Specification W3C 勧告. 10.2 Unordered lists (UL), ordered lists (OL), and list items (LI)",
"sub": "W3C勧告1999年12月24日",
},
{
"title": "HTML 3.2 Reference Specification. W3C Recommendation 14-Jan-1997.",
"href": "https://www.w3.org/TR/2018/SPSD-html32-20180315/",
"heading": "HTML 3.2 Reference Specification",
"sub": "W3C勧告1997年1月14日",
},
{
"title": "Hypertext Markup Language - 2.0. November 1995.",
"href": "https://www.ietf.org/rfc/rfc1866.txt",
"heading": "Hypertext Markup Language - 2.0",
"sub": "November 1995",
},
{
"title": "Hypertext Markup Language (HTML). June 1993.",
"href": "https://www.w3.org/MarkUp/draft-ietf-iiir-html-01.txt",
"heading": "Hypertext Markup Language (HTML)",
"sub": "June 1993",
},
{
"title": "MDN Web Docs. HTML <ol>: The Ordered List element.",
"href": "https://developer.mozilla.org/ja/docs/Web/HTML/Element/ol",
"heading": "<ol>: 順序付きリスト要素 - HTML: ハイパーテキストマークアップ言語 | MDN",
},
],
"version": {
"first": "HTML",
"latest": "HTML Living Standard",
},
}
}
注意: 簡易に描画する為に、各項目の後ろに
,
を付与しています。JSON の形式では、末尾の項目の後には,
は付けません。 - 最終確認日
-
2024-09-01
2.使用可能な箇所
フロー
受け入れる要素に
配置できます。
3.配置できるコンテンツ
li要素
を
配置できます。
ol
script
content
<ol>
<li>一覧項目</li>
</ol>
ol
4.属性
グローバル属性と、
reversed属性,
start属性,
type属性 を
設定できます。
ol
reversed属性
<ol
>
reversed
- リスト1
- リスト2
- リスト3
start属性
<ol start=
"">
start
- リスト1
- リスト2
- リスト3
type属性
<ol type=
"">
type
- リスト1
- リスト2
- リスト3
組み合わせ
<ol
start= "" type= "">
reversed
- リスト1
- リスト2
- リスト3
5.Web API
id属性を用いて
getElementById()メソッドで
要素を取得する方法がお勧めです。
ol
6.レンダリング
ol {
display: block;
margin-block-start: 1em;
margin-block-end: 1em;
padding-inline-start: 40px;
counter-reset: list-item;
list-style-type: decimal;
unicode-bidi: isolate;
}
ol
ブロック
list-style-type
は、リスト項目要素のマーカーを設定します。decimal
は、数値です。1 から始まります。
unicode-bidi
は、置換されない要素のレンダリングでの Bidirectional text(双方向テキスト) に於いての期待される仕様の様です。
:is(dir, dl, menu, ol, ul) ol {
margin-block-start: 0;
margin-block-end: 0;
}
ol[type="1"] { list-style-type: decimal; }
ol[type=a s] { list-style-type: lower-alpha; }
ol[type=A s] { list-style-type: upper-alpha; }
ol[type=i s] { list-style-type: lower-roman; }
ol[type=I s] { list-style-type: upper-roman; }
ol
<div style=
"list-style-type: "> <p>
リスト1 </p> <p>
リスト2 </p> <p>
リスト3 </p> </div>
list-style-type
リスト1
リスト2
リスト3
<div class=
"cdvSample162"> <p>
リスト1 </p> <p>
リスト2 </p> <p>
リスト3 </p> </div>
.cdvSample162 {
padding-left: 2.0em;
counter-reset: ndvDemo162 ;
}
.cdvSample162 > *:first-child ~ * {
counter-increment: ndvDemo162 ;
}
.cdvSample162 > *:before {
content: counter(ndvDemo162, ) ".";
position: absolute;
width: 2.2em;
left: -2.5em; text-align: right;;
text-align: right;;
}
.cdvSample162 > * {
position: relative;
margin: 0;
}
スタイルシートをstyle
尚、例示で動的に表現する為に、Javascript でスタイルシートを操作していますが、疑似要素の関係で用意したセレクタを選択する方法で動作させています。
リスト1
リスト2
リスト3
<ol class=
"colSample163"> <li>
リスト1 </li> <li>
リスト2 </li> <li>
リスト3 </li> </ol>
.colSample163 {
list-style-type: none;
}
.colSample163 > * {
position: relative;
}
.colSample163 > *:before {
position: absolute;
left: -2.5em;
content: counter(list-item);
display: table-cell;
vertical-align: middle;
text-align: center;
width: 1.8em;
border-radius: 50%;
background: #F6A38B;
}
マーカーの装飾例です。list-style-typenone
を指定して、改めて疑似要素でマーカーを表しています。
カウンタを list-item そのまま使用した例示です。
- リスト1
- リスト2
- リスト3
7.気を付ける点
順序
順序に意味のある項目の一覧を表しているので、単なる番号付けとは違います。ol
マーカーの領域
マーカーは一覧に表される項目に付けられます。既定値ではボックスの外に配置されます。マーカーの領域も事前に配慮する必要があります。
項目の一覧
項目の一覧を表しているので、大きなグループなど規模についても考慮が必要かと思います。区分(セクション)などは、順序に意味があってもまとまりが少々大きいかと思います。区分(セクション)の目次などは適切かと思います。
区分(セクション)を開閉式にして一覧できる状態にするという方法もあるので、一概に可否は問えない気を付けるべき事だと思います。