{ "id": "fe5dfbdda773b21593962fff", "source": "solid:signals", "type": "github-document", "title": "create-unique-id", "content": "---\ntitle: createUniqueId\nuse_cases: \u003e-\n form elements, accessibility, aria labels, ssr compatibility, html id\n generation, unique identifiers\ntags:\n - ids\n - accessibility\n - ssr\n - forms\n - utilities\nversion: \"1.0\"\ndescription: \u003e-\n Generate unique IDs that are stable across server and client with\n createUniqueId. Essential for accessible forms and SSR-compatible components.\n---\n\nThe `createUniqueId` function generates a unique ID that remains consistent across both server and client renders.\nIt is commonly used with HTML `id` and `for` attributes to ensure stable hydration.\n\n`createUniqueId` does *not* generate a cryptographically secure ID and is not suitable for security-sensitive data.\nAdditionally, it should not be used in scenarios that require uniqueness across a distributed system.\n\n:::note\n`createUniqueId` relies on a counter-based mechanism to generate IDs.\nIt must be called the same number of times on both the server and client.\n\nCalling `createUniqueId` only on the server or only on the client, such as when using [`isServer`](/reference/rendering/is-server) or [`\u003cNoHydration\u003e`](/reference/components/no-hydration), may lead to hydration errors.\n:::\n\n## Import\n\n```ts\nimport { createUniqueId } from \"solid-js\";\n```\n\n## Type\n\n```ts\nfunction createUniqueId(): string;\n```\n\n## Parameters\n\nThis function does not take any parameters.\n\n## Returns\n\n`createUniqueId` returns a unique `string` that is stable across server and client renders.\n\n## Examples\n\n### Basic Usage\n\n```tsx\nimport { createUniqueId } from \"solid-js\";\n\ntype InputProps = {\n\tid?: string;\n};\n\nfunction Input(props: InputProps) {\n\treturn \u003cinput id={props.id ?? createUniqueId()} /\u003e;\n}\n```", "url": "https://github.com/solidjs/solid-docs/blob/HEAD/src/routes/reference/component-apis/create-unique-id.mdx", "metadata": { "path": "src/routes/reference/component-apis/create-unique-id.mdx", "repo": "solidjs/solid-docs", "repo_url": "https://github.com/solidjs/solid-docs.git", "size": 1688, "source_type": "github" }, "hash": "8e506e58c8fb3692c8e326747f80c35974ed106c9a6306a6926387b728a63a86", "timestamp": "2026-02-23T11:43:00.188682798+01:00" }