# Image

> Represents the SVG <image> (image) element for embedding bitmap images.

[API reference](/docs/api/index.md) › [HTML SVG](/docs/extensions/html-svg/reference/index.md) › Image

| final class | `UIAwesome\Html\Svg\Image` |
| --- | --- |
| Extends | [`UIAwesome\Html\Core\Element\BaseVoid`](/docs/extensions/html-core/reference/element/basevoid/index.md) » [`UIAwesome\Html\Core\Base\BaseTag`](/docs/extensions/html-core/reference/base/basetag/index.md) |
| Implements | [`UIAwesome\Html\Contracts\Attribute\AttributesInterface`](/docs/extensions/html-contracts/reference/attribute/attributesinterface/index.md), [`UIAwesome\Html\Contracts\Element\VoidInterface`](/docs/extensions/html-contracts/reference/element/voidinterface/index.md), [`UIAwesome\Html\Contracts\RenderableInterface`](/docs/extensions/html-contracts/reference/renderableinterface/index.md) |
| Uses traits | [`UIAwesome\Html\Svg\Internal\RendersEmptySvg`](/docs/extensions/html-svg/reference/internal/rendersemptysvg/index.md), [`UIAwesome\Html\Attribute\Global\CanBeHidden`](/docs/extensions/html-attribute/reference/global/canbehidden/index.md), [`UIAwesome\Html\Attribute\Global\HasAccesskey`](/docs/extensions/html-attribute/reference/global/hasaccesskey/index.md), [`UIAwesome\Html\Attribute\Global\HasAria`](/docs/extensions/html-attribute/reference/global/hasaria/index.md), [`UIAwesome\Html\Mixin\HasAttributes`](/docs/extensions/html-mixin/reference/hasattributes/index.md), [`UIAwesome\Html\Attribute\Global\HasClass`](/docs/extensions/html-attribute/reference/global/hasclass/index.md), [`UIAwesome\Html\Attribute\Global\HasData`](/docs/extensions/html-attribute/reference/global/hasdata/index.md), [`UIAwesome\Html\Attribute\Global\HasDir`](/docs/extensions/html-attribute/reference/global/hasdir/index.md), [`UIAwesome\Html\Attribute\Global\HasEvents`](/docs/extensions/html-attribute/reference/global/hasevents/index.md), [`UIAwesome\Html\Attribute\Global\HasId`](/docs/extensions/html-attribute/reference/global/hasid/index.md), [`UIAwesome\Html\Attribute\Global\HasLang`](/docs/extensions/html-attribute/reference/global/haslang/index.md), [`UIAwesome\Html\Attribute\Global\HasRole`](/docs/extensions/html-attribute/reference/global/hasrole/index.md), [`UIAwesome\Html\Attribute\Global\HasStyle`](/docs/extensions/html-attribute/reference/global/hasstyle/index.md), [`UIAwesome\Html\Attribute\Global\HasTitle`](/docs/extensions/html-attribute/reference/global/hastitle/index.md), [`UIAwesome\Html\Attribute\Global\HasTranslate`](/docs/extensions/html-attribute/reference/global/hastranslate/index.md), [`UIAwesome\Html\Core\Event\HasAfterRun`](/docs/extensions/html-core/reference/event/hasafterrun/index.md), [`UIAwesome\Html\Core\Event\HasBeforeRun`](/docs/extensions/html-core/reference/event/hasbeforerun/index.md) |
| Source | [`src/Image.php`](https://github.com/ui-awesome/html-svg/blob/main/src/Image.php#L29) |

Represents the SVG `<image>` (image) element for embedding bitmap images.

Provides a concrete `<image>` element implementation that returns [`SvgVoid::IMAGE`](/docs/extensions/html-svg/reference/tag/svgvoid/index.md#case-IMAGE) and provides linking,
geometry, presentation, and transform attribute methods.

The `<image>` element embeds an external image into the SVG.

See also: <https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image> ([`BaseVoid`](/docs/extensions/html-core/reference/element/basevoid/index.md) for the base implementation.).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-attributes"></span>[`$attributes`](/docs/extensions/html-mixin/reference/hasattributes/index.md#property-attributes) protected | `mixed[]` | HTML attributes array used by the implementing class. Default: `[]`. | [`UIAwesome\Html\Mixin\HasAttributes`](/docs/extensions/html-mixin/reference/hasattributes/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/extensions/html-core/reference/base/basetag/index.md#method-__construct) final | Initializes a new tag instance. | [`UIAwesome\Html\Core\Base\BaseTag`](/docs/extensions/html-core/reference/base/basetag/index.md) |
| <span id="method-__toString"></span>[`__toString()`](/docs/extensions/html-core/reference/base/basetag/index.md#method-__toString) | Returns the rendered tag string. | [`UIAwesome\Html\Core\Base\BaseTag`](/docs/extensions/html-core/reference/base/basetag/index.md) |
| <span id="method-accesskey"></span>[`accesskey()`](/docs/extensions/html-attribute/reference/global/hasaccesskey/index.md#method-accesskey) | Sets the `accesskey` attribute. | [`UIAwesome\Html\Attribute\Global\HasAccesskey`](/docs/extensions/html-attribute/reference/global/hasaccesskey/index.md) |
| <span id="method-addAriaAttribute"></span>[`addAriaAttribute()`](/docs/extensions/html-attribute/reference/global/hasaria/index.md#method-addAriaAttribute) | Sets an `aria-*` attribute. | [`UIAwesome\Html\Attribute\Global\HasAria`](/docs/extensions/html-attribute/reference/global/hasaria/index.md) |
| <span id="method-addAttribute"></span>[`addAttribute()`](/docs/extensions/html-mixin/reference/hasattributes/index.md#method-addAttribute) | Adds or updates a single HTML attribute for the element. | [`UIAwesome\Html\Mixin\HasAttributes`](/docs/extensions/html-mixin/reference/hasattributes/index.md) |
| <span id="method-addDataAttribute"></span>[`addDataAttribute()`](/docs/extensions/html-attribute/reference/global/hasdata/index.md#method-addDataAttribute) | Sets a `data-*` attribute. | [`UIAwesome\Html\Attribute\Global\HasData`](/docs/extensions/html-attribute/reference/global/hasdata/index.md) |
| <span id="method-addEvent"></span>[`addEvent()`](/docs/extensions/html-attribute/reference/global/hasevents/index.md#method-addEvent) | Sets an `on*` event attribute. | [`UIAwesome\Html\Attribute\Global\HasEvents`](/docs/extensions/html-attribute/reference/global/hasevents/index.md) |
| <span id="method-ariaAttributes"></span>[`ariaAttributes()`](/docs/extensions/html-attribute/reference/global/hasaria/index.md#method-ariaAttributes) | Sets multiple `aria-*` attributes. | [`UIAwesome\Html\Attribute\Global\HasAria`](/docs/extensions/html-attribute/reference/global/hasaria/index.md) |
| <span id="method-attributes"></span>[`attributes()`](/docs/extensions/html-mixin/reference/hasattributes/index.md#method-attributes) | Adds or updates multiple HTML attributes for the element. | [`UIAwesome\Html\Mixin\HasAttributes`](/docs/extensions/html-mixin/reference/hasattributes/index.md) |
| <span id="method-class"></span>[`class()`](/docs/extensions/html-attribute/reference/global/hasclass/index.md#method-class) | Sets the `class` attribute. | [`UIAwesome\Html\Attribute\Global\HasClass`](/docs/extensions/html-attribute/reference/global/hasclass/index.md) |
| <span id="method-config"></span>[`config()`](/docs/extensions/html-core/reference/base/basetag/index.md#method-config) | Applies application-scoped config recipes to this tag. | [`UIAwesome\Html\Core\Base\BaseTag`](/docs/extensions/html-core/reference/base/basetag/index.md) |
| <span id="method-dataAttributes"></span>[`dataAttributes()`](/docs/extensions/html-attribute/reference/global/hasdata/index.md#method-dataAttributes) | Sets multiple `data-*` attributes. | [`UIAwesome\Html\Attribute\Global\HasData`](/docs/extensions/html-attribute/reference/global/hasdata/index.md) |
| [`decoding()`](#method-decoding) | Sets the `decoding` attribute. | `Image` |
| <span id="method-dir"></span>[`dir()`](/docs/extensions/html-attribute/reference/global/hasdir/index.md#method-dir) | Sets the `dir` attribute. | [`UIAwesome\Html\Attribute\Global\HasDir`](/docs/extensions/html-attribute/reference/global/hasdir/index.md) |
| <span id="method-events"></span>[`events()`](/docs/extensions/html-attribute/reference/global/hasevents/index.md#method-events) | Sets multiple `on*` event attributes. | [`UIAwesome\Html\Attribute\Global\HasEvents`](/docs/extensions/html-attribute/reference/global/hasevents/index.md) |
| [`fetchpriority()`](#method-fetchpriority) | Sets the `fetchpriority` attribute. | `Image` |
| <span id="method-getAttribute"></span>[`getAttribute()`](/docs/extensions/html-mixin/reference/hasattributes/index.md#method-getAttribute) | Returns the value of a single HTML attribute. | [`UIAwesome\Html\Mixin\HasAttributes`](/docs/extensions/html-mixin/reference/hasattributes/index.md) |
| <span id="method-getAttributes"></span>[`getAttributes()`](/docs/extensions/html-mixin/reference/hasattributes/index.md#method-getAttributes) | Returns the `array` of HTML attributes for the element. | [`UIAwesome\Html\Mixin\HasAttributes`](/docs/extensions/html-mixin/reference/hasattributes/index.md) |
| [`height()`](#method-height) | Sets the `height` attribute. | `Image` |
| <span id="method-hidden"></span>[`hidden()`](/docs/extensions/html-attribute/reference/global/canbehidden/index.md#method-hidden) | Sets the `hidden` attribute. | [`UIAwesome\Html\Attribute\Global\CanBeHidden`](/docs/extensions/html-attribute/reference/global/canbehidden/index.md) |
| [`href()`](#method-href) | Sets the `href` attribute. | `Image` |
| <span id="method-id"></span>[`id()`](/docs/extensions/html-attribute/reference/global/hasid/index.md#method-id) | Sets the `id` attribute. | [`UIAwesome\Html\Attribute\Global\HasId`](/docs/extensions/html-attribute/reference/global/hasid/index.md) |
| <span id="method-lang"></span>[`lang()`](/docs/extensions/html-attribute/reference/global/haslang/index.md#method-lang) | Sets the `lang` attribute. | [`UIAwesome\Html\Attribute\Global\HasLang`](/docs/extensions/html-attribute/reference/global/haslang/index.md) |
| [`opacity()`](#method-opacity) | Sets the SVG `opacity` attribute for the element. | `Image` |
| [`preserveAspectRatio()`](#method-preserveAspectRatio) | Sets the SVG `preserveAspectRatio` attribute for the element. | `Image` |
| <span id="method-removeAriaAttribute"></span>[`removeAriaAttribute()`](/docs/extensions/html-attribute/reference/global/hasaria/index.md#method-removeAriaAttribute) | Removes an `aria-*` attribute. | [`UIAwesome\Html\Attribute\Global\HasAria`](/docs/extensions/html-attribute/reference/global/hasaria/index.md) |
| <span id="method-removeAttribute"></span>[`removeAttribute()`](/docs/extensions/html-mixin/reference/hasattributes/index.md#method-removeAttribute) | Removes a specific HTML attribute from the element. | [`UIAwesome\Html\Mixin\HasAttributes`](/docs/extensions/html-mixin/reference/hasattributes/index.md) |
| <span id="method-removeDataAttribute"></span>[`removeDataAttribute()`](/docs/extensions/html-attribute/reference/global/hasdata/index.md#method-removeDataAttribute) | Removes a `data-*` attribute. | [`UIAwesome\Html\Attribute\Global\HasData`](/docs/extensions/html-attribute/reference/global/hasdata/index.md) |
| <span id="method-removeEvent"></span>[`removeEvent()`](/docs/extensions/html-attribute/reference/global/hasevents/index.md#method-removeEvent) | Removes an `on*` event attribute. | [`UIAwesome\Html\Attribute\Global\HasEvents`](/docs/extensions/html-attribute/reference/global/hasevents/index.md) |
| <span id="method-render"></span>[`render()`](/docs/extensions/html-core/reference/base/basetag/index.md#method-render) final | Renders the tag with lifecycle hooks. | [`UIAwesome\Html\Core\Base\BaseTag`](/docs/extensions/html-core/reference/base/basetag/index.md) |
| <span id="method-replaceAttributes"></span>[`replaceAttributes()`](/docs/extensions/html-mixin/reference/hasattributes/index.md#method-replaceAttributes) | Replaces all HTML attributes for the element. | [`UIAwesome\Html\Mixin\HasAttributes`](/docs/extensions/html-mixin/reference/hasattributes/index.md) |
| <span id="method-role"></span>[`role()`](/docs/extensions/html-attribute/reference/global/hasrole/index.md#method-role) | Sets the `role` attribute. | [`UIAwesome\Html\Attribute\Global\HasRole`](/docs/extensions/html-attribute/reference/global/hasrole/index.md) |
| <span id="method-style"></span>[`style()`](/docs/extensions/html-attribute/reference/global/hasstyle/index.md#method-style) | Sets the `style` attribute. | [`UIAwesome\Html\Attribute\Global\HasStyle`](/docs/extensions/html-attribute/reference/global/hasstyle/index.md) |
| <span id="method-tag"></span>[`tag()`](/docs/extensions/html-core/reference/base/basetag/index.md#method-tag) static | Creates and configures a new tag instance. | [`UIAwesome\Html\Core\Base\BaseTag`](/docs/extensions/html-core/reference/base/basetag/index.md) |
| <span id="method-title"></span>[`title()`](/docs/extensions/html-attribute/reference/global/hastitle/index.md#method-title) | Sets the `title` attribute. | [`UIAwesome\Html\Attribute\Global\HasTitle`](/docs/extensions/html-attribute/reference/global/hastitle/index.md) |
| [`transform()`](#method-transform) | Sets the SVG `transform` attribute for the element. | `Image` |
| <span id="method-translate"></span>[`translate()`](/docs/extensions/html-attribute/reference/global/hastranslate/index.md#method-translate) | Sets the `translate` attribute. | [`UIAwesome\Html\Attribute\Global\HasTranslate`](/docs/extensions/html-attribute/reference/global/hastranslate/index.md) |
| [`width()`](#method-width) | Sets the `width` attribute. | `Image` |
| [`x()`](#method-x) | Sets the SVG `x` attribute for the element. | `Image` |
| [`y()`](#method-y) | Sets the SVG `y` attribute for the element. | `Image` |
| <span id="method-afterRun"></span>[`afterRun()`](/docs/extensions/html-core/reference/event/hasafterrun/index.md#method-afterRun) protected | Post-processes rendered output. | [`UIAwesome\Html\Core\Event\HasAfterRun`](/docs/extensions/html-core/reference/event/hasafterrun/index.md) |
| <span id="method-beforeRun"></span>[`beforeRun()`](/docs/extensions/html-core/reference/event/hasbeforerun/index.md#method-beforeRun) protected | Validates state before rendering. | [`UIAwesome\Html\Core\Event\HasBeforeRun`](/docs/extensions/html-core/reference/event/hasbeforerun/index.md) |
| [`getTag()`](#method-getTag) protected | Returns the tag enumeration for the `<image>` element. | `Image` |
| <span id="method-loadDefault"></span>[`loadDefault()`](/docs/extensions/html-core/reference/base/basetag/index.md#method-loadDefault) protected | Returns class-level default definitions. | [`UIAwesome\Html\Core\Base\BaseTag`](/docs/extensions/html-core/reference/base/basetag/index.md) |
| <span id="method-run"></span>[`run()`](/docs/extensions/html-core/reference/element/basevoid/index.md#method-run) protected | Renders the void element. | [`UIAwesome\Html\Core\Element\BaseVoid`](/docs/extensions/html-core/reference/element/basevoid/index.md) |

## Method details

### decoding() <span id="method-decoding"></span>

```php
public function decoding(string|Stringable|UnitEnum|null $value): static
```

Sets the `decoding` attribute.

Usage example:
```php
$element->decoding('async');
$element->decoding(Decoding::ASYNC);
$element->decoding(null);
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php)`\|null` | Decoding hint value. Use 'async', 'sync', or 'auto', or `null` to remove the attribute. |

**Returns**

`static`: New instance with the updated `decoding` attribute. [`Decoding`](/docs/extensions/html-svg/reference/values/decoding/index.md) for predefined enum values.

### fetchpriority() <span id="method-fetchpriority"></span>

```php
public function fetchpriority(string|UnitEnum|null $value): static
```

Sets the `fetchpriority` attribute.

Usage example:
```php
$element->fetchpriority('high');
$element->fetchpriority(Fetchpriority::HIGH);
$element->fetchpriority(null);
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php)`\|null` | Fetch priority token, or `null` to remove the attribute. |

**Returns**

`static`: New instance with the updated `fetchpriority` attribute. [`Fetchpriority`](/docs/extensions/html-svg/reference/values/fetchpriority/index.md) for predefined enum values.

### height() <span id="method-height"></span>

```php
public function height(int|string|Stringable|UnitEnum|null $value): static
```

Sets the `height` attribute.

Usage example:
```php
$element->height(200);
$element->height('50%');
$element->height('auto');
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `int\|string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php)`\|null` | Height value in pixels or CSS units, or `null` to remove the attribute. |

**Returns**

`static`: New instance with the updated `height` attribute.

### href() <span id="method-href"></span>

```php
public function href(string|Stringable|UnitEnum|null $value): static
```

Sets the `href` attribute.

Usage example:
```php
$element->href('https://example.com/image.png');
$element->href('#image');
$element->href(null);
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php)`\|null` | URL, path, or fragment, or `null` to remove the attribute. |

**Returns**

`static`: New instance with the updated `href` attribute.

### opacity() <span id="method-opacity"></span>

```php
public function opacity(float|int|string|null $value): static
```

Sets the SVG `opacity` attribute for the element.

Creates a new instance with the specified opacity value for the rendered element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `float\|int\|string\|null` | Opacity value (for example, '0.5' or `null` to unset). |

**Returns**

`static`: New instance with the updated `opacity` attribute.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): If the value is outside the allowed range ('0'-'1') and not `null`.

### preserveAspectRatio() <span id="method-preserveAspectRatio"></span>

```php
public function preserveAspectRatio(UIAwesome\Html\Svg\Values\PreserveAspectRatio|string|null $value): static
```

Sets the SVG `preserveAspectRatio` attribute for the element.

Creates a new instance with the specified preserve aspect ratio value for the rendered element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | [`UIAwesome\Html\Svg\Values\PreserveAspectRatio`](/docs/extensions/html-svg/reference/values/preserveaspectratio/index.md)`\|string\|null` | Preserve aspect ratio value (for example, 'xMidYMid meet', [`PreserveAspectRatio`](/docs/extensions/html-svg/reference/values/preserveaspectratio/index.md) enum, or `null` to unset). |

**Returns**

`static`: New instance with the updated `preserveAspectRatio` attribute.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): If the provided value is not a valid [`PreserveAspectRatio`](/docs/extensions/html-svg/reference/values/preserveaspectratio/index.md) enum or `string`.

### transform() <span id="method-transform"></span>

```php
public function transform(string|null $value): static
```

Sets the SVG `transform` attribute for the element.

Creates a new instance with the specified transform value for the rendered element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|null` | Transform value (for example, 'rotate(45)', 'scale(2)', or `null` to unset). |

**Returns**

`static`: New instance with the updated `transform` attribute.

### width() <span id="method-width"></span>

```php
public function width(int|string|Stringable|UnitEnum|null $value): static
```

Sets the `width` attribute.

Usage example:
```php
$element->width(400);
$element->width('50%');
$element->width('auto');
$element->width(null);
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `int\|string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php)`\|null` | Width value in pixels or CSS units, or `null` to remove the attribute. |

**Returns**

`static`: New instance with the updated `width` attribute.

### x() <span id="method-x"></span>

```php
public function x(float|int|string|null $value): static
```

Sets the SVG `x` attribute for the element.

Creates a new instance with the specified x-coordinate value for the rendered element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `float\|int\|string\|null` | X coordinate value (for example, '10', '10.3', '50%', or `null` to unset). |

**Returns**

`static`: New instance with the updated `x` attribute.

### y() <span id="method-y"></span>

```php
public function y(float|int|string|null $value): static
```

Sets the SVG `y` attribute for the element.

Creates a new instance with the specified y-coordinate value for the rendered element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `float\|int\|string\|null` | Y coordinate value (for example, '20', '10.3', '50%', or `null` to unset). |

**Returns**

`static`: New instance with the updated `y` attribute.

### getTag() <span id="method-getTag"></span>

```php
protected function getTag(): BackedEnum
```

Returns the tag enumeration for the `<image>` element.

**Returns**

[`BackedEnum`](https://www.php.net/manual/en/class.backedenum.php): Tag enumeration instance for `<image>`. [`SvgVoid`](/docs/extensions/html-svg/reference/tag/svgvoid/index.md) for valid SVG void-level tags.