{"id":21,"date":"2008-02-06T15:21:33","date_gmt":"2008-02-06T21:21:33","guid":{"rendered":"http:\/\/cssnewbie.com\/basic-techniques\/inline-in-document-and-linked-css\/"},"modified":"2008-02-06T15:21:33","modified_gmt":"2008-02-06T21:21:33","slug":"inline-in-document-and-linked-css","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/inline-in-document-and-linked-css\/","title":{"rendered":"When to Use Inline, In-Document, and Linked CSS"},"content":{"rendered":"<p><img src='https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/02\/css-example.gif' alt='css-example.gif' \/><\/p>\n<p>There are three ways to inject a bit of CSS magic into your web pages. They are inline styles, in-document styles via the &lt;style&gt; tag, and linked style sheets. Each is valuable in its own right \u2013 the trick is knowing when to use them.<\/p>\n<p><strong>Inline styles<\/strong> are the most basic way of applying styles to an element, in that you apply the styles directly to the tag in your HTML. For example, this is an inline style:<\/p>\n<pre lang=\"html4strict\" escaped=\"true\" line=\"1\">&lt;p style=\"font-size: 200%;\"&gt;\n\tThis text will be twice the size\n\tof your other paragraphs.\n&lt;\/p&gt;<\/pre>\n<p>This is most useful when you are trying out new tags. In the example above, if I had several paragraphs on my page, I could easily try out several styles on several paragraphs to more quickly find the exact look I was going for. It\u2019s also useful if you need to override a more global style in one specific instance: if you\u2019re using inline, in-document and linked CSS all at the same time, inline styles take precedence. <\/p>\n<p><strong>In-document (AKA &#8220;embedded&#8221;) styles<\/strong> make use of the &lt;style&gt; tag within the HTML document\u2019s head, like so:<\/p>\n<pre class=\"html css\">&lt;style&gt;\n\tp {\n\t\tfont-size: 200%;\n\t}\n&lt;\/style&gt;<\/pre>\n<p>This technique is best used when you have one page that needs to be styled differently from every other in your website. You still have the flexibility to apply styles to your entire document, and those styles have the opportunity to cascade and change broad swaths of your page with little effort, but to apply these styles to more than one page, you have two options: copy and paste the styles into all your documents (messy, if you ever make any changes), or use linked style sheets.<\/p>\n<p><strong>Linked style sheets<\/strong> are the preferred method for applying CSS to a website. Here, your CSS resides in a separate document, outside of your HTML entirely. You then link to it in your document\u2019s head like this:<\/p>\n<pre lang=\"html4strict\" escaped=\"true\" line=\"1\">&lt;link rel=\"stylesheet\" href=\"style.css\"\nmedia=\"screen\" \/&gt;<\/pre>\n<p>There are three important pieces here:<\/p>\n<ul>\n<li><strong>Rel:<\/strong> Stands for \u201crelationship.\u201d Tells your browser that this is a stylesheet.<\/li>\n<li><strong>Href:<\/strong> Stands for \u201chypertext reference.\u201d This is how your browser knows where to find the stylesheet. If it\u2019s in a different directory, you\u2019ll have to show that in your href.<\/li>\n<li><strong>Media <em>(optional)<\/em>:<\/strong> Says that this stylesheet should be applied to the screen. If you leave this off, it will still be applied to the screen.<\/li>\n<\/ul>\n<p>And most importantly, you can just include this one line of code in the top of every page you want to have styled (between the &lt;head&gt; and &lt;\/head&gt; tags), and the browser takes care of the rest. Now if you ever make a change to your CSS, you can just change it in that one file, and the changes will take place automatically across your entire site. And that, when you get right down to it, is really what makes this whole CSS thing so great in the first place.<\/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>\n<p>There are three ways to inject a bit of CSS magic into your web pages. They are inline styles, in-document styles via the &lt;style&gt; tag, and linked style sheets. Each is valuable in its own right \u2013 the trick is [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/inline-in-document-and-linked-css\/\" title=\"Click to read 'When to Use Inline, In-Document, and Linked CSS'\">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":[168],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/21"}],"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=21"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/21\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}