Rarity

Rarity is a statistic applied to items, blocks and advancements to signify their value and ease in obtaining. It has no effect on gameplay whatsoever.

The only way to change an item's rarity is to enchant it, which brings its rarity from Common or Uncommon to Rare, or from Rare to Epic.

Displaying
Rarity is intended to display anywhere the item name does.

$$ it is shown in the following situations:
 * Item tooltips in the inventory
 * Item tooltips above the hotbar
 * Successful executions of

$$ rarity colors do not display in the following cases:
 * Item tooltips from an item frame
 * Contents tooltips from a shulker box
 * Item tooltips in the statistics screen
 * The CanPlaceOn/CanBreak tags of an item
 * Item names in the Superflat customization screen

While the ominous banner $$ displays its name in gold for the first two cases above, that is not related to rarity. Items with NBT data cannot be specified for the last three cases.