html_builder 1.0.2

  • Installing
  • Versions
  • 69


Pub build status

Build HTML AST's and render them to HTML.

This can be used as an internal DSL, i.e. for a templating engine.


In your pubspec.yaml:

  html_builder: ^1.0.0


import 'package:html_builder/html_builder.dart';

main() {
    // Akin to React.createElement(...);
    var $el = h('my-element', {}, []);

    // Attributes can be plain Strings.
    h('foo', {
        'bar': 'baz'

    // Null attributes do not appear.
    h('foo', {
        'does-not-appear': null

    // If an attribute is a bool, then it will only appear if its value is true.
    h('foo', {
        'appears': true,
        'does-not-appear': false

    // Or, a String or Map.
    h('foo', {
        'style': 'background-color: white; color: red;'

    h('foo', {
        'style': {
            'background-color': 'white',
            'color': 'red'

    // Or, a String or Iterable.
    h('foo', {
        'class': 'a b'

    h('foo', {
        'class': ['a', 'b']

Standard HTML5 elements:

import 'package:html_builder/elements.dart';

main() {
    var $dom = html(lang: 'en', children: [
        head(children: [
            title('Hello, world!')
        body(children: [
            h1('Hello, world!'),

Rendering to HTML:

String html = new StringRenderer().render($dom);

Example with the Angel server-side framework:

import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:html_builder/elements.dart';

configureViews(Angel app) async {
    app.get('/foo', (req, res) async {
        var foo = await app.service('foo').read(req.params['id']);
        var $dom = html(children: [
            head(children: [
            body(children: [
                h1(children: [text(])

          ..contentType = ContentType.HTML
          ..write(new StringRenderer().render($dom))


Changed h and the Node constructor to take Iterables of children, instead of just Lists.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  html_builder: "^1.0.2"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

      import 'package:html_builder/html_builder.dart';
Version Uploaded Documentation Archive
1.0.2 Jul 23, 2017 Go to the documentation of html_builder 1.0.2 Download html_builder 1.0.2 archive
1.0.1 Jun 6, 2017 Go to the documentation of html_builder 1.0.1 Download html_builder 1.0.1 archive
1.0.0+1 Apr 11, 2017 Go to the documentation of html_builder 1.0.0+1 Download html_builder 1.0.0+1 archive
1.0.0 Apr 11, 2017 Go to the documentation of html_builder 1.0.0 Download html_builder 1.0.0 archive


We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
38 / 100
Code health derived from static analysis. [more]
100 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:html_builder/html_builder.dart.


  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use html_builder.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0
Dev dependencies
html ^0.13.1
test ^0.12.0