To style the host element of the component, use ng-style directive. CSS properties help in the styling of the component.
Approach: Styling of host components uses CSS properties, which can be altered, modified and updated whenever needed.
The CSS properties are listed as follows:
- color: Used to set font color.
- background-color: Used to set background color.
- font-size: Used to set size of font.
- padding: Used to set space around the text.
Syntax:
<element ng-style="property"></element>
Example 1: This example uses ng-style directive. CSS properties of font color and background color are used here.
<!DOCTYPE html> <html> <head> <h1><center>Geeks for Geeks</center></h1></head> <script src= </script> <body ng-app="gfg" ng-controller="gfgctrl"> <h1 ng-style="ele">GFG</h1> <h2 ng-style="ele">Portal</h2> <script> var app = angular.module("gfg", []); app.controller("gfgctrl", function($scope) { $scope.ele = { "color": "white", "background-color": "green", } }); </script> </body> </html> |
Output:

Example 2: This example shows the styling of components based on font-size, font-color and background color.
<!DOCTYPE html> <html> <head> <h1><center>Geeks for Geeks</center></h1></head> <script src= </script> <body ng-app="gfg" ng-controller="gfgctrl"> <h1 ng-style="ele">GFG</h1> <h2 ng-style="ele1">Portal</h2> <script> var app = angular.module("gfg", []); app.controller("gfgctrl", function($scope) { $scope.ele = { "color": "white", "background-color": "green", "font-size": "120px", } $scope.ele1 = { "color": "white", "background-color": "green", "font-size": "20px", } }); </script> </body> </html> |
Output:

Recommended Posts:
- How to communicate from parent component to the child component in Angular 9 ?
- Difference between Directive and Component in AngularJS
- HTML | DOM Location host Property
- host command in Linux with examples
- HTML | DOM Anchor host Property
- Node | urlObject.host API
- HTTP headers | Host
- HTTP header | X-Forwarded-Host
- How to Host a Local Server globally for more than one system ?
- How to extract the host name from URL using JavaScript ?
- How to Build Portfolio Website And Host It on GitHub Pages?
- How to host a simple website using Google Sites ?
- AngularJS | ng-style Directive
- How to set active tab style with AngularJS?
- Principal Component Analysis with Python
- Design a form component which takes input from its user and displays a form
- How to pass string to a component using Angular2 ?
- Peripheral Component Interconnect (PCI)
- How to enable routing and navigation between component pages in Angular 8 ?
- What is PCIe(Peripheral Component Interconnect express)?
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.

