of a brief sequence of centered article/tutorial posts going from zero to WebAssembly-based internet apps, working solely inside the online browser and permitting you to study all these matters as you go: GitHub, its Codespaces, WebAssembly (or “WASM”), C code, on-line Visible Studio Code, port forwarding, HTML, and JavaScript. I hope you’ll have as a lot enjoyable as I had whereas getting ready this, and that you’ll study lots and get your curiosity sparked up!
Some say the extra you study, the extra you are feeling you already know nothing and there’s extra to study. That was precisely my feeling right here, a sense that’s really good.
Let’s go!
As a long-time sturdy advocate for client-side internet apps, I’ve at all times thought it was bizarre that I knew principally nothing about WebAssembly. However that began altering just lately when I discovered motivation whereas attempting to construct my new web platform for in-browser analysis of molecular structures and simulations (preprint of its first version here, if you wish to know extra about it). Turns on the market are extremely environment friendly libraries and scientific functions written in languages like C that I discovered helpful for my platform, corresponding to Gemmi and FreeSASA. For each, somebody had already went via the work of making WASM ports that I might use instantly.
However might I do this myself? I imply, might I seize say a chunk of C code and compile it in a manner that will run within the browser? The reply was YES! And furthermore, devoted to my internet advocacy, I might do all of it strictly inside the browser, as I show here for FreeSASA.
Subsequent in my studying course of, I ran a self-tutorial ranging from even earlier than the C code. I deliver it right here with full explanations on methods to go from zero to WASM-ready information, all inside your browser, totally free, with out having to obtain or set up completely any software program, and with nothing greater than a free GitHub account.
What WebAssembly is, and why it issues —in a nutshell
For years, the online browser was principally a presentation layer: nice for interfaces and light-weight interactivity, however not for severe computation. Heavy workloads usually required native functions, Python environments, or distant servers. WebAssembly (WASM) is altering that. It permits compiled languages corresponding to C, C++, and Rust to run straight contained in the browser at near-native velocity, turning the browser into an actual computational platform quite than only a show floor.
In observe, WebAssembly lets builders compile current high-performance code right into a compact binary format that browsers can execute effectively. As an alternative of rewriting performance-critical logic in JavaScript, builders can reuse a long time of optimized programs code whereas nonetheless distributing functions as easy webpages. The result’s software program that’s sooner, extra transportable, and dramatically simpler to share: customers can open a hyperlink and run advanced functions domestically with out installations, dependency conflicts, or platform-specific setup.
This shift issues far past efficiency alone. WebAssembly bridges the hole between the accessibility of the online and the ability of native software program, enabling responsive browser-based instruments for simulations, knowledge evaluation, media processing, scientific computing, and interactive visualization. JavaScript continues to deal with the interface and person interplay, whereas WASM acts because the compute engine behind the scenes. This separation is reshaping what fashionable internet functions can do-and even in the event you could not discover, it’s commonplace in fashionable internet improvement.
Cross-compiling to WASM
In observe, having WebAssembly round means we will:
- compile native code into a transportable binary format,
- load it straight right into a webpage,
- and execute it at near-native velocity proper contained in the browser
For knowledge scientists and scientific builders, this opens a captivating chance: Scientific software program can now run straight contained in the browser with out requiring customers to put in something. No environments to put in and cargo every time, no libraries to handle, no dependency conflicts, no OS limitations.
Only a webpage, making your instruments obtainable simply an URL away!
A hands-on, detailed tutorial that you would be able to run in your browser
On this tutorial, we are going to create the smallest attainable WebAssembly utility, which is able to print “Hiya WASM!” on the net web page and can be primarily based on C code:
#embrace
int major() {
printf("Hiya WASM!n");
return 0;
}
We’ll compile this piece of C code into WebAssembly, generate the browser runtime information, and execute it straight contained in the browser
Most significantly: every little thing will occur on-line, even the writing of C code itself. As soon as we begin by logging into GitHub, we gained’t depart the browser till it’s all working!
We’ll use GitHub Codespaces for browser-based improvement,
Emscripten (proper inside GitHub Codespaces) to compile C into WebAssembly, and a easy Python HTTP server (began from inside GitHub Codespaces too) to run the generated internet app.
By the best way: What’s GitHub Codespaces? It’s an on the spot, cloud-based improvement atmosphere that makes use of a container to give you frequent languages, instruments, and utilities for improvement. GitHub Codespaces can be configurable, permitting you to create a personalized improvement atmosphere on your challenge.
Setting our minds with a workflow
Conceptually, our workflow seems like this:
C code --> Emscripten compiler--> WebAssembly module --> Browser execution
And we are going to subsequent see all steps as if we have been following a guide from the “For dummies” assortment.
Step 1 — Create a GitHub Repository
(By the best way, what’s GitHub? GitHub is a web-based platform, form of social media for coding, that serves as a cloud-hosted, collaborative dwelling for software program initiatives. It was born from Git, a software program for model controling, to permit builders to retailer, observe modifications, and work collectively on code in actual time.)
First, log into GitHub and create a brand new repository. For instance, in my free account it seems like this as of Could 2026 (see crimson arrow on the highest left):
(All photographs by the creator)
Then we give it a reputation and click on “Create repository” with all different fields unchanged from the default:

At this stage, the created repository could initially seem empty. To initialize it, we have now to create a file which may very well be merely a README file:

Then the following display appeared like this after I stuffed within the minimal issues I wanted:

You then set off dedication of modifications with the “Commit modifications…” button on the highest proper, after which lastly click on “Commit modifications” within the field that seems.
Step 2 — Launch GitHub Codespaces
We are actually able to go to Codespaces, the place we are going to begin writing the code!
(By the best way, GitHub Codespaces is an “on the spot” web-based improvement atmosphere that permits you to write, run, and debug code solely in your browser via a web based model of Visible Studio Code.)
You’ll find the button to launch Codespaces by clicking the <> Code button within the web page the place you bought after having commited the modifications above:

If you click on “Create codepsace on major”, in a couple of seconds you get the net Visible Studio Code app, that may appear to be this:

You will notice that the app creates an atmosphere with a singular identify, on this case I received “vigilant-space-rotary-phone” however you’ll get one thing completely different. When you test the URL as of now, you will notice your atmosphere’s identify additionally exhibits up there, for instance mine is “https://vigilant-space-rotary-phone-someunreadblestuff.github.dev/“
Step 3 — Create the C program
Within the Explorer window (on the left) you will notice increasingly information populating an inventory as you develop the app. For the second we have now just one file, the README that we created earlier.
Now click on on New file (see crimson arrow under) and name it one thing with a .c extension. This file will maintain our app’s code:

As soon as the file is created, on the precise we kind the code, for instance:
#embrace
int major() {
printf("Hiya WASM tutorial!n");
return 0;
}
With Ctrl+S (Cmd+S in Mac) you save the file, which is now able to compile.
Step 4: Making Emscripten obtainable on this on-line Visible Studio Code session
However to compile the C code into WebAssembly, we’d like Emscripten, which isn’t there but within the atmosphere. Emscripten is likely one of the core instruments within the WebAssembly ecosystem. It compiles C and C++ code right into a .wasm file accompanied by browser-compatible runtime information that may present the interface between the app’s HTML+JS and the WASM file itself.
To “set up” Emscripten (I take advantage of citation marks as a result of nothing actually will get put in in your laptop, as that is all occurring someplace within the cloud!) you must kind some instructions within the terminal, as proven right here for the primary one:

The primary command, which you see above within the image, merely copies (or “clones”) the present model of Emscript from its GitHub repository:
git clone https://github.com/emscripten-core/emsdk.git
The output can be this:

You then cd into the emsd folder, which incorporates what we simply pulled from GitHub, after which run the command to put in it:

It will take a while to run, and if all of it goes properly (it ought to) then you will notice this on the finish:

We subsequent activate Emscripten:
./emsdk activate newest
And eventually load the atmosphere variables:
supply ./emsdk_env.sh
To confirm the set up, kind this:
emcc --version
It’s best to now see model info for the Emscripten compiler.
Step 5 — Compile this system into WebAssembly!
Nonetheless on the terminal, we go up one degree within the folder construction to get out of emsdk the place we put in Emscripten, after which run THE compiling command emcc file.c -o file.html:

You will notice some new information showing within the Explorer on the highest left:

The information as of now are the README and the c code which we had already created, plus the .wasm, HTML and JS information created by Emscripten. Tremendous easy, you see!
Now what are these information, and what do they do?
- hello-wasm-tutorial.wasm is the compiled WebAssembly binary, i.e. the core executable logic coming from the C program.
- hello-wasm-tutorial.js is the JavaScript glue code that permits to interface the wasm file to the remainder of the JavaScript code and thus the online app itself. This file masses the WASM module, initializes runtime reminiscence, and manages communication between the browser and the WebAssembly module.
- hello-wasm-tutoiral.html is a minimal webpage launcher generated robotically by Emscripten. Opening this web page runs the compiled utility.
Now let’s transfer on to check them!
Step 6: Testing (and look forward to step 7 to maneuver information out and into your individual server!)
To check our wasm app inside the online web page created by Emscripten itself, we have to begin a “native” internet server, the place once more “native” is inside citation marks as a result of we are going to really do it within the cloud (however being “native” for the Codespaces atmosphere, therefore the identify!).
We want this as a result of the app is supposed and designed to be served via an internet server. Thankfully, Python (which is already there within the cloud atmosphere) offers a tiny built-in HTTP server. We are able to activate this server by working this on the terminal:
python3 -m http.server 8000
That is the output you get from that command, together with a button that may launch the online app on a brand new window:

If you click on that you simply get to see a listing itemizing that features all of the information we have now to this point:

And eventually the magic: while you click on hello-wasm-tutorial.html, you get to see load this web page which in flip calls the wasm program after which exhibits its output (and I’m additionally displaying the browser’s console for completion):

Understanding by simplifying the HTML (and recall there’s step 7 to maneuver information out and into your individual server!)
As you see within the above instance (and in your individual laptop in the event you adopted the tutorial!), when Emscripten compiled our code it generated a cumbersome HTML web page with CSS, a complete UI together with loading and different standing messages, buttons, and so on. This is perhaps good for demos, however really complicates studying.
What we will do then is, to begin with, to get the minimal HTML code that may get the wasm code to run. And it seems you want little or no!
Simply create a brand new HTML file within the explorer:
Hiya WASM tutorial, the best!
Save it and go back to the Directory listing page on the Python mini server, hit Refresh to see the new file, and open it. It will now look like this, where the string output from the WASM program is displayed on the console because that’s what we are calling in the JS code:

You can now explore the different files (essentially this simple HTML plus the JS file created by Emscripten, as the C code you wrote it yourself so you already know what it does!) to understand a bit more.
Gaining control over what runs when, by calling functions of the C program from the HTML+JS interface (and step 7 is next!)
Gears up, let’s now see how we can create a web app with a button that will call a function from the WASM program compiled by Emscripten from C code, applying its result to the HTML document itself.
The main thing here si that we must create C functions separate from main() and export them, and recompile the program to produce the new WASM file together with a new JS “glue” file that will interface with the HTML to handle function calling.
Let’s suppose that we modify the C code to the following, which preserves the previous main() function and adds one that we’ll call from a button in the HTML:
#include
void button_message() {
printf("Hello from a function called specifically from the web page!n");
}
int main() {
printf("Hello WASM tutorial (main function!)!n");
return 0;
}
Note that in the main function we have modified the output from printf(); this is to make sure we know where the text is coming from.
Now, we compile with the following command:
emcc hello-wasm-tutorial.c -o hello-wasm-tutorial.js -sEXPORTED_FUNCTIONS=_main,_button_message -sEXPORTED_RUNTIME_METHODS=ccall
Note three things: (i) We don’t ask it to rebuild the whole web app but just the JS glue file (in addition to the WASM file, of course); (ii) We flag which functions we want to get exported (in this case both); (iii) The functions are called with an underscore in front.
You can go back to the Emscripten-generated HTML on the Python server, and you will see it still runs as usual, now just with the slightly modified text as we changed the argument to printf() in the main function:

Of course, since the minimalist HTML page we wrote is calling the same JS glue file and the same WASM, then the changes we introduced in the printf() call inside main() also affect it (see the console log):

Now, we can create a new web page derived from the minimalist one, where we add a button that will call the function button_message() already compiled into the WASM file. This HTML code still calls the same glue JS file, and it has itself some extra JS code inside a
Hiya WASM, referred to as from a button
major() is named on load
Now, this code is a bit sophisticated because of an issue in our quite simple C program: it doesn’t return something like a string that the online app might then correctly pattern, so we use a walkaround to seize the textual content printed by printf() and put it in a JS variable that we will then use at will. I'll quickly cowl the precise approach to deal with passing variables, however in a separate put up!
For the second, stick with this. If you load this new easy web page with button-controlled operate name, you see first this:

After which this after you click on the button:

Lastly, step 7: Obtain the related information and mount them in your server
As there’s no backend, the process is trivial: obtain the HTML, JS and WASM information, and add them to your server ensuring they're all in the identical folder. For instance, right here’s how I moved my final combo of information to my web site at Altervista (by the best way my favorite free hosting platform by far, for the reasons I explain here):
First we have to obtain from Codespaces the three major information (HTML, WASM, JS) to the native laptop:

Subsequent, we add them to the precise folder in our web site, right here my in Altervista account the place the folder finally ends up populated with:

Lastly we simply open the HTML file, and voilà it’s all working!

(You may take a look at this right here: https://lucianoabriata.altervista.org/tests/wasm-tests/wasm-tutorial-1/hello-wasm-tutorial-simpler-withbutton.html)
Time so that you can observe, and till subsequent time!
I actually hope that you simply’ve had plenty of enjoyable simply as I did as I used to be studying about all this world. In my subsequent put up I'll attempt to cowl the next:
- Returning values from C/WASM as an alternative of counting on
printf(), Module.ccall()return sorts,- Passing arguments from JS to WASM,
- Persistent WASM state throughout calls,
- International/static variables in WASM,
- The mannequin of a WASM module that stays “alive” in the course of the session,
- Interplay structure between the browser and the WASM program,
- Why
major()behaves like initialization.
All this, whereas constructing a tiny stateful interactive instance like on this tutorial. And for sure, once more all internet by utilizing GitHub Codespaces.
Till subsequent time, and I allow you to with a abstract of this text that I ready by placing collectively ChatGPT generations with guide edits:


