> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Hello Custom Element

## Article: Hello Custom Element

## Article Link: https://dev.wix.com/docs/coding-examples/getting-started/hello-world/hello-custom-element.md

## Article Content:

# Hello Custom Element

Create an interaction between a Wix site page and a custom element. 

<div style="display: flex; flex-direction: row; align-items: center;"> 
<span style="display: flex; flex-direction: row; align-items: center; margin-right: 20px;"> 
<img src="https://wixmp-833713b177cebf373f611808.wixmp.com/images/08d72650aa29b51886430ccb4db77bd8.png" style="width: 15px; height: 15px;"> 
<span style="margin-left:3px; color:rgb(51 56 83); font-size:1rem">Intermediate</span> 
</span> 
<span style="color:rgb(51 56 83); font-size:1rem">Last updated: 01 Apr 2025</span> 
</div> 
<div style="display: flex; flex-direction: column; padding-top: 20px; padding-bottom: 20px;">
<div style="width: 100%; margin-bottom: 20px;"> 
<img src="https://static.wixstatic.com/media/d2a594_b63226188bdf406db88d57b7c2b47a86~mv2.png" alt="Hello Custom Element" style="width: 100%;"> 
</div> 
<div style="display: flex; flex-direction: row; justify-content: space-between; align-items: center; width: 100%;">
<div style="margin: 0px 20px 20px 0px;">
<a href="fallback::https://manage.wix.com/edit-template/from?originTemplateId=fbed384d-039d-4c1a-b2b5-9ce625123632&templateId=775e9e50-4530-42e1-9eeb-bd954a429c78&autoDevMode=true" target="_blank"> <button style="margin-right: 10px;background-color:#106DFF; color:white; padding:10px 20px; border:none; border-radius:21px; cursor:pointer; margin: 0px 20px 20px 0px;" target="_blank">Open Example</button></a> 
<a href="fallback::https://www.wix.com/velo-examples/hello-ce-s" target="_blank"><button style="background-color:white; color:#106DFF; padding:10px 20px; border:1px solid #106DFF; border-radius:21px; cursor:pointer; width:125px;" target="_blank">Preview</button></a> 
</div> 
</div> 
</div> 
</div>

## About
---

In this code example, we create a custom HTML element that interacts with a site page. When you click the button on the site page, it sends a message to the custom element and updates its displayed text. Similarly, when you click the button on the custom element, it sends a message back to the site page.

## Before you begin
---
Your site must have a Wix premium plan to use this feature.

## APIs 
---
<ul> 
<li><a href="portalId::f356b938-ca2c-46f4-a390-e7ed146e00e0resourceId::4226f67a-73d7-47fd-acd0-e8e474f9f390slug::custom-element/introduction*fallback::https://dev.wix.com/docs/velo/api-reference/$w/custom-element/introduction".md target="_blank">$w.CustomElement API</a></li> 
<li><a href="portalId::f356b938-ca2c-46f4-a390-e7ed146e00e0resourceId::4226f67a-73d7-47fd-acd0-e8e474f9f390slug::button/introduction*fallback::https://dev.wix.com/docs/velo/api-reference/$w/button/introduction".md target="_blank">$w.Button API</a></li> 
<li><a href="portalId::f356b938-ca2c-46f4-a390-e7ed146e00e0resourceId::4226f67a-73d7-47fd-acd0-e8e474f9f390slug::text/introduction*fallback::https://dev.wix.com/docs/velo/api-reference/$w/text/introduction".md target="_blank">$w.Text API</a></li> 
</ul> 

## How we built it 
---
We added the following to our site:

#### Page Elements
* A custom element to interact with the page.
* A button to send a message and update the custom element’s text. 
* A text element to update with the message sent from the custom element. 


#### Frontend Code 

##### Home

The code in this file demonstrates how to interact with the custom element. 
In this file, we:
*   Listen for the custom element’s \`sayHello\` event handler and update the message on the page’s text element. 
*   Listen for the button’s \`onClick()\` event handler and send a message to the custom element by calling \`setAttribute()\` on the custom element.
    

##### Public code
**ce-hello-world.js**
The code in this file defines a custom HTML element that includes methods for creating elements, handling events, and updating content based on user interactions.

In this file, we: 
*   Define methods to create various HTML elements for building the custom element.
*   Define a custom HTML element class called \`HelloWorld\` that extends the built-in HTML Element. 
*   Instantiate the element’s structure and design when it’s added to the site page. 
*   Add an event handler that sends a message to the site page when the button is clicked. 
*   Implement getter and setter methods for a custom attribute called \`“msg”\` that update the displayed content with the message sent from the site page.

## Code Snippets
---
<details open> 
<summary> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 18" width="22" height="22">
    <path d="M16.003 15.18c0 .57-.11 1.01-.31 1.32.2.31.31.75.31 1.32 0 .94.33 1.22.53 1.24.27.02.481.25.471.52-.01.27-.22.48-.49.48-.521 0-1.512-.47-1.512-2.24 0-.51-.1-.74-.16-.81h-.06c-.06 0-.11 0-.16-.01a.505.505 0 0 1-.561-.29.522.522 0 0 1-.04-.21c0-.08 0-.17.04-.25.1-.22.35-.32.58-.27h.2c.06-.06.17-.29.17-.81 0-1.77.992-2.24 1.513-2.24.28 0 .5.22.5.5s-.22.5-.5.5c-.18.02-.511.3-.511 1.24l-.01.01Zm5.967 1.1c-.09-.22-.33-.33-.57-.28h-.211c-.06-.06-.17-.29-.17-.81 0-1.77-.991-2.24-1.512-2.24-.27 0-.48.21-.49.48-.01.27.2.5.47.52.2.02.53.3.53 1.24 0 .57.11 1.01.311 1.32-.2.31-.31.75-.31 1.32 0 .94-.33 1.22-.511 1.24-.28 0-.5.22-.5.5s.22.5.5.5c.52 0 1.512-.47 1.512-2.24 0-.51.1-.74.16-.81h.06c.06 0 .11 0 .15-.01.23.06.47-.05.57-.27.041-.08.041-.17.041-.25 0-.07 0-.14-.04-.21h.01ZM17.014 4H6.001C5.451 4 5 4.45 5 5v14c0 .55.45 1 1.001 1h7.008v-1H6.001V5h11.013v6h1.001V5c0-.55-.45-1-1-1Zm-9.01 7h7.008v-1H8.004v1Zm7.008-4H8.004v1h7.008V7Z"></path>
  </svg> public/custom-element </summary> 

```javascript
const createH3 = () => {
    const h3Element = document.createElement('h3');
    h3Element.textContent = 'This is the custom element';
    h3Element.id = 'hello-h3';
    return h3Element;
};

const createP = () => {
    const pElement = document.createElement('p');
    pElement.textContent = 'A message from the page will appear here';
    pElement.id = 'hello-p';
    return pElement;
};

const createButton = () => {
    const buttonElement = document.createElement('button');
    buttonElement.textContent = 'Send message to custom component';
    buttonElement.id = 'hello-button';
    return buttonElement;
};

const createContainer = () => {
    const container = document.createElement('div');
    container.id = 'hello-container';
    return container;
};

const createStyle = () => {
    const styleElement = document.createElement('style');
    styleElement.innerHTML = `
    @import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;500;700&display=swap');
    * {
        font-family: 'Syne', sans-serif; 
    }
    #hello-h3 {
        display: flex;
        height: 100%;
        height: -moz-available;
        height: -webkit-fill-available;
        width: 100%;
        justify-content: center;
        font-family: 'Syne', sans-serif;
        font-size: 6vw; 
        font-weight: 400;
      }

    #hello-container {
        border: 1px black; 
        background-color: rgb(255,255,255 / 0.05);
        backdrop-filter: blur(9px);   
        padding-top: 50px;
        padding-bottom: 50px;
        display: flex;
        flex-direction: column;
        width: 100%;
        justify-content: center;
        text-align:center;
        box-shadow: 4.49px 4.494px 37.98px 0px rgba(0, 0, 0, 0.50);

    }

    #hello-h3 {
        // font-size: 64px;
        color: white;
    }

    #hello-p {
        font-size: 2.75vw;
        color: white;
        margin-bottom: 29px;
    }

    #hello-button {
        border: none;
        border-radius: 9px;
        color: black;
        padding: 15px 40px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 2.75vw;
        align-self: center;
        cursor: pointer;
        background: linear-gradient(90deg, #BFEF02 0%, #DFFF5F 100%);
        min-height: 68px; 
        height: auto;
        width: 66%;
    }
    `;
    return styleElement;
};

class HelloWorld extends HTMLElement {
    constructor() {
        super();
    }

    connectedCallback() {
        this.appendChild(createStyle());
        let container = createContainer();
        let button = createButton(); 
        button.addEventListener('click', () => {
            this.dispatchEvent(new CustomEvent('sayHello', { detail: { data: 'Hello from the custom element' } }));
        });
        container.appendChild(createH3());
        container.appendChild(document.createElement('br'));
        container.appendChild(createP());
        container.appendChild(document.createElement('br'));
        container.appendChild(button);
        this.appendChild(container);
    }

    get msg() {
        return this.getAttribute('msg');
    }

    set msg(value) {
        this.setAttribute('msg', value);
    }

    static get observedAttributes() {
        return ['msg'];
    }

    attributeChangedCallback(name, oldVal, newVal) {
        this.render();
    }

    render() {
        document.getElementById('hello-p').textContent = this.msg;
    }          
}
customElements.define('hello-world', HelloWorld);
```
</details>

<details open> 
<summary> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 18" width="22" height="22">
    <path d="M16.003 15.18c0 .57-.11 1.01-.31 1.32.2.31.31.75.31 1.32 0 .94.33 1.22.53 1.24.27.02.481.25.471.52-.01.27-.22.48-.49.48-.521 0-1.512-.47-1.512-2.24 0-.51-.1-.74-.16-.81h-.06c-.06 0-.11 0-.16-.01a.505.505 0 0 1-.561-.29.522.522 0 0 1-.04-.21c0-.08 0-.17.04-.25.1-.22.35-.32.58-.27h.2c.06-.06.17-.29.17-.81 0-1.77.992-2.24 1.513-2.24.28 0 .5.22.5.5s-.22.5-.5.5c-.18.02-.511.3-.511 1.24l-.01.01Zm5.967 1.1c-.09-.22-.33-.33-.57-.28h-.211c-.06-.06-.17-.29-.17-.81 0-1.77-.991-2.24-1.512-2.24-.27 0-.48.21-.49.48-.01.27.2.5.47.52.2.02.53.3.53 1.24 0 .57.11 1.01.311 1.32-.2.31-.31.75-.31 1.32 0 .94-.33 1.22-.511 1.24-.28 0-.5.22-.5.5s.22.5.5.5c.52 0 1.512-.47 1.512-2.24 0-.51.1-.74.16-.81h.06c.06 0 .11 0 .15-.01.23.06.47-.05.57-.27.041-.08.041-.17.041-.25 0-.07 0-.14-.04-.21h.01ZM17.014 4H6.001C5.451 4 5 4.45 5 5v14c0 .55.45 1 1.001 1h7.008v-1H6.001V5h11.013v6h1.001V5c0-.55-.45-1-1-1Zm-9.01 7h7.008v-1H8.004v1Zm7.008-4H8.004v1h7.008V7Z"></path>
  </svg> Home </summary> 

```javascript
// Velo API Reference: https://www.wix.com/velo/reference/api-overview/introduction
$w.onReady(function () {
    $w('#customElement').on('sayHello', ({ detail: { data } }) => {
        $w('#message').text = data;
    })

    $w('#sendButton').onClick(() => {
        $w('#customElement').setAttribute('msg', "HELLO FROM THE PAGE");
    });
});
```
</details>

<!-- Static content -->
## Get Help
--- 
### Join the community 

Join the [Wix for Devs][discord-community] community on Discord, where experienced developers and fellow creators come together to share tips, troubleshoot issues, and collaborate.

### Hire a developer 

Building a coded solution on your own can be challenging. Let an experienced Wix developer build it for you, so you can keep working on your site or business.
Visit the [Wix Marketplace][wix-marketplace] to find a trusted developer. 

<!-- Predefined links -->
[discord-community]: https://discord.com/invite/GhdmDN926z 
[wix-marketplace]: https://www.wix.com/marketplace/brief-auto-match/web-developer?entry=velo&origin=examples-page "Wix Marketplace"