---
name: "CanvasContext.setGlobalAlpha"
mode: "api"
versionRequirements:
  - { name: "Base Library", version: "2.21.8" }
title: "setGlobalAlpha"
---

## CanvasContext.setGlobalAlpha

> [VERSION] Base Library >= 2.21.8

### Description

Set global alpha

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `alpha` | `number` | Yes | Opacity in the range 0–1 |

### Return Value

None


### Examples

#### Set opacity

```ts
const ctx = ty.createCanvasContext('myCanvas');
ctx.setGlobalAlpha(0.5);
ctx.setFillStyle('#ff0000');
ctx.fillRect(10, 10, 150, 75);
ctx.draw();
```
