# UIAspectRatioConstraint

UIAspectRatioConstraint : `Instance`

## Overview

An instance that can be used to force UI element to maintain its specified aspect ratio even when the element is affected by screen size change or parent element ratio. For example, if aspect ratio is set to 2:1, width will always twice the length of height; if aspect ratio is set to 1:1, it will always be square regardless of its environment.

It is particularly effective when dealing with UI element of which quality drops when a fixed aspect ratio is disturbed, like square image. In addition, even when in situation where UI layout attempts to change element size with UIGridLayout, UIListLayout, or others, aspect ratio limitation is applied on top of other aspect ratios when the size of UI object is determined.

UIAspectRatioConstraint can be controlled only in **client environment**.

## Properties

### AspectRatio

`number`

Specifies which aspect ratio UI element must maintain.

For example, if 2 is given, width become twice height. On the other hands, if vertical ratio must be maintained, use the multiplicative inverse of the number.

This value must be greater than 0 to work properly. An invalid aspect ratio value may prevent limitation conditions from working properly.

#### Code Samples

```lua
local UIAspectRatioConstraint = script.Parent

UIAspectRatioConstraint.AspectRatio = 2
```

### AspectType

`Enum.AspectType`

A way to control how much UI element can be expanded.

If FitWithinMaxSize is selected, object is drawn as big as it does not exceed its actual size (AbsoluteSize); if ScaleWithParentSize is selected, its size will be adjusted as big as it can be based on the size of its parent UI.

#### Code Samples

```lua
local UIAspectRatioConstraint = script.Parent

UIAspectRatioConstraint.AspectType = Enum.AspectType.FitWithinMaxSize
```

### DominantAxis

`Enum.DominantAxis`

Determines in which axis (horizontal or vertical) UI element is adjusted when the UI element tries to become larger than its parent. In other words, it defines the axis that will become a reference point when UI element is adjusted so that it will not exceed its limitation imposed by its parent.

#### Code Samples

```lua
local UIAspectRatioConstraint = script.Parent

UIAspectRatioConstraint.DominantAxis = Enum.DominantAxis.Width
```

## Methods

## Events

## See also

{% content-ref url="/pages/Hgp8bh8C44modKPwUBkg" %}
[GUI](/manual/studio-manual/gui.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.overdare.com/development/api-reference/classes/uiaspectratioconstraint.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
