{"id":3286,"date":"2022-04-04T08:24:00","date_gmt":"2022-04-04T08:24:00","guid":{"rendered":"https:\/\/cssdeck.com\/blog\/?p=3286"},"modified":"2022-04-04T05:44:51","modified_gmt":"2022-04-04T05:44:51","slug":"integrating-inline-css-in-html-without-editing-css-files","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/integrating-inline-css-in-html-without-editing-css-files\/","title":{"rendered":"Integrating CSS Within HTML Without Editing CSS Files"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">What is CSS?<\/h2>\n\n\n\n<p>Cascading Style Sheets (CSS) is a style sheet language that is used to describe the display of a document built in a markup language like HTML. CSS, like HTML and JavaScript, is a foundational technology of the <a href=\"https:\/\/en.wikipedia.org\/wiki\/World_Wide_Web\"><strong>World Wide Web<\/strong><\/a>.<\/p>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/styling-resources-learn-css-for-free\/\">Styling Resources: Learn CSS for Free<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is HTML?<\/h2>\n\n\n\n<p>HTML, or HyperText Markup Language, is the standard markup language for texts intended to be displayed in a web browser. It can be aided by technology like Cascading Style Sheets and scripting languages like JavaScrip.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Integrating CSS within HTML&nbsp;<\/h2>\n\n\n\n<p>CSS may be introduced to HTML texts in three different ways:<\/p>\n\n\n\n<ul><li>Inline CSS &#8211; when the style property is used within HTML elements.<\/li><li>Internally, by including a &lt;style&gt; element in the &lt;head&gt; section.<\/li><li>External CSS &#8211; by linking to an external CSS file with a &lt;link&gt; element.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"673\" height=\"283\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/04\/Screenshot-890.png\" alt=\"\" class=\"wp-image-3288\" \/><\/figure>\n\n\n\n<p>The most frequent method of adding CSS is to maintain the styles in separate CSS files. However, for the sake of this article, we will utilize inline and internal styles because they are easier to illustrate and test.<\/p>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/why-digital-marketers-should-learn-basic-css-and-html\/\">Why Digital Marketers Should Learn Basic CSS and HTML<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Inline CSS in HTML<\/h2>\n\n\n\n<p>CSS is often written in a separate CSS file (with the file extension.css) or in a &lt;style&gt; tag within the &lt;head&gt; tag. However, there is a third option that is equally acceptable. The style attribute of an HTML element is the third place you may write CSS. When CSS is written with the style property, it is referred to as &#8220;inline style.&#8221; This is not regarded as a great practice in general. However, there are occasions where inline styles are the best (or only) option.<\/p>\n\n\n\n<p>A number of CSS property and value pairs make up the style attribute. A semicolon (;) separates each &#8220;property: value&#8221; pair, just like in embedded or external style sheets. It must, however, fit on one line, with no line breaks after the semicolon. Refer to the example mentioned below.<\/p>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<div class=\"wp-block-group is-layout-flow\"><div class=\"wp-block-group__inner-container\">\n<p>&lt;h1 style=&#8221;color:blue; font-size:40px;&#8221;&gt;This is a heading&lt;\/h1&gt;<\/p>\n\n\n\n<p>&lt;p style=&#8221;color:green; font-size:20px;&#8221;&gt;This is a paragraph.&lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;div style=&#8221;color:red; font-size:10px;&#8221;&gt;This is some text content.&lt;\/div&gt;<\/p>\n<\/div><\/div>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"466\" height=\"480\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/04\/Screenshot-891.png\" alt=\"\" class=\"wp-image-3289\" \/><\/figure><\/div>\n\n\n\n<p>Using inline styles is generally seen to be a bad idea. Because style rules are put directly in the HTML element, the presentation becomes entangled with the document&#8217;s content, making it harder to maintain the code and negating the purpose of using CSS.<\/p>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/css-styles-inline-vs-internal-vs-external\/\">CSS Styles: Inline vs. Internal vs. External<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Embedded Style Sheets<\/h2>\n\n\n\n<p>Internal style sheets, often known as embedded style sheets, have no influence on the document they are contained in.<\/p>\n\n\n\n<p>The &lt;style&gt; element is used to generate embedded style sheets in the &lt;head&gt; section of an HTML page. In an HTML page, you can declare an unlimited number of &lt;style&gt; elements, but they must exist between the &lt;head&gt; and &lt;\/head&gt; tags.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"598\" height=\"255\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/04\/Screenshot-892.png\" alt=\"\" class=\"wp-image-3290\" \/><\/figure><\/div>\n\n\n\n<p>Embedded style sheets enable you to create styles for the entire HTML content in a single location. When you use the &lt;style&gt; element to embed style sheet information into an HTML page, this is referred to as embedded style sheets. This is accomplished by putting the style sheet information within &lt;style&gt;&lt;\/style&gt; tags in the document&#8217;s head. Refer to the example mentioned below.&nbsp;<\/p>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<div class=\"wp-block-group is-layout-flow\"><div class=\"wp-block-group__inner-container\">\n<p>&lt;!DOCTYPE html&gt;<\/p>\n\n\n\n<p>&lt;html lang=&#8221;en&#8221;&gt;<\/p>\n\n\n\n<p>&lt;head&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;My HTML Document&lt;\/title&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;style&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;body { background-color: red; }<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p { color: #fff; }<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/style&gt;<\/p>\n\n\n\n<p>&lt;\/head&gt;<\/p>\n\n\n\n<p>&lt;body&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;This is a heading&lt;\/h1&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&lt;p&gt;This is a paragraph of text.&lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;\/body&gt;<\/p>\n\n\n\n<p>&lt;\/html&gt;<\/p>\n<\/div><\/div>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/how-to-override-inline-css-styles\/\">How to Override Inline CSS Styles<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">External Style Sheets<\/h2>\n\n\n\n<p>An external style sheet is for cases when the style is applied to many pages of the website.<\/p>\n\n\n\n<p>An external style sheet is a standalone document that contains all of your site&#8217;s style rules and can be accessed from any HTML page. External style sheets are the most versatile since they allow you to update only one file to give a new look to an entire website.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"529\" height=\"394\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/04\/Screenshot-893.png\" alt=\"inline css in html\" class=\"wp-image-3291\" \/><\/figure><\/div>\n\n\n\n<p>There are two methods for attaching external style sheets: linking and importing.<\/p>\n\n\n\n<p>External style sheets are produced in distinct documents that have a .css extension. An external style sheet is nothing but a collection of CSS rules. HTML tags are not permitted. The &lt;link&gt; element, which appears at the head of an HTML page, is used to direct visitors to an external style sheet.<\/p>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/how-to-link-css-to-html\/\">How To Link CSS To HTML<\/a><\/strong><\/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>What is CSS?<\/p>\n<p>Cascading Style Sheets (CSS) is a style sheet language that is used to describe the display of a document built in a markup language like HTML. CSS, like HTML and JavaScript, is a foundational technology of the World [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/integrating-inline-css-in-html-without-editing-css-files\/\" title=\"Click to read 'Integrating CSS Within HTML Without Editing CSS Files'\">Read Article<\/a><\/p>\n","protected":false},"author":21,"featured_media":3292,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,181],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3286"}],"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\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=3286"}],"version-history":[{"count":2,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3286\/revisions"}],"predecessor-version":[{"id":3293,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3286\/revisions\/3293"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media\/3292"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=3286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=3286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=3286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}