One of the benefits of JavaFX applications is that their user interfaces can be designed rather than developed. This is typically a job done by a designer rather than a developer. As such, it's a good practice to place all of the application styling outside of Java code within a CSS file.
It's possible to style a JavaFX application within Java code by setting fonts and colors and layout padding (we saw an example of setting padding on elements within the Creating a JavaFX application recipe) within the Java code, but obviously, this makes it more difficult to make style changes to an application.
In this recipe, we'll see how we can apply CSS changes primarily to FXML files. We'll also show how CSS can be applied to Java files for those that are curious about how to do this.