{"id":19,"date":"2012-05-04T23:57:45","date_gmt":"2012-05-04T23:57:45","guid":{"rendered":"https:\/\/learnwebcode.com\/?p=19"},"modified":"2016-03-29T01:17:00","modified_gmt":"2016-03-29T01:17:00","slug":"how-to-create-your-first-css-file","status":"publish","type":"post","link":"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/","title":{"rendered":"CSS Lesson 2: How To Create Your First CSS File"},"content":{"rendered":"<p>Today we are going to write and save our first CSS file.  Let\u2019s begin by opening a text editing program.  If you are on a Microsoft Windows PC open the program named Notepad (hold down the Windows Key on your keyboard and press R, then  type <strong><em>notepad<\/em><\/strong> and press enter).  If you are using a Macintosh computer, launch the application named \u201cTextEdit\u201d (which can be found in your Apps folder).<\/p>\n<h2>Let&#8217;s Write Our First Bit of CSS<\/h2>\n<p>Let&#8217;s imagine we have a simple web page with a heading, and we want the heading to be orange and center aligned.  Add the following code into your new blank text document:<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">h1 {\r\ncolor: orange;\r\ntext-align: center;\r\n}<\/pre>\n<p>Hopefully, you remember this code from our previous lesson.  The task for today is to save our CSS file and link it to an HTML page.<\/p>\n<h2>Step 1: Saving The CSS File<\/h2>\n<p>Create a new folder on your desktop (or another location you prefer) and name it <strong>CSS-Test<\/strong><em>. <\/em>Now, back in your text editing program save your document as &#8220;style.css&#8221;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learnwebcode.com\/wp-content\/uploads\/2010\/02\/save-css-file.gif\" alt=\"Save CSS file\" width=\"447\" height=\"365\" \/><\/p>\n<h2>Linking CSS File to an HTML Page<\/h2>\n<p>Our new CSS file is worthless if we don&#8217;t apply it to a web page.  Let&#8217;s create a quick HTML page for this lesson.  Create a new blank file in Notepad (or TextEdit) and add the following code:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;!DOCTYPE html&gt;\r\n\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;meta charset=&quot;utf-8&quot;&gt;\r\n&lt;title&gt;CSS-Test&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;CSS-Test&lt;\/h1&gt;\r\n\r\n&lt;div id=&quot;box-one&quot;&gt;\r\n&lt;p&gt;This is box one.&lt;\/p&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;div id=&quot;box-two&quot;&gt;\r\n&lt;p&gt;This is box two.&lt;\/p&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>If you&#8217;ve read my first few <a title=\"HTML Lessons\" href=\"https:\/\/learnwebcode.com\/xhtml-lessons\/\">HTML Lessons<\/a>, then this code is at least somewhat familiar.  I&#8217;ll explain it as the lesson continues; for now save this document in our &#8220;CSS-Test&#8221; folder and name it &#8220;index.htm&#8221;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"save-xhtml-file\" src=\"https:\/\/learnwebcode.com\/wp-content\/uploads\/2010\/02\/save-xhtml-file.gif\" alt=\"Save HTML File\" width=\"447\" height=\"365\" \/><\/p>\n<h2>Linking the Two Files Together<\/h2>\n<p>We still need to tell the web browser to load our &#8220;style.css&#8221; file when the &#8220;index.htm&#8221; page is viewed.  Add the following code to &#8220;index.htm&#8221; directly above our &lt;\/head&gt; closing tag:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;<\/pre>\n<p>This line of code tells our browser that we want to link a Style Sheet, that it&#8217;s located in the same folder as our HTML page, and that it&#8217;s named &#8220;style.css&#8221;.<\/p>\n<p>Now, when you view &#8220;index.htm&#8221; page in a web browser you should see a centered, orange heading:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"css-test-1\" src=\"https:\/\/learnwebcode.com\/wp-content\/uploads\/2010\/01\/css-test-1.gif\" alt=\"Create your first CSS File\" width=\"447\" height=\"426\" \/><\/p>\n<h2>Let&#8217;s Style Those Two Boxes<\/h2>\n<p>If you look at the code of our HTML page, you&#8217;ll see two &lt;div&gt; elements.  We added an HTML attribute of &#8220;id&#8221; for these two elements and assigned them values of &#8220;box-one&#8221; and &#8220;box-two.&#8221;  We can use an element&#8217;s &#8220;id&#8221; to select and style it with CSS.  For example, let&#8217;s make the first box gray, and the second box yellow.  Add the following code to your CSS file, directly below our original &lt;h1&gt; rule:<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">#box-one {\r\nbackground-color: gray;\r\n}\r\n\r\n#box-two {\r\nbackground-color: yellow;\r\npadding: 10px;\r\n}<\/pre>\n<p>When an element has an &#8220;id&#8221; we can access it with a CSS selector by placing a pound sign (#) in front of it&#8217;s id value.  So to select the first &lt;div&gt; element we simply type &#8220;#box-one&#8221; and then begin our CSS Rule.<\/p>\n<h2>Our New Fancy Boxes<\/h2>\n<p>When you save your CSS file and refresh our HTML page in a web browser you should see something very similar to this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"css-test-2\" src=\"https:\/\/learnwebcode.com\/wp-content\/uploads\/2010\/01\/css-test-2.gif\" alt=\"First CSS file\" width=\"447\" height=\"425\" \/><\/p>\n<h2>Yay For Style<\/h2>\n<p>It may not be beautiful, but we styled our first HTML page with CSS! Let&#8217;s recap your CSS knowledge so far.  You know:<\/p>\n<ul>\n<li>The basic syntax of CSS (<a title=\"CSS Syntax\" href=\"https:\/\/learnwebcode.com\/what-is-css\/\">covered in our previous lesson<\/a>)<\/li>\n<li>How to link a CSS file to an HTML page<\/li>\n<li>How to select certain HTML elements and style them<\/li>\n<\/ul>\n<p>In our <a href=\"\/basic-css-selectors\/\">next lesson<\/a> we&#8217;ll continue learning about CSS Selectors and the different ways to target specific elements with your CSS.<\/p>\n<p>If you prefer to watch video lessons instead of reading written lessons check out <a href=\"\/web-design-for-beginners-real-world-coding-html-css\/\">my 8 hour video course<\/a> and join 4,000+ others who have learned pro-level HTML, CSS, and responsive design.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we are going to write and save our first CSS file. Let\u2019s begin by opening a text editing program. If you are on a Microsoft Windows PC open the program named Notepad (hold down the Windows Key on your keyboard and press R, then type notepad and press enter). If you are using a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-19","post","type-post","status-publish","format-standard","hentry","category-css-lessons"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>CSS Lesson 2: How To Create Your First CSS File - LearnWebCode<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"CSS Lesson 2: How To Create Your First CSS File - LearnWebCode\" \/>\n<meta property=\"og:description\" content=\"Today we are going to write and save our first CSS file. Let\u2019s begin by opening a text editing program. If you are on a Microsoft Windows PC open the program named Notepad (hold down the Windows Key on your keyboard and press R, then type notepad and press enter). If you are using a [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/\" \/>\n<meta property=\"og:site_name\" content=\"LearnWebCode\" \/>\n<meta property=\"article:published_time\" content=\"2012-05-04T23:57:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-03-29T01:17:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/learnwebcode.com\/wp-content\/uploads\/2010\/02\/save-css-file.gif\" \/>\n<meta name=\"author\" content=\"Brad\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Brad\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/\"},\"author\":{\"name\":\"Brad\",\"@id\":\"https:\/\/learnwebcode.com\/#\/schema\/person\/db825ebc5a08e39b01de31771e4c7fe6\"},\"headline\":\"CSS Lesson 2: How To Create Your First CSS File\",\"datePublished\":\"2012-05-04T23:57:45+00:00\",\"dateModified\":\"2016-03-29T01:17:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/\"},\"wordCount\":743,\"commentCount\":30,\"publisher\":{\"@id\":\"https:\/\/learnwebcode.com\/#\/schema\/person\/db825ebc5a08e39b01de31771e4c7fe6\"},\"image\":{\"@id\":\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/learnwebcode.com\/wp-content\/uploads\/2010\/02\/save-css-file.gif\",\"articleSection\":[\"CSS Lessons\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/\",\"url\":\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/\",\"name\":\"CSS Lesson 2: How To Create Your First CSS File - LearnWebCode\",\"isPartOf\":{\"@id\":\"https:\/\/learnwebcode.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/learnwebcode.com\/wp-content\/uploads\/2010\/02\/save-css-file.gif\",\"datePublished\":\"2012-05-04T23:57:45+00:00\",\"dateModified\":\"2016-03-29T01:17:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#primaryimage\",\"url\":\"https:\/\/learnwebcode.com\/wp-content\/uploads\/2010\/02\/save-css-file.gif\",\"contentUrl\":\"https:\/\/learnwebcode.com\/wp-content\/uploads\/2010\/02\/save-css-file.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/learnwebcode.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CSS Lesson 2: How To Create Your First CSS File\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnwebcode.com\/#website\",\"url\":\"https:\/\/learnwebcode.com\/\",\"name\":\"LearnWebCode\",\"description\":\"Become a Web Developer\",\"publisher\":{\"@id\":\"https:\/\/learnwebcode.com\/#\/schema\/person\/db825ebc5a08e39b01de31771e4c7fe6\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnwebcode.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/learnwebcode.com\/#\/schema\/person\/db825ebc5a08e39b01de31771e4c7fe6\",\"name\":\"Brad\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/learnwebcode.com\/wp-content\/uploads\/0UWl0Tet_400x400.jpg\",\"url\":\"https:\/\/learnwebcode.com\/wp-content\/uploads\/0UWl0Tet_400x400.jpg\",\"contentUrl\":\"https:\/\/learnwebcode.com\/wp-content\/uploads\/0UWl0Tet_400x400.jpg\",\"width\":400,\"height\":400,\"caption\":\"Brad\"},\"logo\":{\"@id\":\"https:\/\/learnwebcode.com\/wp-content\/uploads\/0UWl0Tet_400x400.jpg\"},\"url\":\"https:\/\/learnwebcode.com\/author\/lwcadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"CSS Lesson 2: How To Create Your First CSS File - LearnWebCode","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/","og_locale":"en_US","og_type":"article","og_title":"CSS Lesson 2: How To Create Your First CSS File - LearnWebCode","og_description":"Today we are going to write and save our first CSS file. Let\u2019s begin by opening a text editing program. If you are on a Microsoft Windows PC open the program named Notepad (hold down the Windows Key on your keyboard and press R, then type notepad and press enter). If you are using a [&hellip;]","og_url":"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/","og_site_name":"LearnWebCode","article_published_time":"2012-05-04T23:57:45+00:00","article_modified_time":"2016-03-29T01:17:00+00:00","og_image":[{"url":"https:\/\/learnwebcode.com\/wp-content\/uploads\/2010\/02\/save-css-file.gif","type":"","width":"","height":""}],"author":"Brad","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Brad","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#article","isPartOf":{"@id":"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/"},"author":{"name":"Brad","@id":"https:\/\/learnwebcode.com\/#\/schema\/person\/db825ebc5a08e39b01de31771e4c7fe6"},"headline":"CSS Lesson 2: How To Create Your First CSS File","datePublished":"2012-05-04T23:57:45+00:00","dateModified":"2016-03-29T01:17:00+00:00","mainEntityOfPage":{"@id":"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/"},"wordCount":743,"commentCount":30,"publisher":{"@id":"https:\/\/learnwebcode.com\/#\/schema\/person\/db825ebc5a08e39b01de31771e4c7fe6"},"image":{"@id":"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#primaryimage"},"thumbnailUrl":"https:\/\/learnwebcode.com\/wp-content\/uploads\/2010\/02\/save-css-file.gif","articleSection":["CSS Lessons"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/","url":"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/","name":"CSS Lesson 2: How To Create Your First CSS File - LearnWebCode","isPartOf":{"@id":"https:\/\/learnwebcode.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#primaryimage"},"image":{"@id":"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#primaryimage"},"thumbnailUrl":"https:\/\/learnwebcode.com\/wp-content\/uploads\/2010\/02\/save-css-file.gif","datePublished":"2012-05-04T23:57:45+00:00","dateModified":"2016-03-29T01:17:00+00:00","breadcrumb":{"@id":"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#primaryimage","url":"https:\/\/learnwebcode.com\/wp-content\/uploads\/2010\/02\/save-css-file.gif","contentUrl":"https:\/\/learnwebcode.com\/wp-content\/uploads\/2010\/02\/save-css-file.gif"},{"@type":"BreadcrumbList","@id":"https:\/\/learnwebcode.com\/how-to-create-your-first-css-file\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/learnwebcode.com\/"},{"@type":"ListItem","position":2,"name":"CSS Lesson 2: How To Create Your First CSS File"}]},{"@type":"WebSite","@id":"https:\/\/learnwebcode.com\/#website","url":"https:\/\/learnwebcode.com\/","name":"LearnWebCode","description":"Become a Web Developer","publisher":{"@id":"https:\/\/learnwebcode.com\/#\/schema\/person\/db825ebc5a08e39b01de31771e4c7fe6"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnwebcode.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/learnwebcode.com\/#\/schema\/person\/db825ebc5a08e39b01de31771e4c7fe6","name":"Brad","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/learnwebcode.com\/wp-content\/uploads\/0UWl0Tet_400x400.jpg","url":"https:\/\/learnwebcode.com\/wp-content\/uploads\/0UWl0Tet_400x400.jpg","contentUrl":"https:\/\/learnwebcode.com\/wp-content\/uploads\/0UWl0Tet_400x400.jpg","width":400,"height":400,"caption":"Brad"},"logo":{"@id":"https:\/\/learnwebcode.com\/wp-content\/uploads\/0UWl0Tet_400x400.jpg"},"url":"https:\/\/learnwebcode.com\/author\/lwcadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/learnwebcode.com\/wp-json\/wp\/v2\/posts\/19","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learnwebcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learnwebcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learnwebcode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnwebcode.com\/wp-json\/wp\/v2\/comments?post=19"}],"version-history":[{"count":15,"href":"https:\/\/learnwebcode.com\/wp-json\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":999,"href":"https:\/\/learnwebcode.com\/wp-json\/wp\/v2\/posts\/19\/revisions\/999"}],"wp:attachment":[{"href":"https:\/\/learnwebcode.com\/wp-json\/wp\/v2\/media?parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learnwebcode.com\/wp-json\/wp\/v2\/categories?post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learnwebcode.com\/wp-json\/wp\/v2\/tags?post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}