- Courses
- HTML
- HTML top level tags
- <head>
- Placement of link and script tags
Why is it recommended to place <link>
tags inside <head>
and <script>
tags before </body>
?
Placing <link>
tags inside <head>
ensures styles are applied before rendering, while <script>
tags before </body>
improve loading speed.
Loading styles first prevents content flickering and ensures that the page is styled correctly as soon as it is displayed. Placing scripts at the end of the document avoids blocking the HTML parsing process, allowing the page to load faster and improving the user experience.
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<script src="script.js"></script>
</body>