Why WebSharper

One language across the whole stack

Write your reactive UI, your server endpoints and the types they share in a single F# codebase. WebSharper compiles it to a native .NET server and a JavaScript client that stay in sync — with typed calls instead of hand-written fetch and JSON glue.

Browser client reactive UI · DOM typed remoting Shared F# types routing · data used on both sides .NET server sitelets · async JSON · webhooks Typed calls and shared types across the boundary — no hand-written fetch or serialization.

Reactive values

A single Var is the source of truth, bound two-way to the DOM. Derived views recompute on their own when it changes, and the page updates in place — no virtual DOM and no DOM diffing needed.

Learn more
namespace reactive

open WebSharper
open WebSharper.JavaScript
open WebSharper.UI
open WebSharper.UI.Client
open WebSharper.UI.Templating
open WebSharper.UI.Html

[<JavaScript>]
module Client =
    // The whole UI lives in index.html; the client only fills its holes.
    type IndexTemplate = Template<"wwwroot/index.html", ClientLoad.FromDocument>

    [<SPAEntryPoint>]
    let Main () =
        // One reactive value drives everything: the derived views below
        // recompute on their own whenever `count` changes.
        let count = Var.Create 0
        let square = count.View |> View.Map (fun n -> n * n)
        let parity = count.View |> View.Map (fun n -> if n % 2 = 0 then "even" else "odd")

        IndexTemplate()
            .Count(count)
            .Squared(square |> View.Map string)
            .Parity(parity)
            .Decrement(fun _ -> count.Value <- count.Value - 1)
            .Increment(fun _ -> count.Value <- count.Value + 1)
            .Reset(fun _ -> count.Value <- 0)
            .Bind()

Type-safe JS bindings

Describe a JavaScript library once, then use it from F# with full type checking — no hand-written interop, no any. Here the Leaflet map library is bound and the client fills the index.html template's holes.

Learn more
// WebSharper.Leaflet — a small excerpt from the binding definition (WIG).
// Every `Class "L.X"` maps to a JavaScript constructor; members map to methods
// and properties, and their types are checked at compile time.
namespace WebSharper.Leaflet

module Definition =
    open WebSharper
    open WebSharper.InterfaceGenerator

    let TileLayerT = Class "L.TileLayer"
    let MapT = Class "L.Map"
    let MarkerT = Class "L.Marker"
    let LatLngT = Class "L.LatLng"
    let LatLngOrCoords = LatLngT + T<float * float>

    let LatLng =
        LatLngT
        |+> Instance [
            "lat" =? T<float>
            "lng" =? T<float>
        ]

    let TileLayer =
        TileLayerT
        |+> Static [
            Constructor (T<string>?urlTemplate * !?TileLayerOptions)
        ]

    let Marker =
        MarkerT
        |+> Static [
            Constructor (LatLngOrCoords * !?MarkerOptions)
        ]
        |+> Instance [
            "bindPopup" => T<string> ^-> T<unit>
        ]

    let Map =
        MapT
        |+> Static [
            Constructor ((T<Element> + T<string>)?id * !?MapOptions)
        ]
        |+> Instance [
            "setView" => LatLngOrCoords?center * !?T<int>?zoom ^-> T<unit>
            "addLayer" => ILayer ^-> T<unit>
        ]
        |> WithEvents [
            "mousemove", MouseEvent, "Fired while the mouse moves over the map."
        ]

Type-safe HTML templating

Use HTML templates to keep your logic and UI clearly separate and facilitate the collaboration between programmers and designers.

Learn more
IndexTemplate.Main()
    .Name(newName)
    .Add(fun _ ->
        People.Add(newName.Value)
        newName.Value <- ""
    )
    .Remove(fun _ -> 
        People.Remove newName.Value                                                            
    ) 
    .Doc()

Type-safe remoting

Seamlessly call server-side asynchronous functions from the client side.

AJAX call, JSON serialization... Everything is handled automatically.

Learn more
// Server-side, remote-callable function
[<Remote>]
let ServerFn () : Async<string> =
    async { return "Hello, world!" }

// Client-side function
[<JavaScript>]
let CallServer () : unit =
    async {
        let! result = ServerFn()
        Console.Log(result)
    }
    |> Async.Start

Web APIs and server-side JSON and HTML

Declare your URLs as a C# or F# endpoint type, and WebSharper handles the dispatch. Create safe internal links from endpoint values.

You can share the same rendering code and templates between the server and the client.

Automatically parse JSON requests and generate JSON responses based on your types.

Learn more
// Define the application's endpoints
type EndPoint =
    | [<EndPoint "GET /articles">]
        ArticleList
    | [<EndPoint "GET /article">]
        Article of id: int

// Define the content served by these endpoints
let Website =
    Application.MultiPage (fun (ctx: Context<_>) endpoint ->
        match endpoint with
        | ArticleList ->
            Content.Page(
                div [] [
                    h1 [] [text "Welcome!"]
                    a [attr.href (ctx.Link (Article 42))] [
                        text "Go to article 42"
                    ]
                ]
            )
        | Article id ->
            Content.Json { id = id
                            title = "Hello!"
                            date = System.DateTime.Now }
    )

Client-side routing

Write SPAs with the same routing API on the client side as you would use on the server side.

Learn more
let router = Router.Infer<EndPoint>()
let route = router.Install(Article 1)

let view =
    route.View.Map (function
        | Article id ->
            div [] [
                h1 [] [text $"This is article {id}"]
                a [attr.href (router.Link Articles)] [text "Go back to the list of articles"]
            ]
        | Articles ->
            h1 [] [text "List of articles"]
    )

let doc = Doc.BindView id view
Doc.RunById "main" doc

Model-View-Update architecture with WebSharper.Mvu

Structure client-side applications with clear separation of concerns between logic and display. Based on WebSharper.UI, Mvu brings Elm-like architecture to WebSharper.

Learn more
type Model = { name: string }
let InitModel = { name = "" }

type Message =
    | SetName of string

let Update message model =
    match message with
    | SetName n -> { model with name = n }

let View dispatch (view: View<Model>) =
    div [] [
        input [
            attr.value view.V.name
            on.change (fun el _ ->
                dispatch (SetName el?value))
        ] []
    ]

let Main = App.CreateSimple InitModel Update View |> App.Run

Use powerful language constructs on the client side

F#: Query expressions, async workflows, sequence expressions...

C#: LINQ queries, asynchronous Tasks, generators...

Learn more
type Article = { id: int; title: string; date: DateTime }

let start = DateTime(2025, 9, 1)

let articles : Article list = [
    { id = 1; title = "Welcome to WebSharper"; date = DateTime(2025, 9, 20) }
    { id = 2; title = "Async workflows 101"; date = DateTime(2025, 8, 15) }
    { id = 3; title = "Query expressions on client"; date = DateTime(2025, 9, 28) }
    { id = 4; title = "Remoting tips"; date = DateTime(2025, 7, 5)  }
]
// Query expressions (LINQ for F#)
let recentIds =
    query {
        for article in articles do
        where (article.date > start)
        sortByDescending article.date
        select article.id
    }
// Async workflows (run non-blocking work on the client)
let loadAndShow =
    async {
        do! Async.Sleep 10
        Console.Log(sprintf "Recent IDs: %A" (recentIds |> Seq.toList))
    }    

Async.Start loadAndShow

// Sequence expressions (lazy generators)
let squares =
    seq {
        for i in 1 .. 5 do
            yield i * i
    }   
    
Console.Log(String.concat ", " (squares |> Seq.map string))

Build React components

You can also use widespread libraries such as React to build applications. The syntax is as convenient as JSX, with the added benefit of strong typing.

Learn more
type Person = { name: string; age: int }

type ShowPerson(props) =
    inherit React.Component<Person, unit>(props)

    override this.Render() =
        ul [attr.className "person"] [
            li [] [text ("Name: " + this.Props.name)]
            li [] [text ("Age: " + string this.Props.age)]
        ]

Metaprogramming

Source Code Generators

Write high-level specifications in F# (Warp) and let WebSharper generate the optimized boilerplate for you.

MyApp.warp
template Main "index.html"

endpoint Home "/" return Main
MyApp.warp_EndPoint.fs
namespace MyApplication

open WebSharper.Sitelets

type EndPoint =
    | [<EndPoint "/">] Home
MyApp.warp_UI.fs
namespace MyApplication

open WebSharper.UI.Templating

[<JavaScript>]
module UI =
    type MyTemplate = Template<"index.html">
    let Main = MyTemplate().Doc()

Interactive Explorer

MyApp.warp
template Main "index.html"

endpoint Home "/" return Main
namespace MyApplication

open WebSharper.Sitelets

type EndPoint =
    | [<EndPoint "/">] Home