This is a good point and a good question. Yes, as a general rule, both civil and criminal cases in the United States are public. Now that most court documents are filed electronically you can access these documents online. Federal court documents are available through PACER (pacer.gov) and many state courts make documents available online, too.
But obviously some documents shouldn't be shared. For example, parties in a business dispute might not want to disclose trade secrets. Perhaps in a criminal case there is information that if shared publicly could put someone in danger. If a judge agrees, certain information will be redacted and not shared with the public.
When a litigation involves confidential information one or both parties will ask the Court for a "protective order." In a motion for a protective order a party asks the judge to issue an order that will shield confidential information from being shared with other parties and/or the public.
For example, let's say a document contains a business secret. The company could ask the judge for a protective order so the document does not have to be disclosed. Alternatively, the company could ask for a protective order so that the document will be "lawyer's eyes only" - - meaning lawyers may review the documents but it cannot be disclosed to other parties and the public. Judges will not automatically grant a motion for a protective order. The party must provide sufficient grounds to show why it needs the protective order.