---
title: Examples
slug: wip/examples
createdAt: 2023-07-20T14:45:03.180Z
---

# Examples

## Basic Usage

The Image preloads and displays an image asset and provides the same basic functionality as the native HTML `img` .

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/yLvpzoL/0d36d3eea1762127affcd4020ba9cbed?default-tab=html%2Cresult&#x26;amp;editable=true&#x26;amp;theme-id=39967&#x22; height=&#x22;559px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Preview Image

To improve the user experience, an Image can display a preview while waiting for the high-resolution image to be loaded.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/xxYpXYd/3449e6dbf8f839ac9a512c6c4d70da92?default-tab=html%2Cresult&#x26;amp;editable=true&#x26;amp;theme-id=39967&#x22; height=&#x22;632px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

**Best Practices:**

- Image previews should be a down-scaled version of the actual high-res image. It's common to provide an image that is 10% of its original size.
- To ensure meaningful content is shown as fast as possible without any additional network requests, preview images should be provided as base64 encoded data URIs.

## Responsiveness and Performance

A great way to balance client-side performance and responsive images is by using `srcset` in conjunction with `sizes` and `loading` attributes. Read more about responsive image best practices here: [Image](https://cosmos.redbull.design/wip/image)

**Note:** The `srcset` attribute depends on the `image` attribute being set.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/ZEmoVQN/8324af6d69170692c2818de8cb5f6910?default-tab=html%2Cresult&#x26;amp;editable=true&#x26;amp;theme-id=39623&#x22; height=&#x22;295px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Adaptive Sizing

By default, the Image always takes the available width and calculates its height based on the image that is displayed.

But it can adapt to any size when a different dimension is specified while ensuring that the image asset displayed covers the available space.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/ZErvaGe/65ecf6b32124240a7affee6ea28f76fa?default-tab=html%2Cresult&#x26;amp;editable=true&#x26;amp;theme-id=39967&#x22; height=&#x22;678px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

**Best Practices:**

- Specify a specific size for the Image directly or make it adapt to a container's dimension by setting its height to 100%

## Listen to Resize Events

When initially mounting to the DOM and whenever the Image changes its dimensions, it emits a `resize` event including the current width and height.

A common use case is to update the image asset to make it perfectly fit the available space.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/ExQoomz/b9f2adb80aed90642976a8cc987dd973?default-tab=html%2Cresult&#x26;amp;editable=true&#x26;amp;theme-id=39967&#x22; height=&#x22;760px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Radius

The `radius` property controls the border-radius of the featured image, preview image, and fallback image. It accepts preset values like 'none,' 'small,' 'medium,' 'large,' or 'full.'

**Note:** The CSS custom property `--cosmos-image-border-radius` will override the `radius` property when set.

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/GRPrjjK/56ed9e1076a960584cde51f6858d597c?default-tab=html%2Cresult&#x26;amp;editable=true&#x26;amp;theme-id=39623&#x22; height=&#x22;350px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::

## Fit

The `fit` property defines how the image should be resized to fit its container. It either scales and crops the image to fill the container ('cover') or scales it to fit within the container while preserving its aspect ratio ('contain').

:::Iframe{iframeHeight="0" code="<iframe title=&#x22;Embeded content from codepen.io&#x22; class=&#x22;no-border max-full-width full-height flex-grow&#x22; src=&#x22;https://codepen.io/redbulldesign/embed/NWedRgb/24047db04053d359feec0b996d73efc0?default-tab=html%2Cresult&#x26;amp;editable=true&#x26;amp;theme-id=39967&#x22; height=&#x22;780px&#x22; loading=&#x22;lazy&#x22;></iframe>"}

:::


