Marko Fundamentals
The web is built on HTML and JavaScript. Marko is a programming language that attempts to rethink what web development might look like if HTML and JavaScript were a single, unified language.
HTML
There are countless guides and tutorials already on the internet for learning HTML, and these docs won't do them any justice. Marko builds on top of HTML, so everything you learn about it can be applied to Marko.
We'll provide a brief overview of HTML and JS here, but for a more comprehensive guide some of our favorites are MDN and Free Code Camp.
JavaScript
JavaScript is the programming language of the web that enables interactive and dynamic content. When working with traditional HTML and JavaScript, you often need to write code that interacts with the DOM (Document Object Model).
Basic DOM Interaction
In traditional JavaScript and HTML, handling interactions looks like this:
<button id="myButton">
Click me
</button>
<script>
document.getElementById("myButton").addEventListener("click", function () {
alert("Button clicked!");
});
</script>
button#myButton -- Click me
script
--
document.getElementById("myButton").addEventListener("click", function () {
alert("Button clicked!");
});
--
This approach has several drawbacks:
- You need to assign IDs or find elements by selectors
- The connection between elements and their behavior is indirect
- As applications grow, this becomes difficult to maintain
Marko addresses these issues by integrating JavaScript expressions directly into templates and providing simpler ways to handle events, which we'll explore later in this tutorial.
Marko
Everything we've seen so far isn't just HTML and JavaScript— it's actually valid Marko code too! The vast majority of HTML code that you find on the internet can be copy-pasted into a .marko
file and it will work, just as expected!
But Marko extends HTML with powerful features that make building interactive web applications easier.
Next, check out the components and reactivity tutorial
Contributors
Helpful? You can thank these awesome people! You can also edit this doc if you see any issues or want to improve it.
Comments
HTML comments are written between
<!--
and-->
. These are useful for documenting your code or temporarily disabling parts of it:Comments can span multiple lines, but they cannot be nested inside other comments.