Standalone F# scripts
Author HTML in F# and use dotnet fve build to render the page, compile its styles and JavaScript, and open it in your browser. No web server is required.
On this page
Prerequisites
Use a .NET 11 SDK and Node.js 20 or newer with npm for CLI builds. FVE installs and caches its pinned Tailwind and esbuild tools automatically; no per-page npm project or manual frontend-tool installation is needed.
SDK 10 and 11 are actively tested for script execution; use SDK 11 for new scripts. SDK selection is separate from Core’s net8.0 compatibility asset. If a parent directory selects an older SDK, select SDK 11 in a script-local global.json before running the script.
Use the Core package
A script can reference the pinned Core package directly and render ordinary typed HTML:
#r "nuget: FSharp.ViewEngine, 2026.8.2"
open System.IO
open FSharp.ViewEngine
open type Html
let document =
html {
_lang "en"
head { title { "A standalone page" } }
body { h1 { "Built with F#" } }
}
File.WriteAllText(Path.Combine(__SOURCE_DIRECTORY__, "page.html"), Render.toHtmlDocString document)dotnet fsi page.fsxInstall editable components into a script
Use a local tool manifest to pin the CLI. Run these commands in a new directory. Script consumers use the same registry, dependency resolution and editable-source protections as project consumers:
dotnet new globaljson --sdk-version 11.0.100 --roll-forward latestFeature
dotnet new tool-manifest
dotnet tool install FSharp.ViewEngine.Cli
dotnet fve init page.fsx
dotnet fve add cardThe CLI creates page.fsx and fve.json, pins the Core reference, and writes one dependency-ordered #load directive in a managed block. Keep that block; it opens the configured component namespace. The namespace defaults to the script filename without its extension (page here), with hyphens and spaces replaced by underscores. Use the optional --namespace MyApp.Components override only when you want a different source namespace. Installation does not compile a DLL or require an .fsproj. A new script also gets an editable input.css and matching CSS/JavaScript references in its HTML shell. Build does not rewrite those authored inputs. Existing content outside the block is preserved. When initializing an existing script, remove its old manual FSharp.ViewEngine #r first so the CLI can own that single pinned reference.
Compose the HTML page
Replace the starter document below the managed block with ordinary HTML and an editable Card component:
open System.IO
open FSharp.ViewEngine
open type Html
let document =
html {
_lang "en"
head {
meta { _charset "utf-8" }
meta { _name "viewport"; _content "width=device-width, initial-scale=1" }
title { "A standalone page" }
link { _rel "stylesheet"; _href "page.css" }
}
body {
_class (ComponentsTheme.className ComponentsTheme.sky + " m-0 bg-[var(--fve-background)] p-6 text-[var(--fve-text)]")
main {
_class "mx-auto max-w-xl"
fveCard {
fveCardHeader {
h1 { _class "m-0 text-2xl font-semibold"; "Built with F#" }
}
p { "This page uses editable component source and opens directly from disk." }
}
}
script { _src "page.js" }
}
}
File.WriteAllText(Path.Combine(__SOURCE_DIRECTORY__, "page.html"), Render.toHtmlDocString document)Build and view
Build renders the script, compiles input.css, and bundles the installed components’ browser modules into matching HTML, CSS and JavaScript files. Use --open to view the finished HTML in your default browser:
dotnet fve build --openInit creates input.css with these source scans. Keep it editable; add @source entries for shared files outside the script directory when needed:
@import "tailwindcss" source(none);
@source "./**/*.fs";
@source "./**/*.fsx";
@source "./Components/Assets/*.js";The command reads the entry script from fve.json; use --config path/to/fve.json when building from another directory. Treat page.html, page.css and page.js as generated outputs. Build uses edited installed components without reinstalling or upgrading them. Keep the generated assets, local images and fonts beside the HTML and use relative paths. Application projects continue to use dotnet build.
Keep source ownership explicit
dotnet fve diff
dotnet fve add card --overwriteUse diff before updating. Reinstalling without overwrite preserves edited component source; changing or removing a managed script block fails before any source writes. Use overwrite only when replacing that managed content is intended. Rendered script values are encoded as normal FVE text; raw remains an explicit trusted-markup escape hatch.