> For the complete documentation index, see [llms.txt](https://docs.realmacsoftware.com/elements-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.realmacsoftware.com/elements-docs/elements-language/component/properties-json/general-structure/format.md).

# Format

In some cases, it's advantageous to format a value before it's passed to your element's templates. To achieve this, add a `format` property to the configuration specifying the format string.

**Value formatting is supported by all controls.**

### Basic Example

For example, the following creates a slider ranging from 0-12 with a property called `cardPadding`.

```json
{
  "title": "Card Padding",
  "id": "cardPadding",
  "format": "p-{{value}}",
  "slider": {
    "default": 4,
    "min": 0,
    "max": 12
  }
}
```

If the slider is set to 5 and the template contains

```
{{cardPadding}}
```

the output will be

```
p-4
```

### Arbitrary Value Example

You could also format the control's value to use Tailwind's arbitrary value feature. This would allow your element precise control over all CSS properties. For example, you can control the opacity utility class from Tailwind with a slider:

```json
{
  "title": "Overlay Opacity",
  "id": "overlayOpacity",
  "format": "opacity-[{{value}}%]",
  "slider": {
    "default": 70,
    "min": 0,
    "max": 100
  }
}
```

If the slider is set to 50 and the template contains

```
{{overlayOpacity}}
```

the output will be

```
opacity-[70%]
```

### Advanced CSS Example

You could also format the control's value to output a valid CSS property. For example, if we want to control the translateX CSS property for an accent badge, we can do the following:

```json
{
  "title": "Badge Offset",
  "id": "badgeOffsetX",
  "format": "transform: translateX({{value}}px);",
  "number": {
    "default": 12
  }
}
```

If the number field is set to 50 and the template contains

```
{{badgeOffsetX}}
```

the output will be

```
transform: translateX(12px);
```

Of course, in this case you would want to add this to a CSS template file.

### CSS Custom Property Example

You can even use the format to control a CSS Custom Property (CSS variable). If we take our previous example and expand on it, we might want to instead set a `--badgeOffsetX` CSS custom property with a number input:

```json
{
  "title": "Badge Offset",
  "id": "badgeOffsetX",
  "format": "--badgeOffsetX: {{value}}px;",
  "number": {
    "default": 12
  }
}
```

If the number field is set to 50 and the template contains

```
{{badgeOffsetX}}
```

the output will be

```
--badgeOffsetX: 12px;
```

In this case you would either want to add this to a CSS file, or use an inline style attribute to set the `--translateX`:

```html
// first you would use the CSS custom property in your CSS:
<style>
.myDiv {
  ...
  transform: scale(0.5) translateX(var(--badgeOffsetX, 0));
}
</style>

// now that your class is setup to use the --badgeOffsetX custom property
// you can reassign it locally:
<div class="myDiv" style="{{badgeOffsetX}}"> ... </div>

// this would output:
<div class="myDiv" style="--badgeOffsetX: 12px;"> ... </div>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.realmacsoftware.com/elements-docs/elements-language/component/properties-json/general-structure/format.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
