Loyalty is a Hufflepuff trait, but it’s a quality shown by characters from every house. And while it could just be that few people are all one house with no traits from any other, I’ve noticed that characters from different houses tend to be loyal in different ways. Of course, like anything else, this can depend on the person as much as the house, but in general …
Gryffindors are loyal to a cause. With every other house, their loyalty can conflict with what they see as right or wrong, but with Gryffindor, the first thing they’re loyal to is the cause they believe in. Gryffindors can have more tangible loyalties, just like anyone else, but when it comes down to it, they’re going form relationships with people who share their beliefs and do what they think is right if they have to choose. Look at Lily, and the way she cut Snape off when she realized their values were no longer compatible. Look at the Gryffindor members of the DA and the Order, whose first loyalty is to the fight against Voldemort even before the group itself. Now, does that mean Gryffindors are always right? No. It’s totally possible to have your priorities wrong and pick the wrong cause to back. That’s Percy Weasley’s problem. But overall, they’re going to put their cause before their other loyalties.
Hufflepuffs are loyal to a group. Hufflepuffs are loyal in general – they’re the only house who have loyalty as an actual defining trait of their house. But, I think, Hufflepuff loyalty is to a group or community first and foremost: their house, their school, their secret anti-Voldemort organization, etc. J.K. Rowling has said that the Hufflepuffs who stayed to fight in the Battle of Hogwarts did so for different reasons than the Gryffindors. Rather than wanting heroism, glory, or adventure, they were driven by loyalty to their school, the DA, and the side of good in general. Hufflepuff loyalty at its worst could lead to conformity, groupthink, and accepting misguided ideas without a second thought, but at its best looks like a supportive, tight-knit community.
Slytherins are loyal to people. They’re not incapable of loyalty, but their allegiances shift based on their own best interests and those of their loved ones. However, the love and loyalty of a Slytherin, once won, is strong and not easily shaken. Bellatrix Lestrange is loyal to Voldemort. Snape is loyal to Lily. The Malfoys are loyal to each other. Pottermore says that Slytherins “look after [their] own”, and I would agree. While this fierce interpersonal loyalty may often seem selfish and even cruel – the rest of the world can burn as long as those they love are safe – it doesn’t have to be. Scorpius from Cursed Child is loyal to his parents, Albus, and to some extent Rose before anyone else, but doesn’t lose sight of right and wrong. On the opposite end of the spectrum, Voldemort is loyal only to himself and has no moral compass.
Ravenclaws are loyal to ideas. That might sound odd, but just think about Luna. She’s fanatical about her nargles, wrackspurts, and conspiracy theories, and refuses to back down even when she’s laughed at. She joins Dumbledore’s Army because she believes the Ministry is lying, while other students might have done so to honor Cedric’s memory, to protest Umbridge, etc. Ollivander, another Ravenclaw, is utterly devoted to wandlore, which he has made his life’s work. Harry is not entirely sure he likes Ollivander, who takes a calm, intellectual view of the worst things his wands have gone on to do. At its worst extreme, this could lead to completely ignoring ethics. But on the other hand, Ravenclaws can look almost Gryffindor when their ideas relate to moral issues, such as Ministry corruption and the fight against Voldemort.
Does that mean that Gryffindors and Ravenclaws can’t have people they’d do anything for? Or that Hufflepuffs and Slytherins can’t have a belief or a cause they adhere to? Of course not. But for most characters, in general, loyalty does take on a different form based on which house they’re in.