---
name: "up.Preview.prototype.setStyle"
area: "API"
kind: "Instance method"
parent: "up.Preview class"
url: "https://unpoly.com/api/up.Preview.prototype.setStyle"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.Preview class](https://unpoly.com/api/up.Preview.md)</nav>

# up.Preview.prototype.setStyle([element], styles)

Temporarily sets inline CSS styles on an element.

## Example {#example}

This preview temporarily changes the background and foreground colors of the targeted fragment:

```js
up.preview('highlight', function(preview) {
  preview.setStyle({
    'color': 'yellow',
    'background-color': 'red'
  })
})
```

---

## Parameters {#parameters}

### [element=this.fragment] {#element}

(optional)

The element or selector to change.

If omitted, the [targeted fragment](https://unpoly.com/api/up.Preview.prototype.fragment.md) will be changed.

Type: [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) | string

### styles {#styles}

(required)

One or more CSS properties with kebab-case keys.

Type: [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects)

