Why <link> and not <style>?

Why do we print this:

<link rel='stylesheet' type='text/css' href='/file.css' />

Instead of this:

<style type='text/css' src='/file.css' />

The reason this seems unintuitive is because we use a tag <style>for inline CSS (just like we use a tag <script>for inline and external Javascript).

+5
source share
1 answer

Of course, you can use the tag if you want, but this only works when your CSS code is embedded in the html file, in which case it will look like this:

<style media="screen" type="text/css">

Add style rules here

</style>

When you use a tag, you "link" the external resource to the current document, so we use the "link" tag.

This is the definition from W3:

.

.

-1

All Articles