<code>: The Inline Code element - HTML: HyperText Markup Language 编辑
The 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.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.Content categories | Flow content, phrasing content, palpable content. |
---|---|
Permitted content | Phrasing content. |
Tag omission | None, both the starting and ending tag are mandatory. |
Permitted parents | Any element that accepts phrasing content. |
Implicit ARIA role | No corresponding role |
Permitted ARIA roles | Any |
DOM interface | HTMLElement Up to Gecko 1.9.2 (Firefox 4) inclusive, Firefox implements the HTMLSpanElement interface for this element. |
Attributes
This element only includes the global attributes.
Example
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:
Notes
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.
Specifications
Specification | Status | Comment |
---|---|---|
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 |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论