3

Is it possible to load external Style Sheet after Internal (or embedded) styles get loaded. I mean, say I have a div with Yellow background color, set using embedded style in a page, like;

<style type="text/css">
div{
  background-color: yellow;
}
</style>

And can I change the background color to green using an external style sheet like;

<link rel="stylesheet" href="style.css" type="text/css" />

If this is possible, show me an example.

I know this is possible with inline style, but I don't want to use that.

1

4 Answers 4

5

Yes.

Just put the <link> tag after the <style> tag, or make the selector in the external stylesheet more specific.

1

To answer your question, yes you can. The styles will be applied in a specific order. See here for precedence rules in CSS.

-1

if you want to overwrite a css with same class, you can use 'important' in that class. Study more about important in css.

-2

offcourse you can just place the external style sheet after the internal style sheet in HTML head section to override the internal style sheet!

CSS ORDER

What style will be used when there is more than one style specified for an HTML element?

Generally speaking we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules, where number four has the highest priority:

1. Browser default

2. External style sheet

3. Internal style sheet (in the head section)

4. Inline style (inside an HTML element)

2
  • You are correct about inline styles (however not in the context you are saying. inline styles generally refer to <element style="" />...) however the rest is not. Please read : coding.smashingmagazine.com/2007/07/27/…
    – rlemon
    Aug 19, 2012 at 18:01
  • Just be aware that the style applied to any particular element is not just dependent on the cascading order of the stylesheets. Specificity (part of the cascade) and inheritance all play a vital role.
    – MrWhite
    Aug 19, 2012 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.