Task runners work by defining a series of tasks in a configuration file. For example, in Gulp, you would create a gulpfile.js where you define tasks such as minifying CSS, optimizing images, and compiling HTML templates. Once the tasks are defined, they can be executed with a single command, automating the entire process.