摘要
HTML <code>
元素呈现一段计算机代码. 默认情况下, 它以浏览器的默认等宽字体显示.
- Content categories Flow content, phrasing content, palpable content.
- Permitted content Phrasing content.
- Tag omission None, both the starting and ending tag are mandatory.
- Permitted parent elements Any element that accepts phrasing content.
- DOM interface
HTMLElement
Up to Gecko 1.9.2 (Firefox 4) inclusive, Firefox implements theHTMLSpanElement
interface for this element.
属性
此元素仅包含 全局属性.
例子
<p>Regular text. <code>This is code.</code> Regular text.</p>
结果
Regular text. This is code.
Regular text.
(中文的等宽字和正常字看起来区别不大, 因为汉字本身就是方块行. 但是仍能看出几行文字之间的对齐差异)
注意
CSS 规则可以覆盖浏览器默认的 code
标签字体样式. 但用户设置的浏览器字体选项可能会超过 CSS 的优先级, 使之无效.
Specifications
Specification | Status | Comment |
---|---|---|
WHATWG HTML Living Standard | Living Standard | |
HTML5 | Candidate Recommendation | |
HTML 4.01 Specification | Recommendation |
浏览器兼容性
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 1.0 | 1.0 (1.7 or earlier) | (Yes) | (Yes) | (Yes) |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | (Yes) | 1.0 (1.0) | (Yes) | (Yes) | (Yes) |