HTML
<code>
element
displays its contents styled in a fashion intended to indicate that the text is a short fragment of computer code.
By default, the content text is displayed using the
user agent's
default monospace font.
| 内容类别 | 流内容 , 措词内容 ,可触及内容。 |
|---|---|
| 准许内容 | 措词内容 . |
| Tag omission | None, both the starting and ending tag are mandatory. |
| Permitted parents | Any element that accepts 措词内容 . |
| Implicit ARIA role | 无对应角色 |
| Permitted ARIA roles | 任何 |
| DOM 接口 |
HTMLElement
Up to Gecko 1.9.2 (Firefox 4) inclusive, Firefox implements the
HTMLSpanElement
interface for this element.
|
此元素只包括 全局属性 .
A paragraph of text that includes
<code>
:
<p>The function <code>selectAll()</code> highlights all the text in the input field so the user can, for example, copy or delete the text.</p>
The output generated by this HTML looks like this:
To represent multiple lines of code, wrap the
<code>
element within a
<pre>
element. The
<code>
element by itself only represents a single phrase of code or line of code.
A CSS rule can be defined for the
code
selector to override the browser's default font face. Preferences set by the user might take precedence over the specified CSS.
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
code
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 4 | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
完整支持