How do you create a custom WordPress theme from scratch?

Creating a custom WordPress theme involves building template files, such as index.php, style.css, and functions.php. The style.css file should contain theme metadata, and functions.php can enqueue styles and scripts. WordPress functions, like get_header(), get_footer(), and the loop, are used to structure the theme.

<?php
/*
Theme Name: Custom Theme
Description: A custom WordPress theme.
*/