Skip to main content

Notifications

Community site session details

Community site session details

Session Id : R/oy7yFUGksLQ90vlnMz1x
Power Automate - Building Flows
Answered

Issue with Applying CSS to Specific Column Headers in HTML Tabl

Like (0) ShareShare
ReportReport
Posted on 7 Apr 2025 10:18:27 by 12
Hello Everyone,
I'm a new member of this community and I'm excited to learn and share knowledge with all the experts here. I have a question regarding applying CSS to specific column headers in HTML tables generated by Power Automate. Despite trying various methods and resources, I haven't been able to achieve the desired output. Below is a detailed description of my flow and the issue I'm facing.
Description:
I am trying to format specific column headers in an HTML table generated by Power Automate. My goal is to change the background color of headers containing "***SUPPLIER INPUT |" to green with black font. Despite following various steps, the output does not reflect the desired changes.
Steps Taken:
  1. Manually Trigger a Flow: Start the flow manually.
  2. Get File Content from SharePoint: Retrieve the file content.
  3. List Rows Present in a Table: List rows from an Excel table.
  4. Filter Array: Filter rows where Supplier Response Status is 'Pending Response'.
  5. Filter Array: Further filter rows where MOQ Response Status is 'For RPA Send Out'.
  6. Select Action: Map data and modify column names.
//Comment Only
{
  "Column A": "@item()?['####']",
  "Column B": "@item()?['####']",
  "Column C": "@item()?['####']",
  "Column D": "@item()?['####']",
  "Column E": "@item()?['####']",
  "Column F": "@item()?['####']",
  "**SUPPLIER INPUT | ColumnNameA": "#######",
  "Column H": "@item()?['####']",
  "Column I": "@item()?['####']",
  "Column J": "@item()?['####]",
  "Column K": "@item()?['####']",
  "**SUPPLIER INPUT | ColumnNameB": "#######",
  "**SUPPLIER INPUT | ColumnNameC": "#######",
  "**SUPPLIER INPUT | ColumnNameD": "#######"
}
  1. Create HTML Table: Use the output of the Select action and set columns to automatic.
  2. Compose CSS: Add CSS to modify column headers.

//Comment Only
  table {
    font-family: Arial, Helvetica, sans-serif;
    border-collapse: collapse;
    width: 100%;
  }
  table th {
    background-color: black;
    color: white;
  }
  table th:nth-child(7),  /* **SUPPLIER INPUT | Column HeaderNameA */
  table th:nth-child(12), /* **SUPPLIER INPUT | Column HeaderNameB */
  table th:nth-child(13), /* **SUPPLIER INPUT | Column HeaderNameC*/
  table th:nth-child(14)  /* **SUPPLIER INPUT | Column HeaderNameD */ {
    background-color: green;
    color: black;
  }
  1. Combine HTML and CSS: Combine the HTML table output with the CSS styling.
//Comment Only
    @{outputs('Compose_CSS')}
    @{outputs('Create_HTML_Table')}
  1. Send Email: Send the formatted HTML table via email.

//Comment Only
       @{outputs('Compose_HTML_and_CSS')}

Issue:
The specific column headers with "***SUPPLIER INPUT |" are not displaying the green background and black font as expected. The CSS does not seem to be applied correctly. I have tried various resources and methods, but none have worked so far.
Request:
Could you please help me identify what might be going wrong and how to correctly apply the CSS to these specific column headers?
Thank you in advance for your assistance!

My Flow Sample Output: (All column headers BG are black)
 
 
Expected Output:
 
 
  • Verified answer
    rzaneti Profile Picture
    3,972 Super User 2025 Season 1 on 09 Apr 2025 at 11:54:06
    Issue with Applying CSS to Specific Column Headers in HTML Tabl
    Hi @Chooloo,
     
    Glad to hear that it worked for one column! I ran some tests from here and, although it is possible to implement this logic to multiple columns with a series of Composes, the flow becomes confusing and can lead to some errors. I made a few changes to try to keep it simpler, please check if it works for you.
     
    I'm first adding an extra property to our sample data:
     
    Then, right after the Create HTML table action, I'm initializing a variable of type string and passing the HTML table as input:
     
    Then I'm creating a compose to store an array containing the name of the columns that you want to style. In my case, it is just name, age and department. You can also see the flow structure so far on the right:
     
     
     
    Next, we will loop our compose that contains the array of headers with an Apply to each:
     
     
    Inside the Apply to each, there are two Composes: one for storing the original tag, and other for the styled tag. The content of these composes looks like this, where we're passing the header's name as dynamic content corresponding to the Current item property from Apply to each. As a result, for each iteration of the loop, these tags will be populated with the respective column header: 
     
     
    Then we have one more Compose, at this time to apply the replace function, just like we did for the single column. Instead of passing the Create HTML table output as first argument, pass the variable (in red). For the second argument, instead of hardcoding it, use the original tag Compose (in blue). For the third one, you can use the styled tag Compose, similarly to what we did for the single column (in green):    
     
     
     
     
    As a last step inside the loop, assign the value of this "replace compose" to the table's variable:
     
    Finally, use the table's variable (and not the Create HTML table output) in your email body:
     
    This is the final output:
     
     
    Let me know if it works for you or if you need any additional help!
     
    If this is the answer to your question, please mark the post as Accepted Answer.
    If this answer helps you in any way, please give it a like.

    Check more Power Platform content on my website.
    Lets connect on LinkedIn.
     
     
     
  • Chooloo Profile Picture
    12 on 09 Apr 2025 at 07:36:28
    Issue with Applying CSS to Specific Column Headers in HTML Tabl
    Hello,
     
    I really appreciated how detailed you provide response on my question. I follow the actions below, and it works. But when I tried to modify more than 2 columns bg it doesn't work. Since on my project requirements I have 14 columns with each unique bg color. I created a Compose action where I set a th tags and assigned its class for my columns.
     
    1.) Create a compose action to assigned class and th tags for my 14 columns.
     
    <th class="highlight-header">Org</th>
    <th class="highlight-header1">Material</th>
    <th class="highlight-header2">Description</th>
    <th class="highlight-header3">UOM</th>
    and soon...
     
    2.) I use another compose action to replace all my columns, but it seems unsupported of using multiple replace expression in one compose action. This is how I write them. 
     
    replace(
        replace(
            replace(
                replace(
                    replace(
                        replace(
                            replace(
                                replace(
                                    replace(
                                        replace(
                                            replace(
                                                replace(
                                                    replace(
                                                        replace(
                                                            body('Create_HTML_Table'), 
                                                            '<th>Org</th>', 
                                                            '<th class="highlight-header">Org</th>'
                                                        ), 
                                                        '<th>Material</th>', 
                                                        '<th class="highlight-header1">Material</th>'
                                                    ),
                                                    '<th>Description</th>', 
                                                    '<th class="highlight-header2">Description</th>'
                                                ),
                                                '<th>UOM</th>', 
                                                '<th class="highlight-header3">UOM</th>'
                                            ),
                                            '<th>Supplier Name</th>', 
                                            '<th class="highlight-header4">Supplier Name</th>'
                                        ),
                                        '<th>Lot Size</th>', 
                                        '<th class="highlight-header5">Lot Size</th>'
                                    ),
                                    '<th>Correct Lot Size</th>', 
                                    '<th class="highlight-header6">Correct Lot Size</th>'
                                ),
                                '<th>Current Minimum Order Quantity</th>', 
                                '<th class="highlight-header7">Current Minimum Order Quantity</th>'
                            ),
                            '<th>Delivery Frequency</th>', 
                            '<th class="highlight-header8">Delivery Frequency</th>'
                        ),
                        '<th>Daily Usage</th>', 
                        '<th class="highlight-header9">Daily Usage</th>'
                    ),
                    '<th>Ideal Order Quantities</th>', 
                    '<th class="highlight-header10">Ideal Order Quantities</th>'
                ),
                '<th>Can you meet our Ideal Order Quantities? (Yes/No)</th>', 
                '<th class="highlight-header11">Can you meet our Ideal Order Quantities? (Yes/No)</th>'
            ),
            '<th>If No - Indicate reduce Order Quantities (NEW MOQ)</th>', 
            '<th class="highlight-header12">If No - Indicate reduce Order Quantities (NEW MOQ)</th>'
        ),
        '<th>Feedback on Vertiv's Order Quantity Options</th>', 
        '<th class="highlight-header13">Feedback on Order Quantity Options</th>'
    )
     
    3.) I tried breaking down also into multiple compose action each column. And create another compose action where I concatenate each compose actions outputs, but it creates 2 column headers, but it did highlight my column bg but different format only. 
     
     
    Can someone help me review what could be my options to do my expected output? 
  • Chriddle Profile Picture
    7,687 Super User 2025 Season 1 on 07 Apr 2025 at 11:59:02
    Issue with Applying CSS to Specific Column Headers in HTML Tabl
    This should work in a browser, but hardly any email client supports CSS nth-child.
     
    You could use PA's function nthIndexOf to find the position of the <th> and replace it with e.g. <th class="highlight">.
    And, of course, adjust the CSS accordingly.
     
  • Verified answer
    rzaneti Profile Picture
    3,972 Super User 2025 Season 1 on 07 Apr 2025 at 11:54:06
    Issue with Applying CSS to Specific Column Headers in HTML Tabl
     
    I ran some tests from my end and it looks like the nth-child doesn't work for styling the email HTML content: there are a few threads complaining about it on Reddit and Stack Overflow. 
     
    However, I think I found a workaround for your specific use case :)
     
    The style works fine if you assign a class to the HTML tag, and considering that Create HTML table action retrieves a string (an HTML code), we can use a replace function to switch the default column header for one with a class. 
     
    For this example, I'm working with this HTML table and I want to change the background color of the "name" column:
     
    After creating the HTML table, I add a compose with my styled tag (in green), which basically repeats the th tag, but with the class assigned to it. In a second compose (in yellow), I'm adding a replace function to access the Create HTML table output (in blue), take the <th>name</th> text (in red) and replace it for the styled tag (in green): 
     
     
     
    You can improve this logic to pull the column's name dynamically if needed. Finally, in the email action I'm simply adding the CSS at the top, in the style section, and passing the dynamic content of my Compose with the styled table instead of the Create HTML table itself: 
     
     
    After running the flow, this is the new output:
     
    Let me know if it works for you or if you need any additional help!
     
    If this is the answer to your question, please mark the post as Accepted Answer.
    If this answer helps you in any way, please give it a like.

    Check more Power Platform content on my website.
    Lets connect on LinkedIn.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Building Flows

Overall leaderboard
Loading started