Example: The opposite of white is black.
Example: White is the opposite of black.
You use "the opposite of" to tell us what the opposite of something is.
You us "opposite to" a little differently.
Example: The effect was opposite to the effect they wanted.
It's hard to explain the exact difference. When you use it this way, it's more like something that contradicts something else.