Skip to Content
Clerk logo

Clerk Docs

Ctrl + K
Go to clerkstage.dev

JavaScript <UserProfile />

This JavaScript reference describes the properties and methods related to Clerk's <UserProfile /> component. If you are looking for the React component, see the <UserProfile /> documentation.

User Profile example

The <UserProfile /> component is used to render a beautiful, full-featured account management UI that allows users to manage their profile and security settings.

The following methods available on an instance of the Clerk class are used to render and control the <UserProfile /> component:

mountUserProfile()

Render the <UserProfile /> component to an HTML <div> element.

function mountUserProfile(node: HTMLDivElement, props?: UserProfileProps): void;

mountUserProfile() params

NameTypeDescription
nodeHTMLDivElement(opens in a new tab)The <div> element used to render in the <UserProfile /> component
props?UserProfilePropsThe properties to pass to the <UserProfile /> component

mountUserProfile() usage

main.js
import Clerk from '@clerk/clerk-js'; // Initialize Clerk with your Clerk publishable key const clerk = new Clerk('{{pub_key}}'); await clerk.load(); document.getElementById("app").innerHTML = ` <div id="user-profile"></div> `; const userProfileDiv = document.getElementById("user-profile"); clerk.mountUserProfile(userProfileDiv);
index.html
<!-- Add a <div id="user-profile"> element to your HTML --> <div id="user-profile"></div> <script> window.addEventListener("load", async function () { await Clerk.load(); const userProfileDiv = document.getElementById('user-profile'); Clerk.mountUserProfile(userProfileDiv); }); </script>

unmountUserProfile()

Unmount and run cleanup on an existing <UserProfile /> component instance.

function unmountUserProfile(node: HTMLDivElement): void;

unmountUserProfile() params

NameTypeDescription
nodeHTMLDivElement(opens in a new tab)The container <div> element with a rendered <UserProfile /> component instance.

unmountUserProfile() usage

main.js
import Clerk from '@clerk/clerk-js'; // Initialize Clerk with your Clerk publishable key const clerk = new Clerk('{{pub_key}}'); await clerk.load(); document.getElementById('app').innerHTML = ` <div id="user-profile"></div> ` const userProfileDiv = document.getElementById('user-profile'); clerk.mountUserProfile(userProfileDiv); // ... clerk.unmountUserProfile(userProfileDiv);
index.html
<!-- Add a <div id="user-profile"> element to your HTML --> <div id="user-profile"></div> <script> window.addEventListener("load", async function () { await Clerk.load(); const userProfileDiv = document.getElementById('user-profile'); Clerk.mountUserProfile(userProfileDiv); // ... Clerk.unmountUserProfile(userProfileDiv); }); </script>

openUserProfile()

Opens the <UserProfile /> component as an overlay at the root of your HTML body element.

function openUserProfile(props?: UserProfileProps): void;

openUserProfile() params

NameTypeDescription
props?UserProfilePropsThe properties to pass to the <UserProfile /> component

openUserProfile() usage

main.js
import Clerk from '@clerk/clerk-js'; // Initialize Clerk with your Clerk publishable key const clerk = new Clerk('{{pub_key}}'); await clerk.load(); document.getElementById('app').innerHTML = ` <div id="user-profile"></div> ` const userProfileDiv = document.getElementById('user-profile'); clerk.openUserProfile(userProfileDiv);
index.html
<!-- Add a <div id="user-profile"> element to your HTML --> <div id="user-profile"></div> <script> window.addEventListener("load", async function () { await Clerk.load(); const userProfileDiv = document.getElementById('user-profile'); Clerk.openUserProfile(userProfileDiv); }); </script>

closeUserProfile()

Closes the user profile overlay.

function closeUserProfile(): void;

closeUserProfile() usage

main.js
import Clerk from '@clerk/clerk-js'; // Initialize Clerk with your Clerk publishable key const clerk = new Clerk('{{pub_key}}'); await clerk.load(); document.getElementById('app').innerHTML = ` <div id="user-profile"></div> ` const userProfileDiv = document.getElementById('user-profile'); clerk.closeUserProfile(userProfileDiv);
index.html
<!-- Add a <div id="user-profile"> element to your HTML --> <div id="user-profile"></div> <script> window.addEventListener("load", async function () { await Clerk.load(); const userProfileDiv = document.getElementById('user-profile'); Clerk.closeUserProfile(userProfileDiv); }); </script>

UserProfileProps

All props below are optional.

NameTypeDescription
appearanceAppearance | undefinedOptional object to style your components. Will only affect Clerk Components and not Account Portal pages.
routing'hash' | 'path' | 'virtual'The routing strategy for your pages.
pathstringThe path where the component is mounted when path-based routing is used.
e.g. /user-profile.
This prop is ignored in hash-based routing.
additionalOAuthScopesobjectSpecify additional scopes per OAuth provider that your users would like to provide if not already approved.
e.g. {google: ['foo', 'bar'], github: ['qux']}
customPagesCustomPageAn array of custom pages to add to the user profile.

How to customize the <UserProfile /> component

To learn about how to customize Clerk components, see the customization documentation.

In addition, you also can add custom pages and links to the navigation sidebar of the <UserProfile /> component. See the example below:

main.js
import Clerk from '@clerk/clerk-js'; const clerk = new Clerk('{{pub_key}}'); await clerk.load(); clerk.openUserProfile({ customPages: [ { url: "custom-page", label: "Custom Page", mountIcon: (el) => { el.innerHTML = "πŸ‘‹"; }, unmountIcon: (el) => { el.innerHTML = ""; }, mount: (el) => { el.innerHTML = ` <h1>Custom Page</h1> <p>This is the content of the custom page.</p> `; }, unmount: (el) => { el.innerHTML = ""; }, }, { url: "/homepage", label: "Homepage", mountIcon: (el) => { el.innerHTML = "🌐"; }, unmountIcon: (el) => { el.innerHTML = ""; }, } ] });
index.html
<script> window.addEventListener('load', async function () { await Clerk.load(); window.Clerk.openUserProfile({ customPages: [ { url: "custom-page", label: "Custom Page", mountIcon: (el) => { el.innerHTML = "πŸ‘‹"; }, unmountIcon: (el) => { el.innerHTML = ""; }, mount: (el) => { el.innerHTML = ` <h1><b>Custom Page</b></h1> <p>This is the content of the custom page.</p> `; }, unmount: (el) => { el.innerHTML = ""; }, }, { url: "/other-page", label: "Other Page", mountIcon: (el) => { el.innerHTML = "🌐"; }, unmountIcon: (el) => { el.innerHTML = ""; }, } ] }); }); document.body.appendChild(script); </script>

What did you think of this content?

Clerk Β© 2024