These stars form massive clouds of dust and gas in space.
Gravity pulls the dust and gas together.
As the mass falls together, it gets hot. A star is formed when it is hot enough for a nuclear reaction to start. The hydrogen nuclei fuses together to make helium. When that happens, it releases energy which keeps the core of a star hot.
During this stable phase in the life of a star, the force of gravity holding the star together is balanced by the high pressure due to the high temperatures. Our sun is at this stable phase in its life.