1.仕様
OPTGROUP要素は、
共通のラベルを持つ
option要素のグループを
表します。
- optgroup
-
オプショングループ (option group)
- 種類
-
通常要素
- カテゴリ
-
なし
- 使用できるコンテキスト
-
select
要素 - タグの省略
-
終了タグは省略できます。
- コンテンツ属性
-
グローバル属性 他
- disabled
属性 - フォームコントロールが無効かどうか
- label
属性 - ユーザーに見えるラベル
- disabled
- DOM インターフェイス
-
HTMLOptGroupElement
[Exposed=Window]
interface HTMLOptGroupElement : HTMLElement {
[HTMLConstructor] constructor();
[CEReactions] attribute boolean disabled;
[CEReactions] attribute DOMString label;
};
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
-
暗黙的="
group
" ARIAロール="No
" aria-* 属性="GlobalAny
"暗黙的な ARIAセマンティクスは、
role=group
です。作成者は、暗黙的な ARIAセマンティクス, または HTML要素のネイティブセマンティクスを上書きしてはいけません。
グローバル aria-* 属性と、許可されたロールに適用される任意の aria-* 属性が記述できます。
- レンダリング
- 特になし
optgroup {
0: N;
1: o;
2: t;
3: h;
4: i;
5: n;
6: g;
}
CSS を大雑把に読むと、 特に指定はされていません。既定値から、フローレイアウトに配置されたときにインラインレベルのボックス(インラインボックス)を生成すると思われます。 などになります。
- 説明
-
optgroup
要素 は、共通のラベルを持つoption要素のグループを表します。<!DOCTYPE html>
<html lang=
"ja"> <head>
<meta charset=
"utf-8"> <title>optgroup要素の例 - (Example of optgroup element) | 離珠のHTMLでしぃ!</title>
</head>
<body>
<h1>optgroup要素の例</h1>
<form action=
"../Html/fmreceive.htm"> <select name=
"nseSelect"> <optgroup label=
"alphabet"> <option>abcdef</option>
<option>ghijkl</option>
</optgroup>
<optgroup label=
"number"> <option>123456</option>
<option>789012</option>
</optgroup>
</select>
<button name=
"nbtSender" value= "../Html/exoptgroup.htm">ボタン</button> <br>受信用の<br>ページへ
</form>
</body>
</html>
このサンプルへのリンクです。
(./exoptgroup.htm) - 参照元
-
参照元
- HTML Living Standard. 4.10.9 The optgroup element (Last Updated 27 August 2024)
- HTML 5.2 W3C 勧告. 4.10.9 The optgroup element (W3C勧告、2017年12月14日)
- HTML 5.1 W3C 勧告. 4.10.9 The optgroup element (W3C勧告、2016年11月1日)
- HTML 5 W3C 勧告. 4.10.9 The optgroup element (W3C勧告、2014年10月28日)
- HTML 4.01 Specification W3C 勧告. 17.6 The SELECT, OPTGROUP, and OPTION elements (W3C勧告1999年12月24日)
- <optgroup>: HTML 選択肢グループ要素 - HTML: ハイパーテキストマークアップ言語 | MDN
- JSONデータ
-
JSON形式での、データのイメージです。
{
"optgroup": {
"check": "2024-09-01",
"group": "Form",
"element": "- O (option)* +(%Script) -- option group. (Normal elements.) [None] --",
"attlist": {
"%Global;": "",
"disabled": "(disabled) #IMPLIED -- Whether the form control is disabled --",
"label": "%Text; #IMPLIED -- User-visible label --",
},
"comment": "オプショングループ (option group)",
"point": "共通のラベルを持つoption要素のグループを表します。",
"kind": "Normal",
"categories": "None",
"used": "select",
"contentmodel": "optgroup (option)* +(%Script)",
"tag": [
"-",
"O",
],
"attributes": {
"disabled": "フォームコントロールが無効かどうか",
"label": "ユーザーに見えるラベル",
},
"dominterface": "HTMLOptGroupElement",
"rendering": "None",
"reference": [
{
"title": "HTML Living Standard. 4.10.9 The optgroup element.",
"href": "https://html.spec.whatwg.org/multipage/form-elements.html#the-optgroup-element",
"heading": "HTML Living Standard. 4.10.9 The optgroup element",
"sub": "Last Updated 27 August 2024",
},
{
"title": "HTML 5.2 W3C Recommendation. 4.10.9 The optgroup element. W3C Recommendation, 14 December 2017.",
"href": "https://www.w3.org/TR/2017/REC-html52-20171214/sec-forms.html#the-optgroup-element",
"heading": "HTML 5.2 W3C 勧告. 4.10.9 The optgroup element",
"sub": "W3C勧告、2017年12月14日",
},
{
"title": "HTML 5.1 W3C Recommendation. 4.10.9 The optgroup element. W3C Recommendation, 1 November 2016.",
"href": "https://www.w3.org/TR/2016/REC-html51-20161101/sec-forms.html#the-optgroup-element",
"heading": "HTML 5.1 W3C 勧告. 4.10.9 The optgroup element",
"sub": "W3C勧告、2016年11月1日",
},
{
"title": "HTML 5 W3C Recommendation. 4.10.9 The optgroup element. W3C Recommendation, 28 October 2014.",
"href": "https://www.w3.org/TR/2014/REC-html5-20141028/forms.html#the-optgroup-element",
"heading": "HTML 5 W3C 勧告. 4.10.9 The optgroup element",
"sub": "W3C勧告、2014年10月28日",
},
{
"title": "HTML 4.01 Specification W3C Recommendation. 17.6 The SELECT, OPTGROUP, and OPTION elements. W3C Recommendation 24 December 1999.",
"href": "https://www.w3.org/TR/html401/interact/forms.html#h-17.6",
"heading": "HTML 4.01 Specification W3C 勧告. 17.6 The SELECT, OPTGROUP, and OPTION elements",
"sub": "W3C勧告1999年12月24日",
},
{
"title": "MDN Web Docs. HTML <optgroup>: The HTML Optgroup element.",
"href": "https://developer.mozilla.org/ja/docs/Web/HTML/Element/optgroup",
"heading": "<optgroup>: HTML 選択肢グループ要素 - HTML: ハイパーテキストマークアップ言語 | MDN",
},
],
"version": {
"first": "HTML4",
"latest": "HTML Living Standard",
},
}
}
注意: 簡易に描画する為に、各項目の後ろに
,
を付与しています。JSON の形式では、末尾の項目の後には,
は付けません。 - 最終確認日
-
2024-09-01
2.使用可能な箇所
select要素に
配置できます。
optgroup
3.配置できるコンテンツ
option要素を
配置できます。
optgroupは、子(内容・コンテンツ・Content)として、0 以上の option要素 および script
script
4.属性
グローバル属性と、
disabled,
label を
設定できます。
optgroupは、グローバル属性とdisabled属性, label属性を設定できます。
<form action=
"./fmreceive.htm"> <select name=
"nseSelect"> <optgroup label=
"alphabet"> <option>abcdefg</option>
<option>ghijkl</option>
</optgroup>
<optgroup label=
"number"> <option>123456</option>
<option>789012</option>
</optgroup>
form
buttonnbtSender
で固定です。
disabled属性
<option label=
"alphabet" disabled>
disabledは、コントロールを非対話型にして、その値が送信されないようにする為に使用されるブール属性です。
label属性
<option label=
"alphabet" >
labelは、要素のラベルを提供します。option
label コンテンツ属性が指定されている場合、空であってはなりません。
5.Web API
id属性を用いて
getElementById()メソッドで
要素を取得する方法がお勧めです。
optgroup
6.レンダリング
レンダリングについて
スタイルシートでの
仕様での提案は
特にないようです。
optgroup
optgroup
option
select のラベルの幅は、最も広い optgroup をレンダリングするために必要な幅と、要素のオプションリストで最も広いoption
他の要素を代用して同等のレンダリングをする事を考えたら、リストの1項目という事でdisplay: list-item
が意味的には使えるかもしれません。マーカーを意識する必要があるので、手間は増えますが。
技術的にレンダリングだけを考えたら、ブロックレベルボックスを生成すればよいのでdisplay: block
が使い勝手が良いでしょう。代用する要素をdiv
7.気を付ける点
インターフェース
optgroup
「ユーザー」を意識したページの分かり易さや使い易さ、「作成者」を意識したソースコードの書き易さや読み易さ、「送信先」を意識した送信データの使い易さなど、バランスが大変ですがとりあえず意味ある作りを心掛けましょう。