Inequality is a ubiquitous phenomenon in real-world society. This investigation aims to study inequality in prisoner dilemma. Individuals contribute to a public pool and act either fairly or unfairly to share the public resource. The participator can either accept the allocation scheme to get a payoff that is better than nothing, or reject it to punish inequality. In the case of discrete strategies, we find that both extreme inequality and fairness fail to optimize the spreading of cooperator, a moderate unfairness best favors the evolution of cooperation under the effects of cyclic dominance. In the case of continuous strategies, it is found that the population evolves into a less unfair state particularly for the coexistence of two strategies, and cooperators prevail by acting fairer than defectors in a spontaneous manner. Our work reveals that inequality impacts the evolution of cooperation significantly and highlights the importance of fairness and unfairness in enhancing the evolution of cooperation.