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

The $code_font theme setting determines the font family to use for code elements.

The following Sass variables are available in the theming framework:

VariableDescription
$padding-codeThe padding applied to the <code> element.
$color-codeThe color of the <code> element.
$bg-color-codeThe background color of the <code> element.
$border-radius-codeThe border radius applied to the <code> element.
$padding-preThe padding applied to the <pre> element.
$margin-preThe margin applied to the <pre> element.
$bg-color-preThe background color of the <pre> element.
$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.
$shadow-kbdThe box shadow applied to the <kbd> element.

Questions or feedback about this article? Let us know