How do you write a good opening?
By giving the reader a reason to continue within the first paragraph — which usually means a question, a tension, or a voice worth following, rather than the explanation most first drafts begin with.
The commonest failure is starting too early. Writers begin with weather, waking up, travel, background, or the history required to understand what happens later. The material you needed in order to write the scene is rarely the material the reader needs in order to read it. A reliable diagnostic: delete the first paragraph, or the first page, and check whether anything is lost. Very often the second paragraph is the real opening.
What a strong opening actually does:
Raises a question the reader wants answered. Not a mystery necessarily — an imbalance, an oddity, something unexplained that the reader trusts will be explained.
Establishes voice. A distinctive voice in the first line buys enormous patience; many celebrated openings do nothing else.
Puts someone somewhere doing something, giving the reader a concrete image to hold rather than abstraction.
Signals what kind of thing this is — genre, tone, register — so expectations are set correctly.
Starts close to the change. The reason to begin now rather than a month earlier should be apparent.
What works differently in non-fiction. An opening should establish why this matters and why now, typically through a specific case, a surprising fact, or a stated tension — and then deliver on it. A general throat-clearing introduction is the equivalent of starting with the weather.
Openings that are usually weak: dreams; a character looking in a mirror to describe themselves; extended description before anything happens; a prologue of world history; a rhetorical question to the reader; and a dictionary definition.
Practical process: write the opening last, or expect to rewrite it entirely once you know what the piece became. First drafts need a run-up that finished pieces do not.
The end matters as much. An opening only has to buy the next page; the ending is what determines whether anyone recommends it.