{% set code_snippet %}
<h1>Hello world!</h1>
<p>This is a code snippet.</p>
{% endset %}
{% include '@bolt-components-code-snippet/code-snippet.twig' with {
  content: code_snippet,
  lang: 'html',
} only %}| Prop Name | Description | Type | Default Value | Option(s) | 
|---|---|---|---|---|
| attributes | A Drupal-style attributes object with extra attributes to append to this element. | object | — | 
 | 
| content | Content of the code snippet. | any | — | 
 | 
| lang | Code language of the content. Each language comes with its unique syntax highlights. | string | none | 
 | 
| custom_lang_label | Custom language label. Only use this if the actual language label is not desired. | any | — | 
 | 
| mode | Toggle between light and dark syntax highlights, or turn it off. This works independently of Bolt color themes. | string | light | 
 | 
| hide_copy | Hide copy to clipboard from the code snippet header. | boolean | — | 
 | 
| hide_lang_label | Hide the language label from the code snippet header. | boolean | — | 
 | 
npm install @bolt/components-code-snippet<code> element.<code> element to remove any undesired indents or whitespace.import { props } from '@bolt/core-v3.x/utils';import { props } from '@bolt/core-v3.x/utils';{% set code_snippet %}
import { props } from '@bolt/core-v3.x/utils';
{% endset %}
{% include '@bolt-components-code-snippet/code-snippet.twig' with {
  content: code_snippet,
  lang: 'javascript',
} only %}<div class="c-bolt-code-snippet" data-lang="js" data-mode="light">
<pre><code>import { props } from '@bolt/core-v3.x/utils';</code></pre>
</div>{% verbatim %} tag or they will be parsed as code by Twig..my-css {
  display: block;
}import { props } from '@bolt/core-v3.x/utils';<p>Hello World!</p>{% include '@bolt-components-banner/banner.twig' with {
  content: 'This is the banner content.'
} only %}{% set css_code %}
.my-css {
  display: block;
}
{% endset %}
{% set js_code %}
import { props } from '@bolt/core-v3.x/utils';
{% endset %}
{% set html_code %}
<p>Hello World!</p>
{% endset %}
{% set twig_code %}
{# Twig does not allow nested verbatim tags, so the required verbatim tag placement for Twig language code snippets is shown in comments below #}
{# verbatim goes here #}
{% include '@bolt-components-banner/banner.twig' with {
  content: 'This is the banner content.'
} only %}
{# endverbatim goes here #}
{% endset %}
{% include '@bolt-components-code-snippet/code-snippet.twig' with {
  content: css_code,
  lang: 'css',
} only %}
{% include '@bolt-components-code-snippet/code-snippet.twig' with {
  content: js_code,
  lang: 'js',
} only %}
{% include '@bolt-components-code-snippet/code-snippet.twig' with {
  content: html_code,
  lang: 'html',
} only %}
{% include '@bolt-components-code-snippet/code-snippet.twig' with {
  content: twig_code,
  lang: 'twig',
} only %}<div class="c-bolt-code-snippet" data-lang="css" data-mode="light">
<pre><code>.my-css {
  display: block;
}</code></pre>
</div>
<div class="c-bolt-code-snippet" data-lang="js" data-mode="light">
<pre><code>import { props } from '@bolt/core-v3.x/utils';</code></pre>
</div>
<div class="c-bolt-code-snippet" data-lang="html" data-mode="light">
<pre><code><p>Hello World!</p></code></pre>
</div>
<div class="c-bolt-code-snippet" data-lang="twig" data-mode="light">
<pre><code>{% include '@bolt-components-banner/banner.twig' with {
  content: 'This is the banner content.'
} only %}</code></pre>
</div>[data-mode="light"] or [data-mode="dark"] attribute. Otherwise, there will be no syntax highlighting.import { props } from '@bolt/core-v3.x/utils';import { props } from '@bolt/core-v3.x/utils';{% set code_snippet %}
import { props } from '@bolt/core-v3.x/utils';
{% endset %}
{% include '@bolt-components-code-snippet/code-snippet.twig' with {
  content: code_snippet,
  lang: 'javascript',
} only %}
{% include '@bolt-components-code-snippet/code-snippet.twig' with {
  content: code_snippet,
  lang: 'javascript',
  mode: 'dark',
} only %}<div class="c-bolt-code-snippet" data-lang="js" data-mode="light">
<pre><code>import { props } from '@bolt/core-v3.x/utils';</code></pre>
</div>
<div class="c-bolt-code-snippet" data-lang="js" data-mode="dark">
<pre><code>import { props } from '@bolt/core-v3.x/utils';</code></pre>
</div>custom_lang_label prop or the data-custom-lang-label attribute if using HTML.$ echo "Hello World"{% set code_snippet %}
$ echo "Hello World"
{% endset %}
{% include '@bolt-components-code-snippet/code-snippet.twig' with {
  content: code_snippet,
  lang: 'bash',
  custom_lang_label: 'Terminal',
} only %}<div class="c-bolt-code-snippet" data-lang="bash" data-mode="light" data-custom-lang-label="Terminal">
<pre><code>$ echo "Hello World"</code></pre>
</div>hide_lang_label and hide_copy props to hide one or both of these Code Snippet header items.data-hide-lang-label and data-hide-copy attributes..my-css {
  display: block;
}.my-css {
  display: block;
}.my-css {
  display: block;
}{% set code_snippet %}
.my-css {
  display: block;
}
{% endset %}
{% include '@bolt-components-code-snippet/code-snippet.twig' with {
  content: code_snippet,
  lang: 'css',
  hide_lang_label: true,
} only %}
{% include '@bolt-components-code-snippet/code-snippet.twig' with {
  content: code_snippet,
  lang: 'css',
  hide_copy: true,
} only %}
{% include '@bolt-components-code-snippet/code-snippet.twig' with {
  content: code_snippet,
  lang: 'css',
  hide_lang_label: true,
  hide_copy: true,
} only %}<div class="c-bolt-code-snippet c-bolt-code-snippet--light" data-lang="css" data-hide-lang-label>
<pre><code>.my-css {
  display: block;
}</code></pre>
</div>
<div class="c-bolt-code-snippet c-bolt-code-snippet--light" data-lang="css" data-hide-copy>
<pre><code>.my-css {
  display: block;
}</code></pre>
</div>
<div class="c-bolt-code-snippet c-bolt-code-snippet--light" data-lang="css" data-hide-lang-label data-hide-copy>
<pre><code>.my-css {
  display: block;
}</code></pre>
</div>