ID

Add an ID property to your component so designers can set unique identifiers on HTML elements.

The ID prop creates a text input for element IDs, making it easy to target elements with CSS or JavaScript.

Syntax

1// Prop definition
2props.Id({
3 name: string,
4 group?: string,
5 tooltip?: string,
6})
7
8// Prop value
9string

Prop definition

Define the ID prop in your Webflow code component with a name. Optionally, you can add a group and tooltip text.

1props.Id({
2 name: string,
3 group?: string,
4 tooltip?: string,
5})

Properties

  • name: The name for the property.
  • group: The group for this property (optional).
  • tooltip: The tooltip for this property (optional).

Example

MyComponent.webflow.tsx
1import { declareComponent } from '@webflow/react';
2import { props } from '@webflow/data-types';
3import { MyComponent } from "./MyComponent";
4import "../styles/globals.css";
5
6export default declareComponent(MyComponent, {
7 name: "MyComponent",
8 description: "A component with an ID property",
9 props: {
10 id: props.Id({
11 name: "Element ID",
12 group: "Info"
13 })
14 }
15});

Prop value

The ID prop provides a string to your React component:

PropType.Id
1string

Properties

  • n/a

Webflow properties panel

ID property in the Webflow panel

Example

MyComponent.tsx
1import React from "react";
2import "../styles/globals.css";
3
4interface MyComponentProps {
5id?: string;
6}
7
8export const MyComponent = ({ id }: MyComponentProps) => {
9return (
10 <div id={id}>
11 {/* Component content */}
12 </div>
13);
14}

When to use

Use an ID prop when you want designers to:

  • Set unique identifiers for CSS targeting
  • Connect form labels to inputs
  • Enable JavaScript interactions