<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ogechì🖤</title>
    <description>The latest articles on DEV Community by Ogechì🖤 (@reubenvictoire).</description>
    <link>https://dev.to/reubenvictoire</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F912353%2F3aaceb77-48a8-42fe-89b8-9675d326ca69.jpg</url>
      <title>DEV Community: Ogechì🖤</title>
      <link>https://dev.to/reubenvictoire</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/reubenvictoire"/>
    <language>en</language>
    <item>
      <title>How to add CSS to HTML</title>
      <dc:creator>Ogechì🖤</dc:creator>
      <pubDate>Tue, 23 Aug 2022 20:37:00 +0000</pubDate>
      <link>https://dev.to/reubenvictoire/how-to-add-css-to-html-1oc7</link>
      <guid>https://dev.to/reubenvictoire/how-to-add-css-to-html-1oc7</guid>
      <description>&lt;p&gt;The &lt;strong&gt;Hyper Text Markup Language (HTML&lt;/strong&gt;) and &lt;strong&gt;Cascading Style Sheets (CSS)&lt;/strong&gt; are the two main languages used to create websites. While HTML provides a website's structure, CSS is used to style the website. Together, they give users the ability to design an attractive and well-organized website.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Prerequisites&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This article assumes the reader has the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A text editor&lt;/li&gt;
&lt;li&gt;Basic HTML knowledge.&lt;/li&gt;
&lt;li&gt;Basic CSS knowledge.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Only when CSS is added to the HTML document can the style declarations be applied to the HTML code. However, many newbie developers have trouble adding CSS to HTML. Therefore, the three styling techniques are covered in this article. They are as follows:&lt;br&gt;
   &lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Inline CSS&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here, styles are added directly to the HTML element tags using the style attribute.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1 style = "color : blue;" &amp;gt;Inline CSS&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
 For example,&lt;br&gt;
If you want to change the text color and background color of an element, you can:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add the style attribute to the element.&lt;/li&gt;
&lt;li&gt;Add the style properties to the style attributes.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;p style = " " &amp;gt; Paragraph &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt; &lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;p style = "color:blue; background-color:yellow;"&amp;gt; Paragraph &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;  Due to its high CSS &lt;a href="https://www.w3schools.com/css/css_specificity.asp"&gt;specificity&lt;/a&gt;, only one element can be targeted at a time with this type of styling. Inline styling is not used in daily applications except in rare cases, because the HTML code becomes cumbersome and unpleasant to read.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Avoid using inline CSS as much as you can, but if you must, do it sparingly.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Internal CSS&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here, styles are added using the HTML &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tag in the head section of the HTML document. Then, the style properties are defined using the appropriate selectors in the &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tag. Internal CSS is also oftentimes referred to as embedded CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;head&amp;gt;
     &amp;lt;style&amp;gt;
       h1{
        color:blue;
       }
    &amp;lt;/style&amp;gt;

  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;

     &amp;lt;h1&amp;gt;Internal CSS&amp;lt;/h1&amp;gt;

  &amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
How to change the color of the `h1` element using the internal styling method 





&lt;p&gt; &lt;br&gt;&lt;br&gt;
The styles for a single HTML page are defined using the internal CSS styling method. This is one of the method's main drawbacks.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;The internal style method is therefore not used much in practice.&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;External CSS&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The styling techniques discussed so far are all included in the HTML document (either in the head or the body). But in this case, we import the CSS styles via the &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt;tag from an external style sheet. This is important since it makes the code easier to maintain and read.  &lt;br&gt;&lt;br&gt;
The external CSS style method requires us to create an external style &lt;code&gt;.css&lt;/code&gt; file and link it to HTML. &lt;br&gt;
 &lt;br&gt;
For instance, if you want to style a HTML element using this technique, you can:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create the external style sheet file using the &lt;code&gt;.css&lt;/code&gt; extension (Create a file called &lt;code&gt;style.css&lt;/code&gt;.)&lt;/li&gt;
&lt;li&gt;Target the HTML element inside the &lt;code&gt;style.css&lt;/code&gt; file using the selector like so. &lt;/li&gt;
&lt;li&gt; Import the &lt;code&gt;style.css&lt;/code&gt; file into the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; section of the HTML document using the &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   h1{
       color: blue;

       font-size: 16px;

     }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
 How to target the `h1` element in the external stylesheet 


 

&lt;p&gt; &lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;head&amp;gt;
     &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
     &amp;lt;h1&amp;gt; External CSS &amp;lt;/h1&amp;gt;
  &amp;lt;/body&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; How to import the &lt;code&gt;style.css&lt;/code&gt; file into the HTML document     &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;This method's ability to specify styles for multiple HTML pages is one of its greatest features.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thus, making external CSS the most preferable method for styling web pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I hope you were able to learn about the three distinct approaches to including CSS in HTML.&lt;br&gt;
Feel free to add CSS to your HTML code using the knowledge you have gained from this article.  &lt;/p&gt;

&lt;p&gt;I'll be delighted to address any questions you have in the comments section below.&lt;br&gt;
&lt;strong&gt;If you want to learn more about web development, feel free to follow me on &lt;a href="https://twitter.com/ReubenVictoire"&gt;Twitter&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading🎉.&lt;/p&gt;

&lt;p&gt;Cover photo by &lt;a href="https://unsplash.com/@clemhlrdt"&gt;Clément Hélardot&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>css</category>
      <category>html</category>
    </item>
  </channel>
</rss>
