# Velo: About Custom Elements

Source: https://support.wix.com/en/article/velo-about-custom-elements (updated 2024-06-04)
Related: Wix developer documentation, https://dev.wix.com/docs/llms.txt; Help Center index, https://support.wix.com/en/llms.txt

Custom elements let you add custom elements to your site that are not currently available "out of the box" with the Wix Editor. Custom elements are available from the **Embed Code** section of the **Add** menu in the Editor.  
  
 With Velo, you can enhance the behaviors of custom elements even more than what is possible from the Editor. You can also host your custom elements with Wix using Velo.  
  
 First you create and code the element and its behavior in a JavaScript file. Then you implement how your site should handle events on the custom element.

> **Important** Only premium Wix users on sites [with their own domain and Wix ads removed](https://www.wix.com/account/domains?referralAdditionalInfo=account&domainSearch=true&alwaysfs=) can work with custom elements.

## How to Create Custom Elements

Here is an outline of the steps for adding custom elements:  
  
1. Check [prerequisites](https://support.wix.com/en/article/velo-about-custom-elements#prerequisites-1).
2. [Code](https://support.wix.com/en/article/velo-about-custom-elements#code-the-custom-element) the custom element.
3. [Host](https://support.wix.com/en/article/velo-about-custom-elements#host-the-custom-element-with-wix-using-velo) the JavaScript file.
4. [Add a custom element](https://support.wix.com/en/article/velo-about-custom-elements#add-the-custom-element-in-the-wix-editor) to your site.
5. For really cool custom elements, use Velo to code additional behaviors, such as [code event handling and more functionality](https://support.wix.com/en/article/velo-about-custom-elements#code-the-behaviors-with-velo).

## Prerequisites

Before you start, [check prerequisites](https://support.wix.com/en/article/velo-custom-element-faqs#general-requirements-and-guidelines) to make sure you are set up properly to work with custom elements. Some important prerequisites to look at include:

* [Get a domain and remove Wix Ads](https://support.wix.com/en/article/velo-custom-element-faqs#get-a-domain-and-remove-wix-ads-1)
* [Upload images for the custom element in the Wix Editor](https://support.wix.com/en/article/velo-custom-element-faqs#where-do-i-store-images-for-custom-elements-1)

## Code the Custom Element

Code the custom element and its behavior in a static JavaScript file using the Velo IDE or any other IDE.

Each JavaScript file corresponds to one custom element's implementation of its design and behaviors. Custom elements are defined using the standard ECMAScript 2015 class syntax.

> **Note** We assume you know a bit about designing elements with [CSS properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference) in Javascript and working with [web components](https://developer.mozilla.org/en-US/docs/Web/Web%5FComponents).   
> This article provides basic instructions only. For full instructions and examples about using web components, which are the basis of custom elements, see the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/Web%5FComponents).

Some of the behaviors and styles you might consider coding in the custom element include: 

* Variables and styles.
* Functions for animations and other behaviors.
* Events. Creating events is the custom element's way of "communicating" with the Wix site using Velo. Events let Velo know that something has to be handled, and parameters can be sent with the event.

> **Note** Do not use any Velo APIs in your custom element.

Create a class for the custom element and register the custom element.   
  
Here is a sample code snippet:

```javascript
class MyCustomElement extends HTMLElement {
  constructor() {
    super();
    console.log(...);
  }

  connectedCallback() {
    ...
    ...
    ...
  }
}
customElements.define('my-custom-element', MyCustomElement);
```

**Important!**  
 Keep track of the name you used when registering the element with `customElements.define()`. You will need it when defining the tag name while adding the element in the Editor. In our example, the name is `my-custom-element`.

## Host the Custom Element with Wix Using Velo

You can host the custom element's JavaScript file with Wix using Velo (recommended) or [on your own external or local server.](https://support.wix.com/en/article/velo-custom-element-faqs#how-can-i-create-a-server-for-hosting-custom-elements-optional)   
  
 To host with Wix, you must turn on Velo Dev Mode.

When you host with Wix, the default location for your custom element Javascript files will be: `Public/custom-elements/`

You create custom element JavaScript files:

* By creating the file in an IDE and then manually uploading the file to `Public/custom-elements/` in the Site Structure sidebar.
* When [adding the custom element](https://support.wix.com/en/article/wix-editor-adding-a-custom-element-to-your-site#adding-the-custom-element) in the Wix Editor by choosing **New File**.
* By modifying the sample template file [wix-default-custom-element.js](https://support.wix.com/en/article/velo-example-coding-based-on-the-custom-element-template) provided by Velo.

## Add the Custom Element in the Wix Editor

First review the general instructions for [adding a custom element](https://support.wix.com/en/article/wix-editor-adding-a-custom-element-to-your-site#adding-the-custom-element) in the Wix Editor.   
  
 When using Wix to host, or Velo to enhance the custom element, do the following:

## Set the Location of the JavaScript File

In the element's Settings, configure the custom element so it connects to the corresponding JavaScript file.

![](https://d2x3xhvgiqkx42.cloudfront.net/12345678-1234-1234-1234-1234567890ab/76096845-8b12-44f1-91f6-3dc2e838fdd9/2021/01/04/6d339abe-3008-46c1-b26e-61fd1720838d/34b6ab36-bebd-459c-ab76-a77f51a62d92.png)

> **Note** This illustration shows hosting by Wix using a Velo file. You can also host using an external or local server URL.

When you choose **Velo file**, Velo creates the default **Public > custom-elements** folder if it doesn't exist yet.  
  
 When you create a new file, it is by default called **wix-default-custom-element.js**. The file automatically contains a template of a custom element that you can change.

## Configure the Tag as Registered

Enter the tag name. The tag name corresponds to the element name registered using the `define()` function in the custom element code.

## Code the Behaviors with Velo

Custom element behaviors are coded both in the custom elements' Javascript file and also in Velo.   
 You can customize how the custom element behaves for a single page on the site or for all pages on the site.

Make sure to set up event handlers using the `on()` function for the events defined in the custom event's Javascript file.

Create and set attributes on the custom element using `setAttribute()`. This is Velo's way of "communicating" with the custom element. We can pass the custom element attributes and their values so that the custom element's implementation can behave accordingly.

## Examples

Get a hands-on introduction to custom elements with our [Hello Custom Element](https://www.wix.com/velo/example/hello-custom-element) example page.

  
 Check out these articles that demonstrate how to work with custom elements, and get ideas for what you can do: 

* [Basic "Hello World" example](https://support.wix.com/en/article/wix-editor-adding-a-custom-element-to-your-site#custom-element-example)
* [Basic example with images](https://support.wix.com/en/article/velo-example-coding-a-basic-custom-element-with-images)
* [Robust example with Velo](https://support.wix.com/en/article/velo-example-coding-a-more-robust-custom-element)
* [Template example](https://support.wix.com/en/article/velo-example-coding-based-on-the-custom-element-template)

See more examples on the Velo by Wix [Explore Examples](https://www.wix.com/velo/examples) site, such as: 

* [Chart.js custom element example](https://www.wix.com/velo/example/chart.js-custom-element)
* [Dropdown custom element example](https://www.wix.com/velo/example/dropdown-custom-element)
