Elgar made 113 and Markram hit 143 as South Africa piled up 428 for three at the close in Bloemfontein.
Hashim Amla was unbeaten on 89 and in sight of his second century of the series, while South African captain Faf du Plessis was on 62 not out.
Markram's maiden century came in his second Test, eight days after he was run out for 97 in his debut innings during the first Test in Potchefstroom.
It was almost an action replay of the first day of the first Test.
Bangladesh captain Mushfiqur Rahim won the toss and sent South Africa in, only for his bowlers to be put to the sword in a massive opening partnership.
The only major difference was that Bangladesh reshuffled their bowling attack, retaining only Mustafizur Rahman of their front-line bowlers.
The replacements made no significant improvement on those who had played in Potchefstroom.
Although the pitch had more pace and bounce than in the previous match, it only contributed to a faster scoring rate as the ball came on to the bat better.
Elgar and Markram's partnership of 243 exceeded the 196 they put on to set up South Africa's 333-run win in the opening match.
Elgar followed up his 199 in Potchefstroom with his tenth Test century.
He made his runs off 152 balls, with 17 fours. When he reached 16 he became the first batsman in the world to score 1000 runs in 2017.
Neither batsman gave a chance until Elgar, on 110, gloved an attempted hook off Mustafizur and wicketkeeper Liton Das leapt high and got the tips of his right glove to the ball but could not hold on.
Ironically Mustafizur was replaced by Subashis Roy and when Elgar hooked again, Mustafizur ran in from fine leg to take a fine diving catch for Bangladesh's only success before tea.
There was a brief lull after tea when Mustafizur and Roy picked up a wicket apiece and kept the scoring under control while Amla and Du Plessis were playing themselves in.
It didn't last long and the pair posted a century partnership off only 111 balls.
It was a day when virtually nothing went right for Bangladesh. After a fruitless morning they went back to their dressing room to find their halal food was still on the way. The resumption of play was delayed by ten minutes to enable them to eat.