Please note, this is a STATIC archive of website www.w3schools.com from 05 May 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.
THE WORLD'S LARGEST WEB DEVELOPER SITE

AngularJS ng-style Directive


Example

Add some style with AngularJS, using an object with CSS keys and values:

<body ng-app="myApp" ng-controller="myCtrl">

<h1 ng-style="myObj">Welcome</h1>

<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.myObj = {
        "color" : "white",
        "background-color" : "coral",
        "font-size" : "60px",
        "padding" : "50px"
    }
});
</script>
</body>
Try it Yourself »

Definition and Usage

The ng-style directive specifies the style attribute for the HTML element.

The value of the ng-style attribute must be an object, or an expression returning an object.

The object consists of CSS properties and values, in key value pairs.


Syntax

<element ng-style="expression"></element>

Supported by all HTML elements.


Parameter Values

Value Description
expression An expression which returns an object where the keys are CSS properties, and the values are CSS values.