Code elements

The <code> and <pre> elements are for displaying inline and multiline blocks of code.

On this page

Usage

Use the <code> element for inline code snippets.

<p class="mb-0">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>

Use the <pre> element for multiple lines of code.

<pre class="my-0">
  L          TE
    A       A
      C    V
       R A
       DOU
       LOU
      REUSE
      QUE TU
      PORTES
    ET QUI T'
    ORNE O CI
     VILISÉ
    OTE-  TU VEUX
     LA    BIEN
    SI      RESPI
            RER       - Apollinaire
</pre>

Use <kbd> for input that is typically entered via keyboard.

To edit settings, press <kbd>ctrl</kbd> + <kbd>s</kbd>

Customization

Code elements use the monospace font set by the --font-code CSS variable (the $font-family-code Sass variable). Inline <code> elements only change the font; <pre> blocks also have padding, a background color and rounded corners.

The following Sass variables are available in the theming framework. Those for <code> and <pre> are also available as CSS variables, such as --padding-code.

VariableDescription
$font-size-codeThe font size of <code> and <pre> elements.
$padding-codeThe padding applied to <pre> elements.
$margin-codeThe margin applied to <pre> elements.
$color-codeThe text color of <pre> elements.
$bg-color-codeThe background color of <pre> elements.
$border-radius-codeThe border radius applied to <pre> elements.
$padding-kbdThe padding applied to the <kbd> element.
$color-kbdThe color of the <kbd> element.
$bg-color-kbdThe background color of the <kbd> element.
$font-size-kbdThe font size of the <kbd> element.
$border-color-kbdThe border color of the <kbd> element.
$border-width-kbdThe border width of the <kbd> element.
$border-radius-kbdThe border radius of the <kbd> element.
$shadow-kbdThe box shadow applied to the <kbd> element.

To add syntax highlighting to code blocks in articles, see Adding syntax highlighting.

Questions or feedback about this article? Let us know