createElement is Solar’s vnode factory. You call it inside a component’s render function to describe the UI tree you want Solar to produce in the DOM. Every call returns a plain vnode object — a lightweight description of a DOM node — that Solar’s reconciler uses to efficiently mount and update the real DOM through its diffing algorithm.
Signature
Parameters
An HTML tag name such as
'div', 'button', 'p', 'span', or 'input'. Solar passes this string directly to document.createElement when mounting.HTML attributes and event handlers to apply to the element. Pass
null or {} when you have no props to set.Event handlers use the lowercase on* form — onclick, onchange, oninput, onkeydown — matching standard DOM event handler property names. Solar calls addEventListener under the hood, so you pass a function reference rather than a string.The special key style accepts an object of CSS properties (e.g., { color: 'red', fontSize: '1rem' }), which Solar applies via Object.assign(el.style, ...). The key className sets el.className directly.Any number of child nodes. You can mix plain text strings, numbers, and vnodes returned by other
createElement calls or component calls. Solar flattens one level of nested arrays and filters out null, undefined, and false — so conditional children are safe to include inline.Return value
Examples
Event listeners use
onclick (all lowercase), not onClick. This matches the standard DOM addEventListener event name — Solar calls el.addEventListener('click', handler) after stripping the on prefix. Using camelCase like onClick will set it as an HTML attribute string instead of wiring an event listener.