File size: 980 Bytes
5b76e0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Background

The `background` rule sets the background color of the widget.

## Syntax

```
background: <COLOR> [<PERCENTAGE>];
```

## Example

This example creates three widgets and applies a different background to each.

=== "background.py"

    ```python
    --8<-- "docs/examples/styles/background.py"
    ```

=== "background.css"

    ```sass
    --8<-- "docs/examples/styles/background.css"
    ```

=== "Output"

    ```{.textual path="docs/examples/styles/background.py"}
    ```

## CSS

```sass
/* Blue background */
background: blue;

/* 20% red backround */
background: red 20%;

/* RGB color */
background: rgb(100,120,200);
```

## Python

You can use the same syntax as CSS, or explicitly set a `Color` object for finer-grained control.

```python
# Set blue background
widget.styles.background = "blue"

from textual.color import Color
# Set with a color object
widget.styles.background = Color.parse("pink")
widget.styles.background = Color(120, 60, 100)
```