This page was translated from English by the community.Learn more and join the MDN Web Docs community.
<code>: элемент отображения кода
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since июль 2015 г..
Элемент HTML<code> отображает его содержимое в стиле, предназначенном для указания на то, что текст является коротким фрагментом компьютерного кода. По умолчанию текст содержимого отображается с использованием шрифта монопространства по умолчаниюпользовательского агента.
In this article
Интерактивный пример
<p> The <code>push()</code> method adds one or more elements to the end of an array and returns the new length of the array.</p>code { background-color: #eee; border-radius: 3px; font-family: courier, monospace; padding: 0 3px;}| Content categories | Flow content,phrasing content, palpable content. |
|---|---|
| Permitted content | Phrasing content. |
| Tag omission | Нет, открывающий и закрывающий теги обязательны. |
| Permitted parents | Any element that acceptsphrasing 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 theHTMLSpanElement interface for this element. |
Атрибуты
Этот элемент включает в себя толькоглобальные атрибуты.
Пример
Текстовый абзац, включающий<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>Вывод, генерируемый этим HTML, выглядит так:
Примечания
Для представления нескольких строк кода, оберните элемент<code> в элемент<pre>. Элемент<code> сам по себе представляет только один элемент кода или строку кода.
CSS-правило может быть определено для того, чтобы селекторcode переопределил шрифт браузера по умолчанию. Предпочтения, установленные пользователем, могут иметь приоритет над указанными CSS.
Спецификации
| Specification |
|---|
| HTML> # the-code-element> |