Alignment was once a core Dungeons & Dragons mechanic, but it's now reserved for flavor text and Internet memes. One of the most recognizable parts of Dungeons & Dragons is the game's alignment system, which serves as a way to quickly categorize a character's moral beliefs. While D&D's alignment system has changed over the years, its most popular form is a 3x3 chart that defines characters and monsters as belonging to one of nine categories. A player can have either a good, neutral, or evil morality, and they can have either lawful, neutral, or chaotic ethical beliefs. When creating a character or roleplaying as an NPC, a player chooses one morality system and one ethical belief (such as Chaotic Neutral, or Lawful Good) to provide a foundation for how that character views the world and makes their choices. The system was a fundamental part of the earliest versions of the game, providing both a foundation for roleplaying as a character and giving the players certain mechanical effects. However, as the game's views on morality and ethics shifted and Dungeons & Dragons moved away from placing restrictions on players based on their character's morality, the alignment system has become mostly a vestige of the past.
Earlier versions of Dungeons & Dragons used the alignment system as a mechanic to help DMs maintain their world and to keep players from acting "out of character." Not only could a DM penalize a player for committing an act that they deemed was outside their alignment, there were also spells that affected characters of certain alignments differently. For instance, Protection From Evil in older editions specifically protected its caster from evil creatures only, while players could only be a monk if they had a lawful alignment. If a player committed an action that was outside of their alignment, they could be punished by losing a level or having to earn twice as much XP to level up.
While there were mechanical benefits to the alignment system, it also forced players to conform to certain behaviors, especially as defined by their DM. For instance, a paladin could only be Lawful Good, which meant that players couldn't be a Paladin for an evil deity. Although the alignment system wasn't meant to force players into certain lanes, it ended up promoting a very specific kind of fantasy world, one where there was little room for nuanced characters or moral debate. Players were expected to act a certain way because of their alignment, and a character's worldview couldn't grow and change as they played through a campaign. Alignment played a role in pushing the idea that certain races had to act a certain way, which pushed the problematic concept of monolithic cultures.
Dungeons & Dragons de-emphasized the importance of alignment in Fourth Edition, and now it's all but gone in Fifth Edition. While every monster and NPC statblock still lists the alignment of the character, there are now no rules that limit certain classes to characters of a specific alignment, or spells that impact characters differently depending on whether they are Chaotic Good or Chaotic Evil. More importantly, alignment no longer limits players to how their character can act, or pushes the idea that all creatures of the same race of species always acts the same way. The current Player's Handbook notes that "few people are perfectly and consistently faithful to the precepts of their alignment" and that even two players within the same alignment may have totally different behaviors. Although there are a handful of magic items that still require a certain alignment to use, even these are more exceptions than any real rule.
Although alignment no longer has any mechanical role in Dungeons & Dragons, it's still a useful tool for new players dipping their toes into roleplay for their first time. The alignment system now provides a broad guideline to how certain characters see the world and acts a starting point instead of a fence to limit certain behaviors. It's now a tool instead of a mechanical ruleset, which allows for different kinds of stories and a wider variety of worlds to appear at the D&D table.