In June 2017, he was named in South Africa's Test squad for their series against England, but did not play. In August 2017, he was named as captain of the South Africa A cricket team for their two four-day matches against India A. In September 2017, he was named in South Africa's Test squad for their series against Bangladesh. He made his Test debut for South Africa against Bangladesh on 28 September 2017.
Record breaking start
After narrowly missing out on a maiden Test century on debut, Markram completed the feat in the second Test against Bangladesh on 6 October 2017 scoring 143 off 186 balls before being bowled by Rubel Hossain. In October 2017, he was added to South Africa's One Day International squad ahead of the third match against Bangladesh, replacing Hashim Amla. He made his ODI debut for South Africa against Bangladesh on 22 October 2017, scored 66 runs and took 2 wickets. In December 2017, he scored his second Test hundred and became the first South Africa player to score two centuries in his first three Tests.
One Day International captaincy
In February 2018, South Africa's captain Faf du Plessis was ruled out of the last five ODIs and the Twenty20 International series against India due to a finger injury. Markram was named as South Africa's captain for the remaining ODI fixtures in du Plessis' absence. He, at the age of 23 years 123 days, is the second youngest player to captain South Africa in ODIs after Graeme Smith.
2018-present
On 30 March 2018, Markram scored his career-best score of 152 runs on the first day of the fourth test against Australia. In June 2018 he was named in South Africa's Test squad for a two Test series in Sri Lanka. Markram averaged just 10 with the bat in this series, his first overseas for South Africa, which showed a vulnerability against spin bowling. In August 2018, he was named in South Africa's Twenty20 International squad for the one-off match against Sri Lanka, but he did not play in the fixture. In March 2019, he was again named in South Africa's T20I squad, this time for the series against Sri Lanka. He made his T20I debut for South Africa against Sri Lanka on 22 March 2019. In April 2019, he was named in South Africa's squad for the 2019 Cricket World Cup. In August 2019, Markram was named in South Africa's squad for the three Test series in India. Markram struggled in the first two matches of this series, bagging a pair in the second Test, before being ruled out of the third due to a self-inflicted wrist injury. This series raised further questions about Markram's overseas performances, averaging just 10.50 in four away Tests, all in the subcontinent. In December 2019 Markram was named in South Africa's squad for the four Test home series against England. In the first Test, he scored 20 runs in the first innings and 2 in the second as South Africa beat England by 107 runs at Centurion. Markram however missed the remainder of the series after fracturing his finger.