

#
要素について
カテゴリー | フロー・コンテンツ、フレージング・コンテンツ、パルパブル・コンテンツ |
利用場所 | フレージング・コンテンツが置ける場所 |
内容 | フレージング・コンテンツ |
タグの省略 | 不可 |
“code”要素はコンピューター用のコードを表す要素です。
HTMLやXMLの要素、ファイル名、プログラムなどのコンピュータが認識する文字列を表すために使用できます。
サンプルコード
<p>
<code>a</code> 要素に<code>referrerpolicy="no-referrer"</code>と指定するとリンクを開いたときにリファラーを送信しない。
</p>
a
要素にreferrerpolicy="no-referrer"
と指定するとリンクを開いたときにリファラーを送信しない。
一般的なブラウザでは“code”要素の内容は等幅フォントで表示されます。
複数行にまたがるソースコードは“pre”要素の中に“code”要素を配置して表すことができます。
<pre>
<code>
<!------
now = new Date()
document.write("今日は" + now.getFullYear() + "年"
+ (now.getMonth() + 1) + "月"
+ now.getDate() + "日です")
//------>
</code>
</pre>
<!------
now = new Date()
document.write("今日は" + now.getFullYear() + "年"
+ (now.getMonth() + 1) + "月"
+ now.getDate() + "日です")
//------>
#
#
仕様書
“code”要素はHTML2.0から定義されている要素です。現行の仕様であるHTML Living Standardでも定義されています。
DOMインターフェース
“address”要素は“HTMLElement”インターフェイスを使用します。
UAスタイルシート
@namespace url(http://www.w3.org/1999/xhtml);
code {
font-family: monospace;
}