HTMLの<legend>タグを使うと、入力Formのグループである<fieldset>に表題や説明文を表示することができます。その使い方をサンプルを交えてご紹介します。
<fieldset>
  <legend>
    <!-- phrasing content -->
  </legend>
  <!-- flow content -->
</fieldset>
  <form action="#">
  <fieldset>
    <legend>口座種別</legend>
    <input type="radio" name="account" value="s" id="s" checked>
    <label for="s">普通預金</label>
    <input type="radio" name="account" value="c" id="c">
    <label for="c">当座預金</label>
  </fieldset>
</form>
  legendタグには次の属性を指定できます。
| OS | ウェブブラウザ | アクセスキーの操作方法 | 
|---|---|---|
| Linux | Chrome | Alt + Shift + アクセスキー | 
| Firefox | Alt + Shift + アクセスキー | |
| Mac | Chrome | control + option + アクセスキー | 
| Firefox | control + option + アクセスキー | |
| Safari | control + option + アクセスキー | |
| Windows | Chrome | Alt + アクセスキー | 
| Edge | Alt + アクセスキー | |
| Firefox | Alt + Shift + アクセスキー | |
| Internet Explorer | Alt + アクセスキー | 
<legend class="text-primary">
  Example
</legend>
    <legend id="account-type">
  Example
</legend>
    <fieldset>
  <legend style="color: red;">
    Example
  </legend>
<fieldset>
      
    <fieldset>
  <legend title="口座種別を次のうちから選んでください。">
    口座種別
  </legend>
  <input type="radio" name="account" value="s" id="s" checked>
  <label for="s">普通預金</label>
  <input type="radio" name="account" value="c" id="c">
  <label for="c">当座預金</label>
</fieldset>
      
    legend要素の内容には記述コンテンツおよび見出し(h1 - h6)を含めることができる。
legend要素の親要素はfieldset要素である。
JavaScriptからはHTMLLegendElementインタフェースを通じてHTMLのlegend要素にアクセスできる。
HTMLLegendElementインタフェースは次のプロパティを持つ。
| プロパティ | 型 | 説明 | 
|---|---|---|
| accessKey | DOMString | accessKey属性 | 
| className | DOMString | class属性 | 
| form | HTMLFormElement | legendが属するform要素(読み取り専用) | 
| dir | DOMString | 要素の記述方向 | 
| id | DOMString | id属性 | 
| innerHTML | DOMString | 要素内のHTML | 
| innerText | DOMString | ノードの描画されるテキスト | 
| lang | DOMString | 要素のlang属性 | 
| style | CSSStyleDeclaration | style属性 | 
| tagName | String | 要素のタグ名(読み取り専用) | 
| title | DOMString | title属性 | 
JavaScriptからHTMLLegendElementインタフェースを使ってlegendを操作する例を次に示します。
try {
  element = document.getElementById("account-type");
  form = element.form;
  accessKey = element.accessKey;
} catch (e) {
  console.error(e);
}
  legend要素はどのコンテンツモデルにも属さない。
Web Hypertext Application Technology Working Group (2022) "The legend element" HTML Living Standard