<code>
摘要
HTML <code>
元素呈现一段计算机代码。默认情况下,它以浏览器的默认等宽字体显示。
- Content categories (en-US) Flow content (en-US), phrasing content (en-US), palpable content.
- Permitted content Phrasing content (en-US).
- Tag omission 不允许,开始标签和结束标签都不能省略。
- Permitted parent elements Any element that accepts phrasing content (en-US).
- DOM interface
HTMLElement
Up to Gecko 1.9.2 (Firefox 4) inclusive, Firefox implements theHTMLSpanElement
interface for this element.
属性
此元素仅包含 全局属性 (en-US).
例子
html
<p>Regular text. <code>This is code.</code> Regular text.</p>
结果
Regular text. This is code.
Regular text.
(中文的等宽字和正常字看起来区别不大,因为汉字本身就是方块行。但是仍能看出几行文字之间的对齐差异)
注意
CSS 规则可以覆盖浏览器默认的 code
标签字体样式。但用户设置的浏览器字体选项可能会超过 CSS 的优先级,使之无效。
规范
Specification |
---|
HTML Standard # the-code-element |
浏览器兼容性
BCD tables only load in the browser