Kind of a sandwich approach. Flavor first in the broadest sense, like “I want to make a pirate adventure” or “I want a one-shot set in a sewer,” or “this encounter needs to introduce the werewolf theme of this adventure.”
Then, tinker with the mechanics until the math works, since that’s the part that needs the most direct attention.
Then, given whatever mechanics I’ve come up with, go back to the aesthetics and flavor and figure out how it works. If I decided an enemy is ranged, how does it fight at range? Is it magical, or throwing things, or has a weapon?
I usually find some mechanic I want to experiment with or explore then build everything around it. Like finding a feat that sounds cool, or a subclass ability that would be fun to try. I find it difficult to pay attention if I'm playing something simple where I just walk up and hit things with the same attack time and time again, no matter how much I like roleplaying the character. But if I find a cool ability I'll always be looking for new ways to use it and be a more active player in the game.
Plus it gives me a good place to start fleshing out the flavour by justifying why they would have that ability and what it would look like.
I tend to think of a class that might fit the game I want to play, usually magic user, or a subclass that sound afun, so guess mechanics first. Then It used to be that I would choose race to fit that mechanically, but with the relax of the ability score 2,1 I then move on to back story. What sort of story do I want to tell I then pick a race and background to fit what sort background and personality I want my charecter to have. I find the background shapes the now, so are they shy due to past treatment or are they extrovert hero that travels with tales of daring do????
Most of the time I pick my class/subclass first then determine what kind of person/backstory would lead to those skills. But occasionally I'll get the odd inspiration for a character that would naturally lead to a specific class.
Sometimes I've looked at some rules interaction that looks fun, then build a character around that.
Other times I have a concept for a certain type of character (aesthetics, personality and/or archetype) and from there look for mechanics that can help realise that vision.
Yet other times I have a backstory in mind and that story and the setting drives the game mechanics choices.
When I roll up a character for a game with a starting situation I have little influence over I start with what narrative impact I want to do. From what I know of the campaign whete I want to drive it. After that how I want to accomplish that, very much including things such as party role/niche and class. Backstory is generally something that comes last when I try and figure out why the character wants to do those things.
When I do have influence over the starting situation mechanical considerations comes earlier. I can mold the campain to a character idea rather than fitting a character into a campaign.
It really depends. Sometimes I'll think "I wanna play x class this time." Sometimes I'll think "Here's a vague idea for a character, now what class would that be?" I think I usually do the first, but sometimes the second is fun and leads to interesting places.
Backstory first, but sometimes when getting down to the nitty gritty of the numbers I get inspired by choices I have to make there and will adjust the backstory to fit the stats.