Skip to content
TrademarkTrademark
Docs
Components

ElementType

Updated: June 30, 2026
View on GitHub

The ElementType component is a utility component that dynamically renders as different HTML elements based on the props provided. It can render as a link (<a> or Next.js <Link>), a button, or a div, making it useful for creating interactive elements with consistent styling but different underlying behaviors.

ElementType automatically handles both internal and external links.

Button behavior

ElementType renders as a button when provided with an onClick handler or type prop.

Fallback

When no interactive props are provided, ElementType renders as a Flex component.

Behavior

The ElementType component follows these rules to determine which element to render:

  1. If href is provided and the URL is external (starts with http:// or https://), renders as an <a> tag with target="_blank" and rel="noreferrer". If the URL is internal, renders as a Next.js <Link> component

  2. If onClick is provided or type is "submit" or "button", renders as a <button> element

  3. Otherwise, renders as a <Flex> component (which is a div with additional styling)

Usage

The ElementType component is designed to be used internally by other Once UI components to provide consistent behavior while allowing flexibility in the rendered HTML element. For example, it's used by the Button component to enable both link and button behaviors.

API reference

Type
Default
href
string—
onClick
() => void—
onLinkClick
() => void—
type
buttonsubmitreset
—
children
React.ReactNode—
className
string—
style
React.CSSProperties—
…and every FlexProps propinherited—
Edit this page on GitHub