# Components Being able to render HTML is great, but web apps need styling and in-browser behavior as well. Marko's components makes it easy to to co-locate your styles and scripts with the HTML that they interact with. In order to make use of components, you will need to use an asset manager (like `lasso`, `webpack`, or `browserify`). We recommend the [`lasso` taglib]() as it only requires adding a couple of tags to your layout template. ## Single file components ### A simple component Let's say we have a ` ``` Marko makes this really easy, allowing you to define a `class` for a component right in the `.marko` template and call methods of that class with `on-` attributes: ```xml class { sayHi() { alert(`Hi!`); } } ``` ### Accessing input When a template is rendered, it is passed an `input` variable. You can access the same input values inside a component's class via `this.input`: ```xml class { sayHi() { alert(`Hey, ${this.input.name}!`); } } ``` ### Adding state Alerting when a button is clicked is great, but typically you need to update your UI in response to an action. Marko's stateful components make this easy. All you need to do is set `this.state` from inside your component's class. This makes a new `state` variable available to your template. When a value in `this.state` is changed, the template will automatically re-render and only update the part of the DOM that changed. ```xml class { constructor() { this.state = { count:0 }; } increment() { this.state.count++; } }
The current count is ${state.count}
``` > **Note:** Only state properties defined when initially setting `this.state` will be watched for changes. If you don't need a property initially, you can set it to `null`. ### Styles Adding styles to your template is also made easy. These styles won't be output in a `