An external style sheet and external JavaScript file are used to define the various styles and actions respectively while keeping everything centralized. This is a best practice because if you were to place your scripts and styles directly in the head of each document, there would be no centralized location to make your changes and you’d have to search for all the various rules across multiple locations. See Placing Styles and Scripts Directly in a Document for more information.

The following shows where to place our links to our external script file(s) and CSS file(s). Typically this is done directly after the title tag, but could be placed anywhere in the head of the document.

<meta charset="UTF-8">
<meta name="description" content="Free Web Tutorials">
<meta name="keywords" content="HTML, CSS, JavaScript, PHP, SQL">
<meta name="author" content="1SMARTchicken">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced HTML Template</title>
<!-- styles -->
<link rel="stylesheet" type="text/css" href="/docs/style.css">
<link rel="stylesheet" type="text/css" href="/docs/sidebar-styles.css">
<!-- scripts -->

The link tag is used to link to external style sheets. The type attribute tells the browser what kind of document to expect and the href attribute is the target URL for where the document lives.

Similarly, the script tag is used to link to an external JavaScript file, and requires the type attribute to tell the browser to expect JavaScript and the src attribute which tells the browser where the document lives in the file structure.

Non-Crucial Scripts

Non-crucial scripts can be placed just before the closing /body tag which can speed up the page load time because the page can first render before applying the scripts.

					<!-- scripts -->

The order you link to a style sheet is important. That’s why they’re called Cascading Style Sheets. The rules cascade down the list of documents and if there is a conflict, the last rule loaded is what the browser applies unless one of the rules has more specificity or includes the !important rule.