> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.laposta.org/llms.txt.

# Making background colours editable with template tags

> Allow the editor to choose the background colour of the entire email or a block in your own HTML template in the editor.

In a custom HTML template, the background colours are fixed. If you want the editor to be able to choose a background colour, add the `lp-bgcolor` attribute to that element, for example to a `table` or a `td`.

> **Note**
>
> These tags only apply to an imported HTML template, not to the drag & drop editor. You can read how to import such a template in [Importing your own HTML template](/hoe-importeer-ik-mijn-sjabloon-vanaf-mijn-eigen-computer).

## Making a background colour editable with `lp-bgcolor`

Add `lp-bgcolor` to the element for which the editor is allowed to choose the background colour. Also give the element a default colour with `bgcolor` and `background-color`. That colour remains in place until the editor chooses a different one. When the editor chooses a colour, Laposta sets it in those same two places. A background image remains in place.

### Options

**`lp-bgcolor`**

Makes the background colour editable. As the value, enter the colours the editor can choose from as comma-separated hex codes, for example `lp-bgcolor="#f4f4f4,#ffffff,#1d3557"`. You can specify up to 12 colours, in the format `#rgb` or `#rrggbb`. The editor sees them in the editor as swatches. If you use `lp-bgcolor` without a value, the editor can choose any colour freely.

---

**`lp-bgcolor-name`**

The name of the colour setting, for example `lp-bgcolor-name="page"`. With this name, you can give other elements the same colour using `lp-bgcolor-follow`. A name starts with a letter and contains only letters, digits and hyphens, up to 30 characters. Give every setting a name. Without a name, a chosen colour may end up on a different setting after re-importing the template.

---

**`lp-bgcolor-label`**

The name the editor sees next to the colour in the editor, for example `lp-bgcolor-label="Background"`. Without a label, the editor sees the name from `lp-bgcolor-name`, and without a name, the words Background color. Do not use `lp-label` for this: that does not work for a background colour.

---

**`lp-bgcolor-follow`**

Gives this element the same colour as the setting with this name, for example `lp-bgcolor-follow="page"`. If the editor chooses a different colour for the page setting, this element changes along with it.

---

### Example

In this example, the editor can choose the colour of a table from three colours:

```html
<table width="600" bgcolor="#ffffff" style="background-color:#ffffff;"
       lp-bgcolor="#ffffff,#fff3d6,#e0f2f1" lp-bgcolor-name="box" lp-bgcolor-label="Box colour">
```

## Using the same colour in multiple places with `lp-bgcolor-follow`

Often, the same colour is used in multiple places, such as on the `body` and on the outer cell of each block. Add `lp-bgcolor-follow` there, with the name of the setting. Only elements with this attribute adopt the chosen colour. In the example below, the `body` gets the colour that the editor chooses under ‘Background’.

### Example

```html
<body bgcolor="#f4f4f4" style="margin:0; background-color:#f4f4f4;" lp-bgcolor-follow="page">
<table width="100%" bgcolor="#f4f4f4" style="background-color:#f4f4f4;"
       lp-bgcolor="#f4f4f4,#ffffff,#1d3557" lp-bgcolor-name="page" lp-bgcolor-label="Background">
```

## One colour for the entire email or per block

If `lp-bgcolor` is outside an `<lp-repeater>`, the editor chooses one colour for the entire email. That colour is located in the sidebar of the editor under ‘Colors’.

If `lp-bgcolor` is inside an [`<lp-layout>`](/tags-om-blokken-te-herhalen), the editor chooses a colour per block. This is done using the palette icon in the block menu.

With ‘Default’, the editor resets the colour to the one from the template.

An `lp-bgcolor-follow` inside a block first looks up the name among the colours for the entire email and then within the block itself. This gives the outer cell of every block the page colour, including in blocks that the editor adds later.

> **Note**
>
> Do not reuse the name of a colour for the entire email inside a layout. The block will not get its own colour in that case.

## Colours in sublayouts

With [sublayouts](/tags-om-blokken-te-herhalen), the editor can switch between variants within a single block, for example a text block with and without a button. If you want the chosen colour to remain when the editor switches variants, give the colour the same name and the same colour list in each sublayout.

```html
<lp-layout lp-label="Text block">
  <lp-sublayout>
    <!-- Variant 1: text only -->
    <table width="600" bgcolor="#ffffff" style="background-color:#ffffff;"
           lp-bgcolor="#ffffff,#fff3d6,#e0f2f1" lp-bgcolor-name="block" lp-bgcolor-label="Block colour">
      <tr>
        <td style="padding:24px;"><lp-multiline><p>Text</p></lp-multiline></td>
      </tr>
    </table>
  </lp-sublayout>
  <lp-sublayout>
    <!-- Variant 2: text with button, with the same name and colour list -->
    <table width="600" bgcolor="#ffffff" style="background-color:#ffffff;"
           lp-bgcolor="#ffffff,#fff3d6,#e0f2f1" lp-bgcolor-name="block" lp-bgcolor-label="Block colour">
      <tr>
        <td style="padding:24px;"><lp-multiline><p>Text</p></lp-multiline></td>
      </tr>
      <tr>
        <td style="padding:0 24px 24px;"><a href="https://www.example.co.uk" style="color:#1d3557;">Read more</a></td>
      </tr>
    </table>
  </lp-sublayout>
</lp-layout>
```

If the editor chooses light yellow (`#fff3d6`) in the first variant and switches to the second, the block stays light yellow.

Two things differ between the values of `lp-sublayout-content` on the layout:

* With `shared` (the default), each variant can have its own colour list. If the chosen colour is not in the list of the other variant, that variant gets the colour from the template again. Here, an `lp-bgcolor-follow` in a variant only finds the colours for the entire email and those in its own variant.
* With `individual`, a name applies across all variants together. In that case, give the colour the same list everywhere, or place it in one variant and use `lp-bgcolor-follow` in the others.

## A complete example

This template has a page colour from a list, a header in a free colour and text blocks with their own colour per block. You can import it to try it out.

```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Newsletter</title>
</head>
<body bgcolor="#f4f4f4" style="margin:0; background-color:#f4f4f4;" lp-bgcolor-follow="page">

<!-- The page colour: one colour for the entire email, from a list -->
<table width="100%" cellpadding="0" cellspacing="0" bgcolor="#f4f4f4" style="background-color:#f4f4f4;"
       lp-bgcolor="#f4f4f4,#ffffff,#1d3557" lp-bgcolor-name="page" lp-bgcolor-label="Background">
  <tr>
    <td align="center">

      <!-- The header: any colour -->
      <table width="600" cellpadding="0" cellspacing="0" bgcolor="#1d3557" style="background-color:#1d3557;"
             lp-bgcolor lp-bgcolor-name="header" lp-bgcolor-label="Header colour">
        <tr>
          <td style="padding:24px; color:#ffffff;"><lp-singleline lp-label="Title">Newsletter</lp-singleline></td>
        </tr>
      </table>

      <lp-repeater lp-label="Content">
        <lp-layout lp-label="Text block">
          <table width="100%" cellpadding="0" cellspacing="0">
            <tr>
              <!-- The outer cell follows the page colour, in every block -->
              <td align="center" bgcolor="#f4f4f4" style="background-color:#f4f4f4;" lp-bgcolor-follow="page">

                <!-- The block colour: a separate colour per block, from a list -->
                <table width="600" cellpadding="0" cellspacing="0" bgcolor="#ffffff" style="background-color:#ffffff;"
                       lp-bgcolor="#ffffff,#fff3d6,#e0f2f1" lp-bgcolor-name="block" lp-bgcolor-label="Block colour">
                  <tr>
                    <td style="padding:24px;"><lp-multiline><p>Text</p></lp-multiline></td>
                  </tr>
                  <tr>
                    <!-- This strip follows the block colour -->
                    <td height="16" bgcolor="#ffffff" style="background-color:#ffffff;" lp-bgcolor-follow="block"></td>
                  </tr>
                </table>

              </td>
            </tr>
          </table>
        </lp-layout>
      </lp-repeater>

    </td>
  </tr>
</table>

<lp-unsubscribe>Unsubscribe</lp-unsubscribe>
</body>
</html>
```

## Things to keep in mind

* Only use hex colours. Names such as `white` or `rgb(...)` are skipped by Laposta.
* Do not place the attributes on `<html>`, on Laposta tags such as `<lp-layout>`, inside an [`<lp-multiline>`](/tags-om-tekst-te-wijzigen) or inside conditional comments for Outlook (`<!--[if mso]>`). They do not work there.
* If the text colour is fixed, provide a list of suitable colours. With a free choice, the editor might pick a colour on which the text is [hard to read](/vormgeving-in-het-kader-van-toegankelijkheid).
* Do not use `!important` for a background colour in a `<style>` block, not even for mobile or dark mode. Such a rule overrides the colour the editor chooses. In email clients that use the rule, the old colour will then remain. If you have the CSS inline placed, the old colour will remain in all email clients.
* If an element without `lp-bgcolor` or `lp-bgcolor-follow` gets its background colour from a `<style>` block, it keeps the colour from the template. If the editor chooses a different colour, you will see two colours next to each other. Therefore, also add `lp-bgcolor-follow` to such an element.
* An Outlook background in VML (`v:background`, `v:fill`) keeps the old colour in Outlook for Windows.
* In [dark mode](/donkere-modus-dark-mode), the email client may adjust the colour.

## Warnings during import

If something is not right, for example an `lp-bgcolor-follow` with a name that does not exist or a name that occurs twice, you will see a warning in the import report. The import will still go ahead. Adjust your HTML and import the template again.

> **Note**
>
> [Test a template](/moet-ik-het-geimporteerde-sjabloon-nog-testen) with background colours just like any custom template: choose a different colour in the editor and send a testmail to the email clients that are important to you.

## Related articles

#### [Making blocks repeatable with template tags](/tags-om-blokken-te-herhalen)

Create repeatable blocks and variants in your HTML template with lp-repeater, lp-layout…

#### [What requirements must a custom HTML template meet?](/welke-opties-biedt-laposta-bij-een-zelfgemaakt-sjabloon)

Make your own HTML template suitable for Laposta with editable tags and read how to…

#### [Importing your own HTML template](/hoe-importeer-ik-mijn-sjabloon-vanaf-mijn-eigen-computer)

Add a reusable template from your computer, a URL or as HTML code.

#### [Why do you need to test your own HTML template yourself?](/moet-ik-het-geimporteerde-sjabloon-nog-testen)

Why and how to check the display of your own template in different email clients yourself.