> ## Documentation Index
> Fetch the complete documentation index at: https://docs.webfast.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom code and AI-generated blocks

> Add your own HTML, CSS and scripts to a website, including blocks generated with ChatGPT or Claude.

You can add your own code to your website: tracking scripts, chat widgets, custom styles, or whole sections written by you or by another AI tool. Custom code applies to the website you add it to.

## Where to add code

| Where | Applies to | Use it for |
| - | - | - |
| **Settings** > **Custom Code** | Every page of the website | Tracking scripts, chat widgets, cookie banners, site-wide styles |
| **Page Settings** > **Custom Code** | The current page only | Scripts or styles for one page |
| A custom code block | One spot on a page | A section of HTML, such as a block generated with ChatGPT or Claude |

## Add site-wide code

1. Open your website in the editor.
2. Click **Settings**, then choose **Custom Code**.
3. Paste your code into the header or body section.
4. Save, then publish your site.

Header code loads before `</head>`. Use it for analytics and verification tags:

```html Header example theme={null}
<!-- Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-XXXXXXXXXX');
</script>
```

Body code loads before `</body>`. Use it for chat widgets and other scripts that don't need to load first.

> [!TIP]
>
> Google Analytics, Tag Manager, Clarity, Hotjar and Facebook Pixel have one-click connections in **Settings** > **Integrations**. See [Setting up analytics](https://docs.webfast.ai/tutorials/setting-up-analytics.md).

## Create custom blocks with ChatGPT, Claude or another AI

You can use your own ChatGPT, Claude or other AI account to generate a section of code, then add it to your page as a block. This is useful when you want a fresh creative direction, or when you've used up your Webfast AI credits.

**1. Describe the block**

In your AI tool, describe the block, what it's for and the content it should include. Share your website's fonts, colors and an example of its style.

```text Example prompt theme={null}
Create a responsive pricing section as a single HTML block with scoped CSS.
Three tiers: Starter, Growth, Pro. Use the font "Nunito" and my brand colors
#FAF5EC (background), #3B2A1A (text) and #D89B2B (buttons).
Only use JavaScript if it's needed. The code will be embedded in an existing page,
so don't include <html>, <head> or <body> tags.
```

**2. Add a custom code block**

In the Webfast editor, open the block picker and choose the custom code block option. Paste the code in.

**3. Preview it**

Check the block on desktop, tablet and mobile.

**4. Test and publish**

Click every link, button and interactive element, then publish.

Adding code directly like this doesn't use Webfast AI credits. Your AI tool may have its own usage limits or charges.

### Refine external code with Webfast AI

You can also paste code from ChatGPT, Claude or another tool into the Webfast AI chat. Explain where it should go and how it should fit your site, and Webfast AI integrates and refines it for you. This uses Webfast AI credits.

## Edit an element's code

To change the HTML of something already on your page, click **Select**, click the element, and open the **Code** tab in the Properties panel.

## Best practices

* Scope your CSS so it only affects your block.
* Load third-party scripts with `async` or `defer`.
* Check your code for errors before you paste it.
* Keep a note of what each snippet does.

## Troubleshooting

* **Code isn't showing**: make sure you saved and published, then clear your browser cache.
* **Something looks broken**: open your browser's developer console to look for errors, and remove the most recent snippet to see if that fixes it.
* **Page loads slowly**: load scripts asynchronously and remove snippets you no longer use.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.