Why isn’t it <style src=””>?

Publikováno: 10.12.2018

The way JavaScript works is we can do scripts as an inline block:

<script>
let foo = "bar";
</script>

Or, if the script should be fetched from the network...

<script src="/js/global.js"></script>

With CSS, we can do an inline block of styles:

<style>
.foo { color: red; }
</style>

So why not <style src=""></style>? Instead, we have <link href="">.

Harry Roberts asked about that the other day on Twitter:

Can any W3 historians tell us why it’s `<link rel="stylesheet" …

The post Why isn’t it <style src=””>? appeared first on CSS-Tricks.

Celý článek

The way JavaScript works is we can do scripts as an inline block:

<script>
  let foo = "bar";
</script>

Or, if the script should be fetched from the network...

<script src="/js/global.js"></script>

With CSS, we can do an inline block of styles:

<style>
  .foo { color: red; }
</style>

So why not <style src=""></style>? Instead, we have <link href="">.

Harry Roberts asked about that the other day on Twitter:

There is lots of speculation in that thread, but Bruce has a pretty clear answer:

I sort of get that. The location in the document matters with src, but not with <link> — that relates to the entire document instead. I guess the crack in that reasoning is that the order of stylesheets does matter for order-specificity, but I take the point.

The W3C chimed to confirm that logic:

There we have it: <style src=""></style> wasn't even considered.

The post Why isn’t it <style src=””>? appeared first on CSS-Tricks.

Nahoru
Tento web používá k poskytování služeb a analýze návštěvnosti soubory cookie. Používáním tohoto webu s tímto souhlasíte. Další informace