{"id":1968,"date":"2016-06-30T14:46:45","date_gmt":"2016-06-30T14:46:45","guid":{"rendered":"http:\/\/cssreset.com\/?p=1968"},"modified":"2016-06-30T14:46:45","modified_gmt":"2016-06-30T14:46:45","slug":"css-styles-inline-vs-internal-vs-external","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/css-styles-inline-vs-internal-vs-external\/","title":{"rendered":"CSS Styles: Inline vs. Internal vs. External"},"content":{"rendered":"<p>Before you master CSS, you need to understand the different ways in which you can apply the CSS to your HTML. There are three basic ways to include style in your code: inline styling, internal stylesheets, and external stylesheets.<\/p>\n<p>Inline styling is probably the least efficient and least use methods of applying CSS to your HTML code. Inline styling is when you add styles to your HTML elements right within the HTML tags, like this:<\/p>\n<div id=\"ig-sh-1\" class=\"syntax_hilite\">\r\n\r\n\t\t<div class=\"toolbar\">\r\n\r\n\t\t<div class=\"view-different-container\">\r\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\r\n\t\t\t\t\t<\/div>\r\n\r\n\t\t<div class=\"language-name\">HTML<\/div>\r\n\r\n\t\t\r\n\t\t<br clear=\"both\">\r\n\r\n\t<\/div>\r\n\t\r\n\t<div class=\"code\">\r\n\t\t<ol class=\"html4strict\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\">&lt;<span style=\"color: #000000;font-weight: bold\">p<\/span> <span style=\"color: #000066\">style<\/span><span style=\"color: #66cc66\">=<\/span><span style=\"color: #ff0000\">&quot;color: #333;&quot;<\/span>&gt;<\/span>This text will be dark gray<span style=\"color: #009900\">&lt;<span style=\"color: #66cc66\">\/<\/span><span style=\"color: #000000;font-weight: bold\">p<\/span>&gt;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\r\n\r\n<\/div>\r\n\n<p>As you can see, the format of the CSS remains constant no matter where it&#8217;s inserted (property: value;), but in this case the color property will only apply to this particular HTML element. This type of styling doesn&#8217;t really make sense 99% of the time. It&#8217;s not dynamic, it&#8217;s not mobile-friendly, and it&#8217;s time consuming to implement, as each HTML element would have to have its own style rules applied to it.<\/p>\n<p>Internal (or in-document, or embedded) stylesheets are CSS styles that are added to the &lt;head&gt; section of your document within &lt;style&gt; tags, like so:<\/p>\n<div id=\"ig-sh-2\" class=\"syntax_hilite\">\r\n\r\n\t\t<div class=\"toolbar\">\r\n\r\n\t\t<div class=\"view-different-container\">\r\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\r\n\t\t\t\t\t<\/div>\r\n\r\n\t\t<div class=\"language-name\">css<\/div>\r\n\r\n\t\t\r\n\t\t<br clear=\"both\">\r\n\r\n\t<\/div>\r\n\t\r\n\t<div class=\"code\">\r\n\t\t<ol class=\"css\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&lt;style<span style=\"color: #00AA00\">&gt;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">p<span style=\"color: #00AA00\">&#123;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000000;font-weight: bold\">color<\/span><span style=\"color: #00AA00\">:<\/span> <span style=\"color: #cc00cc\">#333<\/span><span style=\"color: #00AA00\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #00AA00\">&#125;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&lt;\/style<span style=\"color: #00AA00\">&gt;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\r\n\r\n<\/div>\r\n\n<p>In these cases, the styles aren&#8217;t just applied to each individual element like with inline styling, but every element of the selector&#8217;s type that is present\u00a0<em>on that page<\/em>. So, in this example, every p tag on this particular page would have the color #333. This type of styling is useful when \u00a0you&#8217;re working with a particular page where something needs to be styled differently than any of the other pages on your site, but it&#8217;s not recommended to do all your styling this way, because it&#8217;s a lot harder to make universal changes to all your pages if you do (plus, it makes your pages look kind of messy).<\/p>\n<p>The final and most widely used type of styling is external CSS stylesheets. These stylesheets are their own file, usually located in a CSS directory of some sort. They&#8217;re often lined to in a universal header or in the &lt;head&gt; section of and HTML file. The format of the CSS is the same as the format of the CSS in the internal or embedded styling, but the CSS rules of an external stylesheet will apply to every HTML page that links to the stylesheet, which makes it very easy and convenient to uniformly style many elements across many different pages, and to make changes to your CSS to optimize your site for mobile and different sized viewports.<\/p>\n<p>The link to your external CSS file should be placed in the &lt;head&gt; of your document, and look something like this:<\/p>\n<div id=\"ig-sh-3\" class=\"syntax_hilite\">\r\n\r\n\t\t<div class=\"toolbar\">\r\n\r\n\t\t<div class=\"view-different-container\">\r\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\r\n\t\t\t\t\t<\/div>\r\n\r\n\t\t<div class=\"language-name\">HTML<\/div>\r\n\r\n\t\t\r\n\t\t<br clear=\"both\">\r\n\r\n\t<\/div>\r\n\t\r\n\t<div class=\"code\">\r\n\t\t<ol class=\"html4strict\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\">&lt;<span style=\"color: #000000;font-weight: bold\">link<\/span> <span style=\"color: #000066\">rel<\/span><span style=\"color: #66cc66\">=<\/span><span style=\"color: #ff0000\">&quot;stylesheet&quot;<\/span> <span style=\"color: #000066\">type<\/span><span style=\"color: #66cc66\">=<\/span><span style=\"color: #ff0000\">&quot;text\/css&quot;<\/span> <span style=\"color: #000066\">href<\/span><span style=\"color: #66cc66\">=<\/span><span style=\"color: #ff0000\">&quot;path\/to\/stylesheet.css&quot;<\/span>&gt;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\r\n\r\n<\/div>\r\n\n<p>Understanding all the different ways to apply CSS to your HTML is important in learning the basics of style and design, but if you&#8217;re new to CSS and aren&#8217;t already using external stylesheets, it&#8217;s time to start experimenting with them. Without them, it&#8217;s a lot more difficult to get creative and use CSS to its full potential.<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Before you master CSS, you need to understand the different ways in which you can apply the CSS to your HTML. There are three basic ways to include style in your code: inline styling, internal stylesheets, and external stylesheets.<\/p>\n<p>Inline styling [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/css-styles-inline-vs-internal-vs-external\/\" title=\"Click to read 'CSS Styles: Inline vs. Internal vs. External'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,6,42],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/1968"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=1968"}],"version-history":[{"count":3,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/1968\/revisions"}],"predecessor-version":[{"id":1971,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/1968\/revisions\/1971"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=1968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=1968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=1968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}