Basics
This page goes through the fundamental basics of what a page is, and how they work in Elegance.
What is a page?
A page is any file named page.ts(x) within the pages directory.
They contain a default export function that returns some elements, which in turn get displayed on a page.
That might look something like this:
export default function Page() {
return <h1>Hello, World!</h1>
}Elegance imports your page, and turns these elements into HTML, and JS.
Our example will turn into this:
<h1>Hello, World!</h1>If you're curious about how this process, works, read this
The folder the page is in determines where it is displayed. A page at: pages/blog/page.ts will show at: https://localhost:3000/blog/. This concept is commonly referred to as "fs-routing"
TSX/TS
You can write your pages both in TSX-style and TS style, but you cannot write them in JS/JSX. This is 2026, we use TypeScript.
If you prefer our way of writing elements (refered to as function-call style element calls), you can write pages like this:
export default function Page() {
return h1("Hello, World!");
}All html, mathMl, and svg elements are available (with some caveats like <var> being varEl to avoid keyword collisions)
If you'd like to pass options, to an element, like a className, you do it in the options object, which you must pass as the first parameter to an element call, like this:
export default function Page() {
return h1({
className: "title-main",
}, "Hello, World!");
}You can pass any number of children to any element (void elements nonwidthstanding), and it behaves as expected. Nested calls are of course supported:
export default function Page() {
return div({
class: "home-page",
},
h1({
className: "title-main",
}, "Hello, World!"),
);
}If you're curious about how TSX works in Elegance, you can read more here