slug: Web/HTML/Element/code
translation_of: Web/HTML/Element/code
---
摘要
HTML <code>
元素呈现一段计算机代码。默认情况下,它以浏览器的默认等宽字体显示。
- Content categories Flow content, phrasing content, palpable content.
- Permitted content Phrasing content.
- Tag omission {{no_tag_omission}}
- Permitted parent elements Any element that accepts phrasing content.
- DOM interface {{domxref("HTMLElement")}} Up to Gecko 1.9.2 (Firefox 4) inclusive, Firefox implements the {{domxref("HTMLSpanElement")}} 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
{{SpecName('HTML WHATWG', 'text-level-semantics.html#the-code-element', '<code>')}}
{{Spec2('HTML WHATWG')}}
{{SpecName('HTML5 W3C', 'text-level-semantics.html#the-code-element', '<code>')}}
{{Spec2('HTML5 W3C')}}
{{SpecName('HTML4.01', 'struct/text.html#h-9.2.1', '<code>')}}
{{Spec2('HTML4.01')}}
浏览器兼容性
{{CompatibilityTable}}
Feature
Chrome
Firefox (Gecko)
Internet Explorer
Opera
Safari (WebKit)
Basic support
1.0
{{CompatGeckoDesktop("1.0")}}
{{CompatVersionUnknown}}
{{CompatVersionUnknown}}
{{CompatVersionUnknown}}
Feature
Android
Firefox Mobile (Gecko)
IE Phone
Opera Mobile
Safari Mobile
Basic support
{{CompatVersionUnknown}}
{{CompatGeckoMobile("1.0")}}
{{CompatVersionUnknown}}
{{CompatVersionUnknown}}
{{CompatVersionUnknown}}
See also
- {{HTMLElement("samp")}}
- {{HTMLElement("kbd")}}
- {{HTMLElement("command")}}
- {{HTMLElement("var")}}
{{HTMLRef}}