TL; DR
Only use inline styling in the latter case, when you need to overlap an already defined style on an external sheet and it will never be repeated.
Embedded styling can be used on pages that have a unique style sheet that will not be reused by any other. A good example are sites with only one page.
If you have not fit any of the above, go with external styling .
Remember that what is said here is not a rule.
Yes, in fact there are different ways to apply the CSS style sheet to HTML. Of the most spoken we have:
Inline styling
This is the most basic form. This is how we first learn, as it is easy and quick to apply. It does not allow reuse of applied style, while other forms do.
It's a nightmare to keep. I would use in the latter case, in the exception of exceptions, if I needed to overlap a defined style in my external styles (I'll tell you below).
<p style="color: #333;">Olá!</p>
The problem is when I need the same style in multiple elements. Repeating the code for each one is not smart. What if I want to change from color: #333;
to something else? It would have to change everything. The solution comes with built-in styling.
Embedded styling
Its advantages over online styling are apparent. Here we have reuse.
<style>
p {
color: #333;
}
</style>
Imagine I want all p
elements to have this style. I do not need the style
attribute in all of them.
If you have a single page on your site, then I see no problem in using it. Unlike ... if you need to use the same styles on different pages, see that copying all styles to another page is a costly alternative, when you need to change something you would need to change all your HTML files. The solution to this is external styling.
External styling (external)
Your styles stored in .css files. You can have several of them and use them when you want. D on't R epeat strong> Y ourself when well used. It enables browser caching, consuming fewer client resources and consequently multiple pages will load faster.
<link rel="stylesheet" type="text/css" href="estilos.css">
Some additional readings: