Convert Figma logo to code with AI

marko-js logomarko

A declarative, HTML-based language that makes building web apps fun

13,347
643
13,347
54

Top Related Projects

227,213

The library for web and native user interfaces.

207,677

This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core

95,657

Deliver web apps with confidence 🚀

78,194

Cybernetically enhanced web apps

36,546

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.

27,910

A rugged, minimal framework for composing JavaScript behavior in your markup.

Quick Overview

Marko is a fast and lightweight UI library for building web applications. It combines the simplicity of HTML with the power of JavaScript, allowing developers to create dynamic and interactive user interfaces efficiently. Marko is designed to be performant and easy to learn, making it suitable for both small and large-scale projects.

Pros

  • Fast rendering and small bundle size, leading to improved performance
  • Easy to learn syntax, combining HTML-like templates with JavaScript
  • Built-in compiler for optimized output and server-side rendering support
  • Seamless integration with existing Node.js and JavaScript ecosystems

Cons

  • Smaller community compared to more popular frameworks like React or Vue
  • Limited third-party component libraries and ecosystem
  • Learning curve for developers accustomed to other UI frameworks
  • Less extensive documentation compared to more established libraries

Code Examples

  1. Basic component:
class {
  onCreate() {
    this.state = { count: 0 };
  }
  increment() {
    this.state.count++;
  }
}

<div>
  <h1>Counter: ${state.count}</h1>
  <button on-click('increment')>Increment</button>
</div>
  1. Conditional rendering:
<if(user.isLoggedIn)>
  <h1>Welcome, ${user.name}!</h1>
  <else>
    <h1>Please log in</h1>
  </else>
</if>
  1. Looping through data:
<ul>
  <for|item| of=items>
    <li>${item.name}</li>
  </for>
</ul>

Getting Started

  1. Install Marko and its CLI:
npm install marko @marko/serve
  1. Create a new Marko component (e.g., hello.marko):
<h1>Hello, ${input.name}!</h1>
  1. Create an entry file (e.g., index.js):
import HelloComponent from './hello.marko';

const hello = HelloComponent.renderSync({ name: 'World' });
hello.appendTo(document.body);
  1. Run the application:
npx @marko/serve index.js

Competitor Comparisons

227,213

The library for web and native user interfaces.

Pros of React

  • Larger ecosystem and community support
  • More extensive documentation and learning resources
  • Wider adoption in industry, leading to better job prospects

Cons of React

  • Steeper learning curve, especially for beginners
  • Requires additional libraries for routing and state management
  • Higher bundle size compared to Marko

Code Comparison

React:

function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}

const element = <Welcome name="Sara" />;

Marko:

<h1>Hello, ${input.name}</h1>

<welcome name="Sara"/>

Key Differences

  • Marko uses a template-based syntax, while React uses JSX
  • Marko has built-in async rendering capabilities
  • React relies on a virtual DOM, while Marko uses a compile-time approach
  • Marko offers both single-file components and separate files for markup and logic
  • React has a more explicit component lifecycle, while Marko handles many optimizations automatically

Performance

  • Marko generally offers better out-of-the-box performance
  • React requires careful optimization to achieve similar performance levels
  • Marko's compiler can generate more efficient code for server-side rendering

Learning Curve

  • React has a steeper initial learning curve but offers more flexibility
  • Marko's syntax is more intuitive for developers familiar with HTML templates
  • React's concepts (like hooks) may take longer to master compared to Marko's straightforward approach
207,677

This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core

Pros of Vue

  • Larger ecosystem and community support
  • More comprehensive documentation and learning resources
  • Flexible and incrementally adoptable framework

Cons of Vue

  • Steeper learning curve for complex applications
  • Potentially slower rendering performance for large-scale apps
  • Less emphasis on server-side rendering capabilities

Code Comparison

Vue component:

<template>
  <div>{{ message }}</div>
</template>

<script>
export default {
  data() {
    return {
      message: 'Hello, Vue!'
    }
  }
}
</script>

Marko component:

class {
  onCreate() {
    this.state = { message: 'Hello, Marko!' };
  }
}

<div>${state.message}</div>

Vue and Marko are both popular JavaScript frameworks for building user interfaces. Vue offers a more extensive ecosystem and flexibility, making it suitable for various project sizes. However, it may have a steeper learning curve for complex applications. Marko, on the other hand, focuses on simplicity and performance, particularly excelling in server-side rendering. The code comparison demonstrates the different syntax and structure between the two frameworks, with Vue using a template-script separation and Marko utilizing a more compact, single-file approach.

95,657

Deliver web apps with confidence 🚀

Pros of Angular

  • More comprehensive framework with built-in solutions for routing, forms, and HTTP requests
  • Larger ecosystem and community support, with extensive documentation and third-party libraries
  • TypeScript-first approach, providing better type checking and tooling support

Cons of Angular

  • Steeper learning curve due to its complexity and numerous concepts to grasp
  • Heavier bundle size, which can impact initial load times for applications
  • More opinionated structure, potentially limiting flexibility in some scenarios

Code Comparison

Angular component:

@Component({
  selector: 'app-hello',
  template: '<h1>Hello, {{name}}!</h1>'
})
export class HelloComponent {
  name: string = 'World';
}

Marko component:

class {
  onCreate() {
    this.state = { name: 'World' };
  }
}

<h1>Hello, ${state.name}!</h1>

Angular and Marko are both powerful tools for building web applications, but they cater to different needs. Angular is a full-featured framework suitable for large-scale applications, while Marko is a lightweight UI library focused on performance and simplicity. The choice between them depends on project requirements, team expertise, and desired application architecture.

78,194

Cybernetically enhanced web apps

Pros of Svelte

  • Smaller bundle sizes due to compile-time optimization
  • Simpler syntax with less boilerplate code
  • More active community and ecosystem

Cons of Svelte

  • Steeper learning curve for developers familiar with traditional frameworks
  • Less mature than Marko, with fewer enterprise-level adoptions
  • Limited server-side rendering capabilities compared to Marko

Code Comparison

Svelte component:

<script>
  let count = 0;
  function increment() {
    count += 1;
  }
</script>

<button on:click={increment}>
  Clicks: {count}
</button>

Marko component:

class {
  onCreate() {
    this.state = { count: 0 };
  }
  increment() {
    this.state.count++;
  }
}

<button on-click('increment')>
  Clicks: ${state.count}
</button>

Both Svelte and Marko offer component-based architectures for building user interfaces. Svelte focuses on compile-time optimizations and a simpler syntax, while Marko provides powerful server-side rendering capabilities and a more traditional component structure. Svelte's approach results in smaller bundle sizes and less boilerplate, but Marko's maturity and enterprise adoption make it a strong choice for large-scale applications. The choice between the two depends on specific project requirements and team preferences.

36,546

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.

Pros of Preact

  • Smaller bundle size (3KB gzipped) for lightweight applications
  • Closer to vanilla JavaScript, easier learning curve for developers
  • Faster rendering and better performance in many scenarios

Cons of Preact

  • Less extensive ecosystem and fewer built-in features compared to Marko
  • Limited server-side rendering capabilities out of the box
  • May require additional libraries for complex state management

Code Comparison

Marko:

class {
  onCreate() {
    this.state = { count: 0 };
  }
  increment() {
    this.state.count++;
  }
}

<button on-click('increment')>
  Count: ${state.count}
</button>

Preact:

import { h, Component } from 'preact';

class Counter extends Component {
  state = { count: 0 };
  increment = () => this.setState({ count: this.state.count + 1 });
  render({ }, { count }) {
    return <button onClick={this.increment}>Count: {count}</button>;
  }
}

Both examples demonstrate a simple counter component, showcasing the syntax differences between Marko and Preact. Marko uses a more declarative approach with its custom syntax, while Preact follows a JavaScript-centric approach similar to React.

27,910

A rugged, minimal framework for composing JavaScript behavior in your markup.

Pros of Alpine

  • Lightweight and minimal, with a small learning curve
  • Easy integration into existing projects without build steps
  • Reactive and declarative syntax for simple UI interactions

Cons of Alpine

  • Limited functionality for complex applications compared to Marko
  • Less performant for large-scale applications
  • Lacks server-side rendering capabilities out of the box

Code Comparison

Alpine:

<div x-data="{ open: false }">
    <button @click="open = !open">Toggle</button>
    <span x-show="open">Content</span>
</div>

Marko:

class {
    onCreate() {
        this.state = { open: false };
    }
    toggle() {
        this.state.open = !this.state.open;
    }
}

<button on-click('toggle')>Toggle</button>
<if(state.open)>
    <span>Content</span>
</if>

Alpine focuses on simplicity and ease of use, making it ideal for adding interactivity to existing HTML. It's perfect for small to medium-sized projects that don't require complex state management or server-side rendering.

Marko, on the other hand, offers a more comprehensive solution for building web applications. It provides better performance for large-scale applications, server-side rendering capabilities, and a more structured approach to component development. However, it has a steeper learning curve and requires a build step.

Choose Alpine for quick, lightweight interactivity in existing projects, and Marko for building more complex, performant web applications with server-side rendering needs.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Marko

A declarative, HTML-based language that makes building web apps fun 🔥

NPM Discord Chat Continuous Integration status Code coverage % # of monthly downloads OpenSSF Best Practices

Docs ∙ Try Online ∙ Contribute ∙ Get Support

Intro

Marko is HTML reimagined as a language for building dynamic and reactive user interfaces. Almost any valid HTML is valid Marko, and Marko extends HTML for building modern applications more declaratively. Among these extensions are conditionals and lists, state, and components.

Marko supports both single-file components and components across separate files.

Single-file component

The following renders a button and a counter of how many times the button has been pressed:

click-count.marko

class {
  onCreate() {
    this.state = { count: 0 };
  }
  increment() {
    this.state.count++;
  }
}

style {
  .count {
    color: #09c;
    font-size: 3em;
  }
  .press-me {
    padding: 0.5em;
  }
}

<output.count>
  ${state.count}
</output>
<button.press-me on-click('increment')>
  Press me!
</button>

Multi-file component

The same component as above, but split into:

  • index.marko template file
  • component.js component JS logic file
  • style.css component styles file

index.marko

<output.count>
  ${state.count}
</output>
<button.press-me on-click('increment')>
  Press me!
</button>

component.js

export default {
  onCreate() {
    this.state = { count: 0 };
  },
  increment() {
    this.state.count++;
  },
};

style.css

.count {
  color: #09c;
  font-size: 3em;
}
.press-me {
  padding: 0.5em;
}

Concise Syntax

Marko also supports a beautifully concise syntax as an alternative to its HTML syntax:

Concise syntaxHTML syntax
ul.example-list
  for|color| of=[a, b, c]
    li -- ${color}
<ul class="example-list">
  <for|color| of=[a, b, c]>
    <li>${color}</li>
  </for>
</ul>

Getting Started

  1. npm install marko
  2. Read the docs

Community & Support

Stack Overflow Discord Twitter

Ask and answer StackOverflow questions with the #marko tag

Come hang out in our Discord chat, ask questions, and discuss project direction

Tweet to @MarkoDevTeam, or with the #markojs hashtag

Contributors

Marko would not be what it is without all those who have contributed ✨

All marko-js/marko GitHub contributors

Get Involved!

NPM DownloadsLast 30 Days