Opinio juris sive necessitatis ("an opinion of law or necessity") or simply opinio juris ("an opinion of law") is the belief that an action was carried out as a legal obligation. This is in contrast to an action resulting from cognitive reaction or behaviors habitual to an individual. This term is frequently used in legal proceedings such as a defense for a case.
Opinio juris is the subjective element of custom as a source of law, both domestic and international, as it refers to beliefs. The other element is state practice, which is more objective as it is readily discernible. To qualify as state practice, the acts must be consistent and general international practice.
A situation where opinio juris would be feasible is a case concerning self-defense. A condition must be met where the usage of force is limited to the situation at hand. The act of striking an attacker may be done with legal justification; however, legal territory limits the acceptability of such a claim. Even in this case, the usage of force must be acceptable to the conditions of the environment, the attacker, and the physical conditions of the people involved, as well as any weapons or tools used.
In international law, opinio juris is the subjective element used to judge whether the practice of a state is due to a belief that it is legally obliged to do a particular act. When opinio juris exists and is consistent with nearly all state practice, customary international law emerges. Opinio juris essentially means that states must act in compliance with the norm not merely out of convenience, habit, coincidence, or political expediency, but rather out of a sense of legal obligation.  Article 38(1)(b) of the Statute of the International Court of Justice accepts "international custom" as a source of law, but only where this custom is 1) "evidence of a general practice," (the objective component) (2) "accepted as law." (the opinio juris or subjective component) Thus, for example, while it may be observed that heads of state virtually always shake hands when they first meet, it is highly unlikely that they do so because they believe that a rule of international law requires it. On the other hand, a state would almost certainly expect some form of legal repercussions if it were to prosecute a foreign ambassador without the consent of his or her home state, and in this sense opinio juris does exist for the international law rule of diplomatic immunity.
Because opinio juris refers to the psychological state of the state actor--asking why the state behaved as it did--it can be difficult to identify and to prove. In practice, a variety of sources tend to be used to demonstrate the existence of opinio juris, including evidence such as diplomatic correspondence, press releases and other government statements of policy, opinions of legal advisers, official manuals on legal questions, legislation, national and international judicial decisions, legal briefs endorsed by the state, a pattern of treaties ratified by the state that all include the same obligation(s), resolutions and declarations by the United Nations, and other sources. In the Paquete Habana case (decided by the United States Supreme Court in 1900 on the question of whether small coastal fishing boats are immune from capture during wartime under customary international law), evidence of opinio juris included medieval English royal ordinances, agreements between European nations, orders issued to the U.S. Navy in earlier conflicts, and the opinions of legal treatise writers. Finally, the context, circumstances, and manner in which the state practice is carried out can also be used to infer the existence of opinio juris. As the ICJ stated in the North Sea Continental Shelf cases of 1969, "Not only must the acts concerned amount to a settled practice, but they must also be such, or be carried out in such a way, as to be evidence of a belief that this practice is rendered obligatory by the existence of a rule of law requiring it." Nonetheless, a state's motives can change over time, and that it is not necessary that opinio juris be a significant impetus for each instance of action. As Judge Lachs wrote in a dissenting opinion in the North Sea Continental Shelf cases, "At successive stages in the development of the [customary] rule the motives which have prompted States to accept it have varied from case to case. It could not be otherwise. At all events, to postulate that all States, even those which initiate a given practice, believe themselves to be acting under a legal obligation is to resort to a fiction, and in fact to deny the possibility of developing such rules."
As difficult as it can be to prove why an actor did act in a certain way, it is exponentially more difficult to prove why it did not act. For this reason, the necessity of demonstrating that a behavior was prompted by a sense of legal obligation makes it particularly difficult for customary international law to develop around the prohibition of a practice. One important case in the development of modern customary international law theory is the Lotus case, in which France attempted to protest Turkey's assertion of criminal jurisdiction over a French citizen for acts committed on the high seas (outside of Turkey's territory). France presented a number of historical examples to demonstrate that the state of nationality or the state whose flag the ship had flown had exclusive jurisdiction in cases such as this. However, the Permanent Court of International Justice (a precursor to the ICJ) declared that the evidence showed merely that "States had often, in practice, abstained from instituting criminal proceedings, and not that they recognized themselves as being obliged to do so; for only if such abstention were based on their being conscious of having a duty to abstain would it be possible to speak of an international custom." This reasoning was cited approvingly in the North Sea Continental Shelf cases, which similarly declined to find the existence of customary law regarding the proper method to delimit territorial claims to the continental shelf extending from the coastline of states bordering the North Sea. The ICJ also declined to find evidence of customary international law in an opinion on the legality of the use or threat of nuclear weapons, despite what some argued to be uniform state practice. As in the North Sea Continental Shelf cases, it found that the mere fact that no state had used nuclear weapons against another state since World War II did not reflect opinio juris. Some states had pointed out that a series of U.N. resolutions had been issued "that deal with nuclear weapons and that affirm, with consistent regularity, the illegality of nuclear weapons," and argued that this signified "the existence of a rule of international customary law which prohibits recourse to those weapons." Nonetheless, the ICJ wrote that states possessing nuclear weapons had almost always objected to these resolutions, which strongly suggests that those states did not believe that a customary law prohibiting their use existed. Moreover, it wrote that the non-use of nuclear weapons could actually provide evidence of their "use" as a deterrent force.
This logical framework makes sense for existing norms of customary international law, but it becomes problematic in the context of new or emerging customary rules. If a practice is not currently governed by customary international law, then it is illogical to inquire into a state's beliefs about the legality of engaging in or abstaining from that practice, i.e., to ask whether it believed that its practice was in compliance with a law that does not yet exist. This paradox may be resolved to some extent by the idea of "crystallization" of customary international law, in which practice and legal obligation evolve jointly and eventually ripen into law. Under one model, this process occurs in three stages: first, some States engage in a given practice for reasons other than a sense of legal obligation (e.g. political expediency, economic gain, courtesy, etc.); next, States reinforce the practice by engaging in it or making claims based upon it, creating loops of reciprocity and reliance based on expectations that the practice will continue; finally, as these relationships expand in number and complexity, they eventually harden into a general rule. In this final stage, as more States become aware of the conduct and actively participate or at least passively acquiesce to the practice, the States' actions begin to be undergirded by a belief that they are complying with an emerging customary rule.