> ## Documentation Index
> Fetch the complete documentation index at: https://cloudinary.com/documentation/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure Svelte Cloudinary (video tutorial)

[githublink]: https://github.com/cloudinary-community/cloudinary-examples/tree/main/examples/sveltekit-cldimage

## Overview

Learn how to install and configure the [Svelte Cloudinary](https://svelte.cloudinary.dev/) community-developed library in your environment. This will enable you to utilize Cloudinary for uploading, managing, and displaying assets in your applications.

## Video tutorial

  This video is brought to you by Cloudinary's video player - embed your own!Use the controls to set the playback speed, navigate to chapters of interest and select subtitles in your preferred language.

> **TIP**: :title=View the code

You can find the code from this tutorial in [GitHub][githublink].
## Tutorial contents
This tutorial presents the following topics. Click a timestamp to jump to that part of the video.
### Introduction
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=0 :sec=00 :player=cld} | Svelte is a modern JavaScript framework designed for building web applications, with SvelteKit providing a convenient option for constructing full-stack applications. [Svelte Cloudinary](https://svelte.cloudinary.dev/) enables developers to manage and optimize the media files in their applications.
|

### More about Svelte Cloudinary
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=0 :sec=23 :player=cld} | Svelte Cloudinary provides access to components for optimizing and modifying media files, and enabling client-side media uploads. Additionally, Cloudinary provides a Node.js SDK for server-side integration with Svelte applications, particularly useful for managing image uploads in scenarios like user forms. This video tutorial focuses on setting up and utilizing the Svelte SDK within an existing Svelte application.
|

### Install and configure Svelte Cloudinary
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=1 :sec=04 :player=cld} | The first step is to install Svelte Cloudinary using `npm install svelte-cloudinary`. Once installed, set your environment variable for Cloudinary in your `.env.local` or `.env` file using the format: `VITE_PUBLIC_CLOUDINARY_CLOUD_NAME="[Your Cloud Name]"`. Find your **Cloud name** on your [Cloudinary Dashboard](https://console.cloudinary.com/app/home/dashboard). 
|

### The CldImage component
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=1 :sec=23 :player=cld} | Now, you can start using Cloudinary. Let's focus on the `CldImage` component. Import it using `import { CldImage } from "svelte-cloudinary"`, and in your app, instead of using the standard image tag, use `CldImage`. For the source, pass a public ID of the image. In this example, the public ID for a Cloudinary image is "demo/red-sneaker". 
|

```svelte
<CldImage src="demo/red-sneaker" alt="Color pair of sneakers"/>
```

### Setting width and height properties
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=1 :sec=46 :player=cld} | You also need to define the width and height properties to avoid layout shift. This setup ensures optimized images, with the image format tailored to the device, reducing file size significantly.
|

```svelte
<CldImage 
  width={960}
  height={600}
  src="demo/red-sneaker" 
  alt="Color pair of sneakers">
/>
```

### Image optimization
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=1 :sec=50 :player=cld} | Open the Network tab and refresh your page to check the format and size of your image, with and without the `CldImage` component. You'll notice that when you use `CldImage`, your images are smaller and use the format that's optimal for the requesting browser.
|

### Use CldImage to display multiple images
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=2 :sec=23 :player=cld} | Use the following sample code to render multiple images with Svelte Cloudinary's `CldImage` component.
|

```svelte
<div class="images_list">
  {#each products as product (product["public-id"])}
    <div class="images__item">
      <CldImage 
        width={960}
        height={600}
        src={product["public-id"]}
        alt={product.alt}
      />
      <span class="images__item__unsplash">
        {product.unsplash}
      </span>
    </div
  {/each}
</div>  
```

### Remove background
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=2 :sec=30 :player=cld} | You can leverage different Cloudinary features with the `CldImage` component. For instance, using the remove background feature. 
|

```svelte
<div class="images_list">
  {#each products as product (product["public-id"])}
    <div class="images__item">
      <CldImage 
        width={960}
        height={600}
        src={product["public-id"]}
        alt={product.alt}
        removeBackground
      />
      <span class="images__item__unsplash">
        {product.unsplash}
      </span>
    </div
  {/each}
</div>  
```

### Overlays
{table:class=tutorial-bullets}|  | 
| --- | --- |
|{videotime:id=media :min=2 :sec=45 :player=cld} | Other features include [overlays](layers), such as adding text watermarks to images. Check the [CldImage Configuration](https://svelte.cloudinary.dev/cldimage/configuration/) page for acceptable properties and values.
|

```svelte
<div class="images_list">
  {#each products as product (product["public-id"])}
    <div class="images__item">
      <CldImage 
        width={960}
        height={600}
        src={product["public-id"]}
        alt={product.alt}
        overlays={[
          {
            text: {
              text: "Brand",
              color: "white",
              fontFamily: "Poppins",
              fontSize: 100,
              fontWeight: "black",
            },
            effects: [{
              opacity:50
            }]
          }
        ]}
      />
      <span class="images__item__unsplash">
        {product.unsplash}
      </span>
    </div
  {/each}
</div>  
```

## Keep learning

> **READING**:
>
> * Learn more about the [Svelte Cloudinary](community_sdks#svelte_components) community-developed library.

> * Watch more [Dev Hints videos](https://www.youtube.com/playlist?list=PL8dVGjLA2oMpaTbvoKCaRNBMQzBUIv7N8) on the [Cloudinary YouTube channel](https://www.youtube.com/cloudinary).

#### If you like this, you might also like...

  
  
  
    Transform and Optimize Images in Svelte
    Transform and optimize images delivered in a Svelte app 
  

  
  
  
    Upload Assets in SvelteKit
    Upload assets using the Upload widget in a SvelteKit app 
  

  
  
  
    Configure the JavaScript SDK in Svelte 
    Install and configure the Cloudinary JavaScript SDK using Svelte 
  

&nbsp;

&nbsp;Check out the Cloudinary Academy for free self-paced Cloudinary courses on a variety of developer or DAM topics, or register for formal instructor-led courses, either virtual or on-site.
&nbsp;
