Showing results for 
Search instead for 
Did you mean: 
Post Prodigy
Post Prodigy

Gallery - random background colors on each row?

I have a gallery

How can i make it so a icon or button have a random background color?

Each row/record in the gallery have a icon.

I want that icons background color (fill) to randomize color based on a set of colors i define.


Continued Contributor
Continued Contributor

Hi @Oskarkuus , there are many ways this could be done but you could add a color column to data source or your collection that is being used to display the items. The colors can be "randomized" by the values you provide. Then the button's fill can be changed by doing ThisItem.Color.


Mark this post as a solution, or kudo it if you found it be helpful. You can choose more than multiple answers as solutions, including your own answer. 🙂

Not applicable

here is the script


RGBA(256*Rand(), 256*Rand(), 256*Rand(), 1)


And here is an image


I hope this answers your question.

Well i have a bit of a problem changing the datasource with my app.

But i rather do the collection part.


My gallery is displayed from the datasource.

Can i create a collection (colColor) onStart and populate that with 20 colors in a column called color?


But how to use that collection in the gallery?

How to make each row in the gallery pick a random color value from the collection?

Not applicable


Continued Contributor
Continued Contributor

The answer @Anonymous  provided is very clever, but you would get a different color every time and you won't be able to predefine it. The only way I know how to make it predefined is to create a color collection with 2 columns - index and color. And then I would add an index column to the collection that is the source of the gallery. I did this in another post that is very similar to this. Look at both of my responses to this post.


If you want me to edit those answers and provide you a solution here you would have to provide me

  1. Source for the gallery,
  2. How many rows there,
  3. What colors you want to use,
  4. And what happens if there are more rows than colors.


My answer above deals with that by looping through the colors.


Mark this post as a solution, or kudo it if you found it be helpful. You can choose more than multiple answers as solutions, including your own answer. 🙂

Helpful resources

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.


New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (2,208)