Open ghost opened 6 years ago
Hi @edwardcodes! Thank you for opening this question! π
There are 3 primary reasons for using an external stylesheet:
Having said that, there is a trend towards "Functional CSS" see: github.com/dwyl/learn-tachyons which means you use "lego-like CSS individual attribute building blocks" to create your styles and "inline styles" with many front-end frameworks which "compile" the entire "application" ("app") into a single JavaScript file including HTML templates, JS "logic" and Styles! This used to be (widely) considered an "Anti-pattern" because when you want to change one Style the entire application needs to be "re-compiled" and the end-user needs to re-download the entire "bundle" which can often be 2Mb+ (in the case of an Angular or React app...) which means that
People learning HTML & CSS should always learn all 3 methods of including CSS Styles:
<style>
tag e.g:
<p class="red"> My Red Text </p>
<!-- somewhere in the same HTML doc -->
<style>
.red { color: red; }
</style>
<head>
of the HTML document.<p style="color: red">My Red Text</>
Each of these methods has a distinct and valid use-case. e.g:
Elm
...) and "compiled" into a single file (all the structure, logic and styles are treated as one thing!)@edwardcodes please let us know if this answers your question? if you found additional info/insight while researching it, please share links so the community can learn! Thanks! (keep the questions coming!) π
hi @edwardcodes External stylesheets allow you to completely separate your CSS from your HTML. Here the style is included in one or more css files and reference from your HTML using the LINK tag:
Link Tag Stylesheet Attributes The link tag has the following attributes:
rel β the relationship of the link to the document href β in this case the location of the stylesheet to be included type β the type of file it is (in our case text/css) media β for what media the stylesheet is to be included screen β normal computer browser β on screen print β on paper (printer friendly) aural β for speech synthesizers embossed β intended for Braille printers all β intended for all types of media The benefits of using an external style sheet are:
everything is stored within a single file. once changed/updated, the changes are reflected on all other pages that reference the stylesheet. this makes it easier to maintain larger websites. pages load quicker once the main CSS file has been cached. as a result bandwidth goes down. effectively, youβre able to change the entire look and feel of a website through a single file. Thanks.
Whats the advantage of styling the html file externally?