You are describing what is known as a Forced Restart.
Quickly press and release the Up button
Quickly press and release the Down button
Hold the Side button for 20-30 seconds while you ignore the slider and anything else until the Apple logo appears in the center of the screen
Then.....release the Side button to let the iPhone restart
A Forced Restart will always work.....unless......the phone has hardware problem.
In that case, the only option is to make an appointment at the Apple Store or take the phone to an authorized Apple service shop.
You can find a list of authorized shops in your area using this link: Find Locations