<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[Patricia Barros]]></title><description><![CDATA[Measuring programming progress by lines of code is like measuring aircraft building progress by weight.]]></description><link>https://patriciabarros.azurewebsites.net/</link><image><url>http://patriciabarros.azurewebsites.net/favicon.png</url><title>Patricia Barros</title><link>https://patriciabarros.azurewebsites.net/</link></image><generator>Ghost 1.10</generator><lastBuildDate>Sun, 19 Apr 2026 02:00:23 GMT</lastBuildDate><atom:link href="https://patriciabarros.azurewebsites.net/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Angular + PrimeNG: Custom styling PrimeNG components]]></title><description><![CDATA[<div class="kg-card-markdown"><p>I hope this post can help others, considering how difficult it was for me to find a good solution. I spent a long of time on stackoverflow, github, primeNG tutorials and many other blogs and forums in the internet.</p>
<p>I have to say that I'm a green angular developer and</p></div>]]></description><link>https://patriciabarros.azurewebsites.net/custom-styling-primeng/</link><guid isPermaLink="false">5a7677a9e43e0a0780192e10</guid><category><![CDATA[PrimeNG]]></category><category><![CDATA[Custom]]></category><category><![CDATA[Style]]></category><category><![CDATA[Angular]]></category><category><![CDATA[Override]]></category><category><![CDATA[Ng-deep]]></category><dc:creator><![CDATA[Patricia Barros]]></dc:creator><pubDate>Fri, 09 Feb 2018 00:05:18 GMT</pubDate><media:content url="https://patriciabarros.azurewebsites.net/content/images/2018/02/primeng.jpg" medium="image"/><content:encoded><![CDATA[<div class="kg-card-markdown"><img src="https://patriciabarros.azurewebsites.net/content/images/2018/02/primeng.jpg" alt="Angular + PrimeNG: Custom styling PrimeNG components"><p>I hope this post can help others, considering how difficult it was for me to find a good solution. I spent a long of time on stackoverflow, github, primeNG tutorials and many other blogs and forums in the internet.</p>
<p>I have to say that I'm a green angular developer and using a component library such as PrimeNG is a huge help, but it can be frustrating at the same time considering the original style of the component may not match with project that you are coding.</p>
<hr>
<h2 id="beforewegetstarted">Before we get started...</h2>
<ul>
<li>Create a new Angular project <code>ng new my-project-app</code></li>
<li>Add PrimeNG to the project <code>npm install primeng --save</code></li>
<li>Add Font Awesome to the project (PrimeNG uses font-awesome style and icons) <code>npm install font-awesome --save</code></li>
</ul>
<hr>
<h2 id="thechallenge">The Challenge</h2>
<p>I needed to include the FileUpload component from PrimeNG in one of the pages that I'm coding, <em>until here nothing new or hard</em>, however the component style doesn't harmonize with the page's style.</p>
<blockquote>
<p>You just don't like the component's look or the style provided by the client is totally different and the component needs to change.</p>
</blockquote>
<p>So, no problem lets override the component style. Easy right? You just need to find the style name to be overridden and done. <mark>It was not that easy...</mark></p>
<hr>
<h2 id="mycustomcomponent">My custom component</h2>
<blockquote>
<p>The source code covered in this post is available <a href="https://github.com/patriba/custom-styling-primeng">here</a></p>
</blockquote>
<p>I needed to change the background and font colors, I also needed to remove the <code>+</code> left image from the button. So, the component will look like a link not a button.</p>
<p>Here is how the original PrimeNG FileUpload looks like <code>on basic mode</code> and how I want my final custom component.</p>
<p><img src="https://patriciabarros.azurewebsites.net/content/images/2018/02/primeng-fileupload.png" alt="Angular + PrimeNG: Custom styling PrimeNG components"></p>
<p>app.component.html piece of code</p>
<pre><code class="language-html">&lt;h2&gt;Original PrimeNG FileUpload component&lt;/h2&gt;
&lt;p-fileUpload name=&quot;avatar&quot; auto=&quot;true&quot; mode=&quot;basic&quot; accept=&quot;image/*&quot; customUpload=&quot;true&quot; (uploadHandler)=&quot;onFileChange($event)&quot; chooseLabel=&quot;Upload here&quot; &gt;&lt;/p-fileUpload&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;h2&gt;My Custom PrimeNG FileUpload component&lt;/h2&gt;
&lt;p-fileUpload id=&quot;myAvatar&quot; auto=&quot;true&quot; mode=&quot;basic&quot; accept=&quot;image/*&quot; customUpload=&quot;true&quot; (uploadHandler)=&quot;onFileChange($event)&quot; chooseLabel=&quot;Upload here&quot; &gt;&lt;/p-fileUpload&gt;
</code></pre>
<blockquote>
<p>More explanation about PrimeNG FileUpload <a href="https://www.primefaces.org/primeng/#/fileupload">click here</a></p>
</blockquote>
<hr>
<h2 id="thesolution">The Solution</h2>
<p><em><strong>First round</strong></em> <mark>FAILED</mark><br>
I tried to override the style as we normally do, just point the name and write my style.</p>
<p>CSS file</p>
<pre><code class="language-css-extras">    #myAvatar span.ui-button {
        border-color:red;
        background: none;
        color: red ;
        font-family: inherit;
    }
    #myAvatar span.ui-button .ui-button-icon-left {
        display:none !important;
    }
    #myAvatar span.ui-button .ui-button-text {
        padding:.375rem .75rem !important;
    }
</code></pre>
<p>How the component looks after aply my css file.<br>
<img src="https://patriciabarros.azurewebsites.net/content/images/2018/02/primeng-fileupload-failed.png" alt="Angular + PrimeNG: Custom styling PrimeNG components"><br>
As you can see in the image above it didn't work with my css.</p>
<br>
<p><em><strong>Second round</strong></em> <mark>SUCCESS</mark></p>
<blockquote>
<p>After some time spent on the internet and many attempts, I finally came across the final solution <a href="https://stackoverflow.com/questions/46280708/override-primeng-css-classes-in-angular/46280815#46280815">Override primeng css classes in Angular<br>
</a></p>
</blockquote>
<p>Using <code>::ng-deep</code> in front of the style that you created do the magic. Allowing to <em>enter</em> in the component and change the style.</p>
<p>CSS file</p>
<pre><code class="language-css">    ::ng-deep #myAvatar span.ui-button {
        border-color:red;
        background: none;
        color: red ;
        font-family: inherit;
    }
    ::ng-deep #myAvatar span.ui-button .ui-button-icon-left {
        display:none !important;
    }
    ::ng-deep #myAvatar span.ui-button .ui-button-text {
        padding:.375rem .75rem !important;
    }
</code></pre>
<p>An then I finally got my custom component.<br>
<img src="https://patriciabarros.azurewebsites.net/content/images/2018/02/primeng-fileupload-success.png" alt="Angular + PrimeNG: Custom styling PrimeNG components"></p>
<blockquote>
<p>More explanation about shadow DOM style scoping you can find in <a href="https://angular.io/guide/component-styles#deprecated-deep--and-ng-deep">Component Styles</a> or <a href="https://stackoverflow.com/questions/46786986/how-and-where-to-use-ng-deep">How and Where to use ::ng-deep?</a></p>
</blockquote>
<br>
<p>Now it is your turn to change the style of any component as you wish and your project requires.</p>
<p>Hope it helps.</p>
</div>]]></content:encoded></item></channel></rss>