Using External, Internal CSS Stylesheets and Inline Styles

To add CSS styles to your website, you can use three different ways to insert the CSS. You can Use an “External Stylesheet“, an “Internal Stylesheet“, or in “Inline Style“. The benefit for using each depends on what you are doing with the Style.The following table explains the difference between them.

Different CSS style linking
Internal StylesheetAn internal stylesheet holds the CSS code for the webpage in the head section of the particular file. This makes it easy to apply styles like classes or id’s in order to reuse the code. The downside of using an internal stylesheet is that changes to the internal stylesheet only effect the page the code is inserted into.
External StylesheetThe External Stylesheet is a .css file that you link your website to. This makes it so that what ever you change in the .css sheet, will effect every page in your website. This prevents you from having to make many code changes in each page. This is for “global” site changes.
Inline StylesThe Inline style is specific to the tag itself. The inline style uses the HTML “style” attribute to style a specific tag. This is not recommended, as every CSS change has to be made in every tag that has the inline style applied to it. The Inline style is good for one an individual CSS change that you do not use repeatedly through the site.

Below are examples of what the code looks like for each type of CSS.

Internal CSS Stylesheet

When creating a stylesheet internally in the web page, you will need to use the HTML tags in the Head section of your webpage. All the code for the Internal CSS stylesheet is contained between the <head></head> section of your websites code. Below is an example of what an Internal stylesheet looks like.

<head> <style type="text/css">
h1 {color:blue;}
h2 {color:red;}
p {color:green;}
</style> </head>

External CSS Stylesheet

When using an external stylesheet you must reference the stylesheet in the HTML page that is using it. You would add the code below to your HTML document to reference a stylesheet in the same location as the HTML page called “style.css“. You can upload the “style.css” page can be located anywhere in your files. You can name your stylesheet whatever you like and link to as many as you like. You can simply link to it in your head section and every edit your make to the “style.css” sheet will be globally changed through out the site. Below is what the code looks like.

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

Inline CSS Styles

The inline style uses the HTML “style” attribute. This allows CSS properties on a “per tag” basis. The following is an example of how the inline style is used.

This is a paragraph!

This inline style will change the color of the paragraph to red and make the font size 18 pixels.

This concludes the article on how to link a CSS file to your webpage. Please check the next article on Using CSS in your Website.

28 thoughts on “Using External, Internal CSS Stylesheets and Inline Styles

  1. Can you use two methods in one html doc?

    What I mean is, can I use external and internal css, and eveything will still work correctly?

    1. Did you make sure to clear your browser cache? If you still have the problem, first, try adding the changes to the CSS editor in the Customizer under Advanced. If that doesn’t help, then look into creating a child theme with the changes that you have applied.

  2. The site is https://lincolnparkdance.net/.

    The height in the snippet below was changed from 135 to 20:

    1. Linking to an external stylesheet would be a separate process than using the built-in CSS editor that comes with the Customizer. Which method are you trying to use? If it is an external stylesheet, it will need to be “enqueued” in the WordPress theme, which is advanced and not recommended without creating a child theme. Is the problem that you are not seeing changes made in the CSS editor in the Customizer?

  3. We’ve got BoldGrid on our site and are trying to use their tools to make a modification to the CSS.  I clicked Customize > CSS/HTML Editor and it brings up the theme’s style.css.  After making my change, I click the Update File button at the bottom of the page and it tells me it was successful.  However, I’m not seeing any changes.  Save and Publish is not available from Customize, leading me to believe it’s not seeing the changes I made.

    I’ve tried adding a link at the top of one of the pages to the external CSS, but it doesn’t appear to be seeing it, so I’m guessing I’m not getting the correct path.

    When I look at Chrome’s web development tools, it looks like I’m in the right spot. What do I need to do to make this change active on the pages on my website?

     

    Thanks, Jeff

    1. Hi Jeff,

      We need a bit more information. Do you have a link to your site so we can take a look for you? Also, can you provide the code snippet you’re trying to add? That way, we can see if, in fact, its loading in the CSS and maybe there’s another conflict.

    1. Overriding rules in External CSS and Internal CSS

      The more specific style sheets override less specific ones. The more selectors that you use in a stylesheet, the more specific it is. If you look at this post, the solution that everyone agrees with suggests that you can use rules from one rule in another rule giving it greater specificity – which means it would override the previous rule. If you need more flexibility than that, then the recommendation is to use LESS or SASS.

      Inline CSS

      When you override inline styles, the decision to override isn’t determined by a rule. It’s more a technique used for overriding inline styles (using the !important tag) where you need to decide when your CSS rule must override the inline CSS. Bear in mind that inline CSS is used to override the Internal or External CSS being applied at that point. For example, in these posts, there is an external stylesheet that is applied. We must use inline changes in order to override the CSS rules in order to apply format changes like font or font color that are otherwise determined in the stylesheet.

  4. This tutorial was relly helpful to know the different types of css styles. It was helpful to creates my blog.

     

    Thanks.,

  5. what is the priority color it takes when we give three different colors for three different stylesheets internal,inline,external

    1. Anjan, the CSS that affects your element will typically be whichever is loaded most recently. If you have CSS declarations in your HEAD tag, those will typically be overwritten by local specifications in your BODY tag or even style specifics on the element itself.

    1. Generally, inline takes precedent over internal, and internal takes precedent over external. However, certain elements, rules, and classes can cancel each other out. So it always best to know which rules are affecting which elements. You can also use the !important identifier in your stylesheet to override other rules, but you should only use this as a last resort.

  6. Hello, I just wanted to ask, about the color. If I need to use Internal CSS is that mean that the color will need to be like “red,orange,blue” it has to be their names? or its okay to use the hash with numbers? thanks 

     

    Because my teacher instruct us to use Internal CSS and i forgot to ask him.

    1. Hello Cy,

      The setting is the same, no matter whether using internal CSS or not. You can use the color name (red, blue) or the hash (#ff0000 for red, #0000ff for blue) Using the hash gives you access to many more colors as they do not have names for every hash combination.

      Kindest Regards,
      Scott M

Was this article helpful? Join the conversation!

Server Madness Sale
Score Big with Savings up to 99% Off

X