विश्व का सबसे बड़ा हिंदी वेब डेवलपर साइट

AngularJS ng-style Directive


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

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

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

var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.myObj = {
        "color" : "white",
        "background-color" : "coral",
        "font-size" : "60px",
        "padding" : "50px"
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.


<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.