1e41f4b71Sopenharmony_ci# Style Inheritance 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci> **NOTE** 4e41f4b71Sopenharmony_ci> 5e41f4b71Sopenharmony_ci> The APIs of this module are supported since API version 9. Updates will be marked with a superscript to indicate their earliest API version. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciA custom component has the **inherit-class** attribute, which is defined in the following table. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci| Name | Type | Default Value | Mandatory | Description | 10e41f4b71Sopenharmony_ci| ------------- | ------ | ---- | ---- | -------------------------------- | 11e41f4b71Sopenharmony_ci| inherit-class | string | - | No | Class styles inherited from the parent component, separated by spaces.| 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ciTo enable a custom component to inherit the styles of its parent component, set the **inherit-calss** attribute for the custom component. 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciThe example below is a code snippet in the HML file of the parent component that references a custom component named **comp**. This component uses the **inherit-class** attribute to inherit the styles of its parent component: **parent-class1** and **parent-class2**. 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci```html 18e41f4b71Sopenharmony_ci<!-- xxx.hml --> 19e41f4b71Sopenharmony_ci<element name='comp' src='../../common/component/comp.hml'></element> 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci<div class="container"> 22e41f4b71Sopenharmony_ci <comp inherit-class="parent-class1 parent-class2" ></comp> 23e41f4b71Sopenharmony_ci</div> 24e41f4b71Sopenharmony_ci``` 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ciCode snippet in the CSS file of the parent component: 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci```css 29e41f4b71Sopenharmony_ci/* xxx.css */ 30e41f4b71Sopenharmony_ci.parent-class1 { 31e41f4b71Sopenharmony_ci background-color:red; 32e41f4b71Sopenharmony_ci border:2px; 33e41f4b71Sopenharmony_ci} 34e41f4b71Sopenharmony_ci.parent-class2 { 35e41f4b71Sopenharmony_ci background-color:green; 36e41f4b71Sopenharmony_ci border:2px; 37e41f4b71Sopenharmony_ci} 38e41f4b71Sopenharmony_ci``` 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ciCode snippet in the HML file of the custom component, where **parent-class1** and **parent-class2** are styles inherited from the parent component: 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci```html 43e41f4b71Sopenharmony_ci<!--comp.hml--> 44e41f4b71Sopenharmony_ci<div class="item"> 45e41f4b71Sopenharmony_ci <text class="parent-class1">Style 1 inherited from the parent component</text> 46e41f4b71Sopenharmony_ci <text class="parent-class2">Style 2 inherited from the parent component</text> 47e41f4b71Sopenharmony_ci</div> 48e41f4b71Sopenharmony_ci``` 49