AttRibutes
Code Highlight
What is this page about?

Attributes, by Finsweet, offers a free series of Solutions that provide essential features to improve your Webflow websites.

Code Highlight

Show custom code blocks with syntax highlighting and theme support in Webflow

Code Highlight • Flash Card

Copy Script

For advanced users familiar with this solution. Includes all attributes from this page. Click on attributes and values to copy them.

Required and Optional attributes

Code

Add to Embed or Embed's parent

fs-codehighlight-element
=
"
code
"

Theme

Add to Code element

fs-codehighlight-theme
=
"
THEME_NAME
"
1

Add this <script> inside the <head> tag of your page or project

This script is the universal Attribute script: you only need to include it once, even if you have multiple Attribute solutions on the page. Learn more .

<script async type="module"
src="https://cdn.jsdelivr.net/npm/@finsweet/attributes@2/attributes.js"
fs-codehighlight
></script>

Copy Script
2

Choose the method you want

3

Add this required attribute to the element

Code Embed

Targets the <code> in an embed element
fs-codehighlight-element
=
"
code
"

This enables Code Highlight for this specific embed instance, ideal for implementing Code Highlight in one or a few instances.

Add this attribute:
Name
fs-codehighlight-element
Copy
Value
code
Copy
Add it to those type(s) of element(s):
Embed
3

Add this required attribute to the element

Parent element with Code

Apply to all <code> tags within this parent element
fs-codehighlight-element
=
"
code
"

Place this attribute on the content that contains the code that should be highlighted.

This could be a Rich Text element, a div block, or the page's <body>. Code Highlight will be applied to all <code> tags within this parent element.

Add this attribute:
Name
fs-codehighlight-element
Copy
Value
code
Copy
Add it to those type(s) of element(s):
Rich Text
Div Block
3

Add this required attribute to the element

Code

Apply to specific instance of <code>
fs-codehighlight-element
=
"
code
"

This will apply Code Highlight to this instance of <code>

Add this attribute:
Name
fs-codehighlight-element
Copy
Value
code
Copy
Add it to those type(s) of element(s):
Embed Code Editor
4

Make sure your code follow this format

Code Format

Update code to follow this specific format
<pre><code> &lt;script> YOUR_CODE &lt;script> </code></pre>

Regardless of the method chosen, your code within the Custom Code editor needs to follow a specific format.

  1. The code should be enclosed within <pre><code> YOUR_CODE </code></pre> tags.
  2. All < symbols inside the code must be escaped, especially in the opening and closing <script> or <style> tags. To escape the < character, replace it with &lt; or &#60;.
5

Publish your project! Done, easy right?

Check more elements and settings below
Optional

Add more

settings

Theme

Chose a custom look for your code
fs-codehighlight-theme
=
"
THEME_NAME
"

Unlike Webflow's Code Block element, you have the ability to customize the theme (colors) of the code syntax highlighting.

Below is a selection of themes you can choose from.

To apply a theme, use the theme name as the value of the attribute.

Add this attribute:
Name
fs-codehighlight-theme
Copy
Value
THEME_NAME
Copy
Example:
fs-codehighlight-theme = "a11y-dark"
Add it to any element with
fs-codehighlight-element = "code"
script icon
Script tag
IMPORTANT

If your page contains several code snippets, you only need to apply this attribute once. It's not necessary to add it to every instance. Only one theme can be applied per page; applying multiple themes to a single page is not possible.

NOTE

This Solution is based on Highlight.js. You'll find many more themes and resources there.

You can create your own theme using CSS, though it's advised to select one from the provided list, because creating one from scratch represents a lot of work.

Our favorite themes

highlightjs webflow theme
Name
fs-codehighlight-theme
Copy
Value
webflow
Copy
highlightjs a11y dark theme
Name
fs-codehighlight-theme
Copy
Value
a11y-dark
Copy
highlightjs a11y light theme
Name
fs-codehighlight-theme
Copy
Value
a11y-light
Copy
highlightjs apathy theme
Name
fs-codehighlight-theme
Copy
Value
base16/apathy
Copy
highlightjs black metal theme
Name
fs-codehighlight-theme
Copy
Value
base16/black-metal
Copy
highlightjs grayscale dark theme
Name
fs-codehighlight-theme
Copy
Value
base16/grayscale-dark
Copy
highlightjs grayscale light theme
Name
fs-codehighlight-theme
Copy
Value
base16/grayscale-light
Copy
highlightjs gruvbox light theme
Name
fs-codehighlight-theme
Copy
Value
base16/gruvbox-light-hard
Copy
highlightjs harmonic dark theme
Name
fs-codehighlight-theme
Copy
Value
base16/harmonic16-dark
Copy
highlightjs nebula theme
Name
fs-codehighlight-theme
Copy
Value
base16/nebula
Copy
highlightjs icy dark theme
Name
fs-codehighlight-theme
Copy
Value
base16/icy-dark
Copy
highlightjs sandcastle theme
Name
fs-codehighlight-theme
Copy
Value
base16/sandcastle
Copy
highlightjs vuclan theme
Name
fs-codehighlight-theme
Copy
Value
base16/vulcan
Copy
highlightjs woodland theme
Name
fs-codehighlight-theme
Copy
Value
base16/woodland
Copy
highlightjs googlecode theme
Name
fs-codehighlight-theme
Copy
Value
googlecode
Copy
highlightjs gradient dark theme
Name
fs-codehighlight-theme
Copy
Value
gradient-dark
Copy

Still need help?