Instructors, teachers, and professors alike have probably told you to avoid sentence fragments. Microsoft Word probably hates you for it too—but, just like anything else, it's okay to use in moderation. The definition of a sentence fragment, by the way, is a sentence that can't stand alone. Most commonly, they're missing subjects or verbs:
Under a rock, just before crawling out.
That's a fragment missing a subject. Who or what is crawling out? Perhaps it should be Under a rock, just before crawling out, the spider laughed maniacally.
What? Spiders laugh. Shut up.
Anyway, here's another example:
Trying very hard not to cry as the spider crawled up his leg.
This one is tricky, because "his" looks like it could be a subject. It's a person (me, if that ever happened) and he's trying to do something, right?
Not quite. This is a modifying verbal phrase, which means it gives more information about the sentence. You could add that fragment onto something like, He flailed at it like an awkward two-armed ceiling fan.
Combine the two, and you get this: Trying very hard not to cry as the spider crawled up his leg, he swatted at it like an awkward two-armed ceiling fan.
By the way, the above sentence makes sense, but try not to start sentences with "-ing" words, because it can keep the reader waiting for too long. Most of the time it's much better to get to the point, then add detail later.
He swatted at the spider like an awkward two-armed ceiling fan, trying very hard not to cry as it crawled up his leg.
Even that one might be too long for my taste. So when can I use sentence fragments?
People speak in fragments all the time. There might be a place for fragments if you're writing dialogue.
Consider something like this:
I can't control when I burst into flames—I guess that's why they call it "spontaneous combustion."
There's nothing wrong with that sentence, and it isn't a fragment. Plenty of people talk like that, many in even longer sentences. But what if you want a more deadpan delivery, or something with a pause? Something a tad more dry? <--see? there's one!
I can't control when I burst into flames—it just happens. Spontaneously.
The word spontaneously, in that instance, is what they call a "stylistic sentence fragment," and authors use them all the time. In order to vary sentence length, pacing, and reflect realistic dialogue, sometimes you have to use a sentence fragment. Or maybe you want to emphasize something, like I did with "something a tad more dry.".
In any case, watch out for fragments in most of your writing, but just know you should never say never. About fragments.