HTML Code 元素(<code>)表現出電腦程式碼的片段。通常,它會由瀏覽器預設的 monospace 字體顯示出來。
| 內容分類 | 流內容、段落式内容、捫及內容 |
|---|---|
| 允許內容 | 段落式内容. |
| 標籤省略 | None, both the starting and ending tag are mandatory. |
| 允許父元素 | 任何允許段落式内容的元素。 |
| DOM 介面 | HTMLElement。Gecko 1.9.2 (Firefox 4) 以前,Firefox 針對這個元素使用 HTMLSpanElement 介面實做。 |
屬性
這個元素只支援全域屬性。
例子
<p> Regular text. <code> This is code. </code> Regular text. </p>
結果
Regular text. This is code. Regular text.
註記
CSS 的 code 選擇器設定可以透過蓋過瀏覽器預設,而用戶個人設定可以蓋過 CSS 設定。
規範
| 規範 | 狀態 | 註解 |
|---|---|---|
| WHATWG HTML Living Standard The definition of '<code>' in that specification. |
Living Standard | |
| HTML5 The definition of '<code>' in that specification. |
Recommendation | |
| HTML 4.01 Specification The definition of '<code>' in that specification. |
Recommendation |
瀏覽器相容性
| 特徵 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| 基本支援 | 1.0 | 1.0 (1.7 or earlier) | (Yes) | (Yes) | (Yes) |
| 特徵 | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| 基本支援 | (Yes) | 1.0 (1.0) | (Yes) | (Yes) | (Yes) |