Bootstrap Code
Bootstrap allows you to display code in two ways:
The first is the
<code>
tag. If you want to display code inline, you should use the<code>
tag.The second is the
<pre>
tag. If the code needs to be displayed as a standalone block element or if the code spans multiple lines, you should use the<pre>
tag.
Make sure that when you use the <pre>
and <code>
tags, the opening and closing tags use the unicode variants: < and >.
Let's look at the following example:
Example
<p><code><header></code> is surrounded as an inline element.</p>
<p>If you need to display code as a standalone block element, use the <pre> tag:</p>
<pre>
<article>
<h1>Article Heading</h1>
</article>
</pre>
The example is shown as follows:
More Examples
Element/Class | Description | Example |
---|---|---|
<var> |
Variable assignment: x = a + b y | Try it |
<kbd> |
Key prompt: CTRL + P | Try it |
<pre> |
Multi-line code | Try it |
<pre class="pre-scrollable"> |
Multi-line code with scrollbar | Try it |
<samp> |
Computer program output: Sample output | Try it |
<code> |
Inline code snippet: span, div | Try it |