The answer from Rick isn't wrong but also isn't complete.
There are three kinds of contempt of court:
direct punitive contempt of court (which applies to misconduct in the presence of the judge in the courtroom),
indirect punitive contempt of court (which punishes violation of a court order outside the courtroom), and
indirect remedial contempt of court (which creates an incentive to obey a court order that is currently being disobeyed outside the courtroom, which the person held in contempt has the present power to comply with).
Direct contempt of court is typically a disorderly persons offense in New Jersey, which carries up to 6 months in the county jail and a $1,000 fine. Direct punitive contempt of court is imposed summarily by the presiding judge without a trial other than giving the person punished an opportunity to explain themselves on the spot.
The eighteen month limitation on incarceration for contempt of court applies only to indirect punitive contempt of court, which are criminal offenses with special procedures attached to them, and to violations of restraining orders a.k.a. protection orders, discussed below in the footnote.
Indirect punitive contempt of court is imposed following a process ending with a collateral hearing in the case where it arises, often with the plaintiff in a civil case deputized to serve as a prosecutor for the charges.
Not all states have statutory limitations on punitive contempt of court sanctions that do not involve a protection order violation. In one case in Illinois, a twenty year incarceration sentence was imposed in a direct punitive contempt of court case that was reduced to ten years on appeal, for refusing to testify. See People v. Geiger, 2015 IL App (3d) 130457 (Aprils) & People v. Perez-Gonzalez, 2014 IL App (2d) 120946 (June) (both summarized here).
There is no limitation on the length of incarceration imposed or fine which may be imposed in indirect remedial contempt of court, which is reviewed on appeal for an abuse of discretion. The theory behind this is that the person incarcerated holds the key to their release by complying with the order which can be done at any time. Indirect remedial contempt of court, unlike punitive contempt of court, in compensatory, remedial, and civil in nature, rather than being quasi-criminal or having an object to punish a violator. The goal of remedial contempt is to secure compliance not to punish the person incarcerated.
Typically, indirect remedial contempt of court is used for matters like failure to turn over assets in foreign accounts or password protected crypto that the person sanctioned controls, to force the turnover of cash or valuables at a location only known to the person incarcerated, or to compel someone's testimony on non-privileged matters in a court case or deposition or in response to judgment creditor issued interrogatories demanding that the location of the judgment debtor's assets be revealed.
If someone simply fails to sign a document despite being ordered to do so, remedial contempt of court could be used, but it is more common to have the court involuntarily appoint the court clerk as the agent of the person who refuses to sign for the narrow purpose of signing a particular document or set of documents (e.g. a real estate contract) on behalf of the recalcitrant party.
No fixed term of incarceration or maximum fine is set in a remedial contempt of court order. Incarceration for indirect remedial contempt of court can continue until the matter to be compelled is moot, or until the person incarcerated no longer has the capacity to obey the court order. There are cases of people being incarcerated for indirect remedial contempt of court for more than a decade.
A law review article critical of this practice can be found here.
The longest case of incarceration for remedial contempt of court is described by Wikipedia as follows:
H. Beatty Chadwick (born 1936) is the current American record holder
for the longest time being held in civil contempt of court. In
1995, a judge ruled that Chadwick hid millions of U.S. dollars in
overseas bank accounts so that he would not have to pay the sums to
his ex-wife during their divorce. He was incarcerated until such
time as he could present $2.5 million to the Delaware County Court in
Pennsylvania. Chadwick maintains that the money was lost in bad
investments and therefore he cannot surrender money he does not
possess. Although never charged with a crime, H. Beatty Chadwick spent
fourteen years of his life in prison.
On July 10, 2009, Chadwick was ordered released from prison by
Delaware County Judge Joseph Cronin, who determined his continued
incarceration had lost its coercive effect and would not result in him
surrendering the money.
See also this news report on the same case. Legal commentary on that case can be found here.
Footnote Re Protection Orders
Most if not all states issue protection orders typically ordering someone who has harassed, stalked, or threatened violence against someone to stay away from one or more persons or places, often in a domestic violence or toxic fan situation.
These orders, unlike almost all other civil court orders, can be enforced directly by law enforcement without a contempt of court process, and it is a crime other than contempt of court to violate such an order. In the case of all other civil court orders for injunctive relief, contempt of court is the only or primary remedy.