What is the preferred way of including CSS within a project? How do I know when to
Use inline styles, the tags, or a .css file?
As a web developer you will eventually come across HTML documents which include CSS either inline with
style attributes or within the
<style> tags at the head of the document. Hence, it is important to be aware of all the various ways to include CSS in a project.
That having been said, mashing HTML and CSS together is not a great habit to get into. As developers we want to “separate our concerns” because this usually creates codebases that are more flexible, readable, and maintainable. As such, keeping our CSS contained within a separate .css file is the preferred way of including CSS within most projects.
For a deeper dive into some of the nuances here, take a look at this article.