This question already has an answer here:
MBP 2015 13, 10.12.2
I want to use an external display via HDMI and turn off my Macbook Pro's display. How can I do it?
There is another question: How do I turn off laptop display when I have an external display?, but I don't think this one should be marked as duplicate.
Its 2017 now and the old question has answers from 2011-2014.
The other thing is - that the old question has also links to other answers and solutions. With this question we have answer with 2 variations of how to do it in one place.