Federer, Djokovic, Nadal, all the top pros slide even on hardcourts WHEN they are going way wide to return an angled shot.
I got into the habit of sliding on hardcourts back in high school too, but it became a huge disadvantage; I began sliding when I had no reason to, sliding on easier shots, etc. especially when my shoes got worn down.
I had to consciously think about NOT sliding for a long time to break the habit. Now I'm back to just sliding on the wide shots
That said, it's all about explosive movement. People start the first step with explosive movement, but in order to slide successfully you also need to kinda lunge into the last shot as well. Obviously you can't slide if you're merely walking, thus the needed force and speed.
The least traction possible also helps sliding, as has been mentioned. This (for me at least) means only one shoe on the ground, and ideally not the entire shoe. When I slide to my forehand, most of my weight is on my toes. For my backhand it's more on the outside of my foot, since my foot is perpendicular to the baseline (backwards, extreme reach to hit a slice or something..)
I would NOT recommend trying/doing this with new shoes. I learned the hard way that new shoes don't slide well, leading to injuries and hurt ankles. Break them in, wear them down a little bit, then go for it CAREFULLY.
And just for clarification, someone above said that sliding means you weren't in position to hit the shot. That's not necessarily true. Sliding is a last second burst to stretch even farther than you normally could. While sliding COULD mean you're being lazy or whatever, for many if not most people that slide correctly, it means that you are going for shots that you would normally have missed.