In order to establish trust in the system among the subjects of international law, there should be general principles that everyone should follow. The similarities and differences between the jus cogens and the erga omnes doctrine have not yet been concluded in the theory and practice of international law. Both are elements of the public order concept aimed at maintaining the basic order of the international community but it can be said that they are different from each other in terms of sanctions.
The principle of jus cogens are the general interests of the international community rather than the individual interests of states, the global common good, important for international peace and order, have a moral basis and are generally accepted by the international community. As Hernandez mentioned ‘ The ILC was one of the first institutions to use the term jus cogens, which it introduced in its Draft Articles on the Law of Treaties to be considered by States at the Vienna Conference on the Law of Treaties in 1968’.  Obligations erga omnes is the rules that states are obliged to comply with. It is especially applied on human rights.
In the Barcelona Traction Case, the Court mentioned for the first time obligations erga omnes.  The court said that the fundamental rights of human beings give rise to the erga omnes obligation.
Differences between 2 categories
In jus cogens, norms that cannot be contracted otherwise are dealt with. For instance; the slave trade, piracy, genocide and acts contrary to the sovereign equality of statesshould be evaluated within this scope. There is an opinion that in the case of a jus cogens breach, for instance, the violation of prohibition of use of force that is included in the United Nations Treaty, other states will react and try to prevent this situation. However, in breach of the erga omnes obligation, it is accepted that the reaction may be less severe than jus cogens. Another difference is that in erga omnes, a legal action may have consequences not only for those concerned however against everyone, while jus cogens may not produce results for everyone.
As Hernaindez mentioned, jus cogens creates a ‘broader concept’, while erga omnes is a ‘narrow concept’. According to erga omnes, any state has the right to complain for a breaching of the rule. For example; a country does not have to be directly or indirectly involved in the genocide case in order to file a complaint.
Although these two concepts are related, to summarize, it can be said that jus cogens rules consist of rules stipulating erga omnes obligations, but erga omnes obligations will not constitute jus cogens in all cases.
1 Gleider Hernandez, International Law, Oxford University Press, 60.
 ICJ Reports 1970, p.2, para 33. See also Christian Tomuschat and Jean-Marc Thouvenin (Eds.), The Fundamental Rules of The International Legal Order, Jus Cogens and Obligations Emga Omnes, Martinus Nijhoff Publishers (Leiden/Boston) ,p.22
ALEXIDZE, Levan (1981), "Legal Nature of Jus Cogens," Recueil des Cours de l'Academie de Droit International, iii: 223-270.
Barcelona Traction, Light and Power Company, Limited (Belgium vs. Spain) (New Application: 1962) (https://www.icj-cij.org/en/case/50/judgments)
Christian Tomuschat and Jean-Marc Thouvenin (Eds.), The Fundamental Rules of The International Legal Order, Jus Cogens and Obligations Emga Omnes, Martinus Nijhoff Publishers (Leiden/Boston)
Erika de Wet. (2013) Jus Cogens and Obligations Erga Omnes. The Oxford Handbook of International Human Rights Law. Ed. By Dinah Shelton.
Gleider Hernández. (2019). International Law. Oxford, United Kingdom. Oxford University Press.
The Concept of the Common Heritage of Mankind in International Law (London: Martinus Nijhoff Publishers).
James Crawford. (2019). Brownlie’s Principles of Public International Law (9th ed). Oxford, United Kingdom. Oxford University Press.