A new language, with tools and libraries, for structured web app engineering

Get started

Dart has all the pieces you need to write modern web apps:

The Dart language is familiar and easy to learn. It's class based and object oriented, without being dogmatic.
Tools such as Dart Editor and the pub package manager keep you productive.
Core libraries provide all the basics, including support for asynchronous programming with Futures.
Performance is good and getting better. Dart apps are fastest in the Dart VM, but they can be speedy even after compilation to JavaScript.
Polymer.dart lets you use future web APIs today, with support for web components, custom elements, data binding, and more.
All modern browsers (both desktop and mobile) can run Dart web apps, thanks to our Dart-to-JavaScript compiler.
Chrome, Firefox, Safari, IE logos
Headlines from news.dartlang.org

Code

You can find code examples in Dart Editor's welcome page, in the Samples page, and below. You can also experiment with Dart right in your browser: try.dartlang.org

Dart aims to be unsurprising, but it does add a few language features to keep your code succinct yet understandable. Read all about Dart syntax in the Dart language tour.

import 'dart:math';                   // Import a library.

// Functions and variables can be inside or outside of classes.
var shapes = new List();              // A global variable.
addShape(shape) => shapes.add(shape); // Function shorthand syntax.

// Every app has a main() function, where execution starts.
main() {  
  // The cascade operator (..) saves you from repetitive typing.
  addShape(new Ellipse(10, 20)..rotation = 45*PI/180
                              ..color = 'rgb(0,129,198)'
                              ..outlineWidth = 0);
  
  // You can easily insert expression values into strings.
  print('Area of the first shape: ${shapes[0].area}');
}

Declaring types is optional in Dart. These types don't affect the runtime behavior, but you can use them to clarify APIs and get better help from tools—for example, better code completion, easier navigation, and earlier error detection. For details, see Optional Types in Dart.

// Without types.
recalculate(origin, offset, estimate) {
  // ...
}
// With types (and an optional parameter).
num recalculate(Point origin,
                num offset,
                {bool estimate:false}) {
  // ...
}

Dart is object oriented, with full support for classes. Each class has a single superclass, but classes can implement any number of interfaces. For details, see Classes in the language tour.

import 'dart:math';

class Ellipse extends Shape {              // Declare a class.
  num majorAxis = 0;                        // An instance variable (property).
  num minorAxis = 0;
  static const num C = PI/4;              // A constant.
  num get area => C*majorAxis*minorAxis;   // A property implemented with a getter.

  Ellipse(this.majorAxis, this.minorAxis); // Compact constructor syntax.
  Ellipse.circle(num diameter) {           // A named constructor.
    minorAxis = majorAxis = diameter;
  }
}

abstract class Shape {                     // Declare a class that can't be instantiated.
  num get area;
  num rotation = 0;
  num outlineWidth = 1;
  String color = 'black';
}

Functions that do potentially expensive work return Futures. To specify what happens when the function's work is done, invoke then() on the Future. To handle errors, invoke catchError(). Learn more by reading Using Future Based APIs.

import 'dart:io';
import 'dart:async';

void printDailyNewsDigest() {
  File file = new File("dailyNewsDigest.txt");
  file.readAsString()                  // readAsString() returns a Future.
    .then((content) => print(content)) // Handle successful completion.
    .catchError((error) =>             // Handle failure.
        print("Sorry, no news today. Here's why:\n$error"));
}

Here's an example of implementing a web app using the polymer.dart package.

<head>
  <link rel="import" href="click_counter.html">
  <script src="packages/polymer/boot.js"></script>
</head>

<body>   
  <click-counter></click-counter>
</body>
<polymer-element name="click-counter">
  <template>
    <button on-click="increment">Click Me</button>
    <p>You clicked the button {{count}} times.</p>
  </template>
  <script type="application/dart">
    import 'package:polymer/polymer.dart';
    import 'dart:html';

    @CustomTag('click-counter')
    class ClickCounterElement extends PolymerElement with ObservableMixin {
      @observable int count = 0;
      
      void increment(Event e, var detail, Node target) {
        count += 1;
      }
    }
  </script>
</polymer-element>

Get started

Getting started with Dart is easy. Just download Dart, and you'll get Dart Editor, a full-featured editing environment that comes with samples and app templates. Then, for a gentle introduction to web programming, follow the Dart tutorials. When you have a question that the documentation doesn't answer, check Stack Overflow.