marko-js / marko

A declarative, HTML-based language that makes building web apps fun
https://markojs.com/
MIT License
13.25k stars 643 forks source link
client-side-rendering dom frontend isomorphic javascript nodejs server-side-rendering ui-components vdom
# [Marko](https://markojs.com/) **A declarative, HTML-based language that makes building web apps fun 🔥** [![NPM](https://img.shields.io/npm/v/marko.svg)](https://www.npmjs.com/package/marko) [![Discord Chat](https://img.shields.io/badge/discord-chat-7188da.svg)](https://discord.gg/RFGxYGs) [![Continuous Integration status](https://github.com/marko-js/marko/actions/workflows/ci.yml/badge.svg)](https://github.com/marko-js/marko/actions/workflows/ci.yml) [![Code coverage %](https://codecov.io/gh/marko-js/marko/branch/master/graph/badge.svg)](https://codecov.io/gh/marko-js/marko) [![# of monthly downloads](https://img.shields.io/npm/dm/marko.svg)](https://npm-stat.com/charts.html?package=marko) [![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/7029/badge)](https://bestpractices.coreinfrastructure.org/projects/7029) [Docs](https://markojs.com/docs/getting-started/) ∙ [Try Online](https://markojs.com/try-online/) ∙ [Contribute](#contributors) ∙ [Get Support](#community--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

<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
```marko ul.example-list for|color| of=[a, b, c] li -- ${color} ``` ```marko
  • ${color}
```

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](https://stackoverflow.com/questions/tagged/marko) Come [hang out in our Discord chat](https://discord.gg/RFGxYGs), ask questions, and discuss project direction [Tweet to `@MarkoDevTeam`](https://twitter.com/MarkoDevTeam), or with the [`#markojs` hashtag](https://twitter.com/search?q=%23markojs&f=live)

Contributors

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

All marko-js/marko GitHub contributors

Get Involved!