> For the complete documentation index, see [llms.txt](https://tonyding.gitbook.io/angular/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tonyding.gitbook.io/angular/angular-tips-1/set-css-background-image-value-in-angular.md).

# Set CSS background-image value in Angular

Component Html code

```markup
<div *ngIf="doc.filePreviewUrl" class='imageDiv' [style.background-image]="getSafeUrl(filePreviewUrl)"></div>
```

Component TS code

```typescript
import { DomSanitizer } from '@angular/platform-browser';

constructor(private sanitization: DomSanitizer) { }

// Return trust style
getSafeUrl(filePreviewUrl){
  return this.sanitization.bypassSecurityTrustStyle('url(\'' + filePreviewUrl + '\')');
}  
```

Component CSS

```css
.imageDiv{
    height: 100%;
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
}
```
