AngularJS | ng-style Directive

The ng-style Directive in AngularJS is used to apply custom CSS styles on an HTML element. The expression inside the ng-style directive must be an object. It is supported by all the HTML elements.
Syntax:

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

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
    <head>
        <title>ng-style Directive</title>
        <script src=
        </script>
<style type="text/css">
    .bg-color {
        background-color: pink;
        padding:10px;
        font-size: 18px;
    }
</style>
    </head>
    <body ng-app="app" style="text-align:center">
      <h1 style="color:green">GeeksforGeeks</h1>
      <h2>ng-style Directive</h2>
  
  
    <div ng-controller="controllerName">
        Input: 
       <input type="text" ng-model="color" placeholder="Enter any color." />
        <p ng-repeat="i in sort" ng-style="{color:color}">
         <span class="bg-color">  Name: {{i.name}}</span>
        </p>
    </div>
    <script>
    var app = angular.module("app", []);
    app.controller('controllerName', ['$scope', function ($scope) {
        $scope.sort = [
       { name: 'Merge sort' }, 
       { name: 'Quick sort' }, 
       { name: 'Radix sort' }];
    }]);
</script>
</body>
</html>

chevron_right


Output:
Before:
ngstyle
After:
ngstyle



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.