This is the kind of question, “How do we get to Mars?” that normally would take a lot of discussion and involve a whole lot of mathematics.
I’m going to try to explain it simply and to the best of my limited ability.
Mars is in orbit around the sun. Earth is in orbit around the sun. Earth, being closer to the sun, orbits faster. Mars orbits more slowly. So you have to wait until the two planets are lined up to launch, which happens about every 2 years or so. But it’s not a straight shot out to Mars. Everything works following the rules of orbital mechanics.
Essentially, we launch a spacecraft from Earth into a highly elliptical orbit around the sun. This orbit is so elliptical, that it extends all the way out to the orbit of Mars. You time it so just as this spacecraft reaches it’s farthest point from Earth before beginning it’s return journey, Mars comes along in it’s orbit. The spacecraft meets up with Mars.

The image above from the Jet Propulsion Laboratory website of NASA illustrates how this transfer of an elliptical orbit from Earth catches up to Mars. This process takes about 9 months for a spacecraft like this to reach Mars, and can be accomplished only about once every 2 years.