{"id":16800,"date":"2018-09-10T14:02:59","date_gmt":"2018-09-10T19:02:59","guid":{"rendered":"https:\/\/www.dotcom-tools.com\/blog\/?p=16800"},"modified":"2021-11-17T01:53:50","modified_gmt":"2021-11-17T07:53:50","slug":"top-tips-for-writing-cleaner-css-code","status":"publish","type":"post","link":"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/","title":{"rendered":"Top Tips for Writing Cleaner CSS Code"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"size-full wp-image-16801 aligncenter\" src=\"https:\/\/www.dotcom-tools.com\/web-performance\/wp-content\/uploads\/2018\/09\/Tips-for-Clean-CSS-code.jpg\" alt=\"Tips for Clean CSS code\" width=\"900\" height=\"400\" srcset=\"https:\/\/www.dotcom-tools.com\/web-performance\/wp-content\/uploads\/2018\/09\/Tips-for-Clean-CSS-code.jpg 900w, https:\/\/www.dotcom-tools.com\/web-performance\/wp-content\/uploads\/2018\/09\/Tips-for-Clean-CSS-code-350x156.jpg 350w, https:\/\/www.dotcom-tools.com\/web-performance\/wp-content\/uploads\/2018\/09\/Tips-for-Clean-CSS-code-768x341.jpg 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/>Do you think <a href=\"https:\/\/www.dotcom-tools.com\/web-performance\/blog\/what-elements-slow-your-website-down\/\" target=\"_blank\" rel=\"noopener\">optimization<\/a> only refers to <a href=\"https:\/\/www.dotcom-tools.com\/web-performance\/blog\/how-to-load-images-faster-on-a-website\/\" target=\"_blank\" rel=\"noopener\">images<\/a> and overall page layout? One of the most commonly misunderstood elements of website development is how the actual layout of CSS code files impacts overall website performance. Considering the importance of performance and page loading for modern SEO and user-engagement, the foundation of optimized websites is based upon clean code.<\/p>\n<p>If you\u2019re searching for a way to easily clean and optimize your CSS code, then there are several powerful tips you should follow. Each of the following tips have been proven by <a href=\"https:\/\/www.dotcom-tools.com\/web-performance\/blog\/tips-for-css-workflow\/\" target=\"_blank\" rel=\"noopener\">industry-leading programmers<\/a> to not only make your writing experience more streamlined, but also capable of delivering smarter, cleaner code files.<\/p>\n<h2>Tip #1 | Be Mindful of Whitespace<\/h2>\n<p>Think making that extra blank line won\u2019t cause harm to your site? While one may not, when you\u2019re dealing with a massive CSS file, each line of whitespace can prove quite detrimental to the speed and loading times for your site.<\/p>\n<p>While whitespace is important for readability, the uploaded file should be carefully constructed to minimize the use of whitespace. When possible, consider Minifying your CSS file. This process creates a separate CSS file that\u2019s had whitespace and unnecessary filler spaces removed. You upload the minified file to your server for speed while keeping the standard file intact for easier updating and debugging.<\/p>\n<h2>Tip #2 | Use CSS Preprocessors<\/h2>\n<p>This is an awesome way to keep your code looking clean while simultaneously boosting its efficiency. Basic CSS is pretty straightforward and doesn\u2019t really allow for much flexibility in terms of variables and groupings. However, when you use a <a href=\"https:\/\/www.dotcom-tools.com\/web-performance\/blog\/importance-of-css-preprocessors\/\" target=\"_blank\" rel=\"noopener\">CSS preprocessor<\/a>, such as SASS, you\u2019re given a whole new world of optimization and streamlined code commands.<\/p>\n<p>While there are many different functions a preprocessor is capable of performing, some of the most noteworthy include:<\/p>\n<ul>\n<li><strong>Reduce Repetitions &#8211;<\/strong> Instead of writing the declarations for each selector who share the same visual style (minus one or two elements), simply create the main selector-declaration. Following selectors that share the same declarations are written with SELECTOR &#8211; MAIN SELECTOR NAME &#8211; NEW DECLARATION(S).<\/li>\n<li><strong>Nesting Syntax &#8211;<\/strong> Are you looking for a way to streamline setting your target DOM elements? If so, then you\u2019ll really appreciate the nesting capabilities of CSS preprocessors.<\/li>\n<li><strong>Swifter Code Processing\/Rendering &#8211;<\/strong> By avoiding repetitions, combining multiple CSS files into a main stylesheet and compressing graphics and icons into a single PNG file, preprocessors reduce overall page weight and HTTP requests. Ultimately, this results in a much swifter page speed for optimized performance Google and your readers enjoy.<\/li>\n<\/ul>\n<h2>Tip #3 | Learn CSS Shorthand<\/h2>\n<p>Want to reduce the time it takes to code a page without having to minimize the amount of declarations or stylistic options? If so, then you should absolutely learn CSS shorthand. This not only allows you to write code faster, but its resulting visual design is much cleaner and easier to read when having to debug or make adjustments. Take a look at <a href=\"https:\/\/google.github.io\/styleguide\/htmlcssguide.html\" target=\"_blank\" rel=\"noopener\">Github\u2019s CSS guidelines<\/a> for best practices regarding shorthand and overall CSS code placement.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Do you think optimization only refers to images and overall page layout? One of the most commonly misunderstood elements of website development is how the actual layout of CSS code files impacts overall website performance. Considering the importance of performance and page loading for modern SEO and user-engagement, the foundation of optimized websites is based&hellip;<\/p>\n","protected":false},"author":6,"featured_media":16801,"comment_status":"open","ping_status":"open","sticky":false,"template":"template-url.php","format":"standard","meta":[],"categories":[75],"tags":[76,69,77,81,71],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v17.6 (Yoast SEO v19.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>Top Tips for Writing Cleaner CSS Code | Dotcom-Monitor Tools Blog<\/title>\r\n<meta name=\"description\" content=\"Each of the following tips have been proven by industry-leading programmers capable of delivering you smarter, cleaner CSS code files.\" \/>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"Top Tips for Writing Cleaner CSS Code\" \/>\r\n<meta property=\"og:description\" content=\"Each of the following tips have been proven by industry-leading programmers capable of delivering you smarter, cleaner CSS code files.\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/\" \/>\r\n<meta property=\"og:site_name\" content=\"Dotcom-Monitor Tools Blog\" \/>\r\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/dotcommonitor\" \/>\r\n<meta property=\"article:published_time\" content=\"2018-09-10T19:02:59+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2021-11-17T07:53:50+00:00\" \/>\r\n<meta property=\"og:image\" content=\"https:\/\/www.dotcom-tools.com\/web-performance\/wp-content\/uploads\/2018\/09\/Tips-for-Clean-CSS-code.jpg\" \/>\r\n\t<meta property=\"og:image:width\" content=\"900\" \/>\r\n\t<meta property=\"og:image:height\" content=\"400\" \/>\r\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\r\n<meta name=\"twitter:card\" content=\"summary\" \/>\r\n<meta name=\"twitter:creator\" content=\"@dotcom_monitor\" \/>\r\n<meta name=\"twitter:site\" content=\"@dotcom_monitor\" \/>\r\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Matt Schmitz\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dotcom-tools.com\/web-performance\/#website\",\"url\":\"https:\/\/www.dotcom-tools.com\/web-performance\/\",\"name\":\"Dotcom-Monitor Tools Blog\",\"description\":\"Let&#039;s Make the Web a Faster Place.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dotcom-tools.com\/web-performance\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/#primaryimage\",\"url\":\"https:\/\/www.dotcom-tools.com\/web-performance\/wp-content\/uploads\/2018\/09\/Tips-for-Clean-CSS-code.jpg\",\"contentUrl\":\"https:\/\/www.dotcom-tools.com\/web-performance\/wp-content\/uploads\/2018\/09\/Tips-for-Clean-CSS-code.jpg\",\"width\":900,\"height\":400,\"caption\":\"Tips for Clean CSS code\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/#webpage\",\"url\":\"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/\",\"name\":\"Top Tips for Writing Cleaner CSS Code | Dotcom-Monitor Tools Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dotcom-tools.com\/web-performance\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/#primaryimage\"},\"datePublished\":\"2018-09-10T19:02:59+00:00\",\"dateModified\":\"2021-11-17T07:53:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.dotcom-tools.com\/web-performance\/#\/schema\/person\/84f55a21a34f808cb7cc381f7f580ebb\"},\"description\":\"Each of the following tips have been proven by industry-leading programmers capable of delivering you smarter, cleaner CSS code files.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.dotcom-tools.com\/web-performance\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Top Tips for Writing Cleaner CSS Code\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dotcom-tools.com\/web-performance\/#\/schema\/person\/84f55a21a34f808cb7cc381f7f580ebb\",\"name\":\"Matt Schmitz\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dotcom-tools.com\/web-performance\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/78f5aac7d4727a530bbb530b52140067?s=96&d=retro&r=pg\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/78f5aac7d4727a530bbb530b52140067?s=96&d=retro&r=pg\",\"caption\":\"Matt Schmitz\"},\"description\":\"Matt Schmitz is a web performance engineer and director of Dotcom-Monitor\u2019s web performance division. Matt is a leading authority on page speed optimization and has been featured by a number of web performance blogs and media outlets. When he\u2019s not working to make the web a faster place, Matt\u2019s interests include gaming, cryptocurrency, and martial arts.\",\"url\":\"https:\/\/www.dotcom-tools.com\/web-performance\/author\/schmitzm\/\"}]}<\/script>\r\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Top Tips for Writing Cleaner CSS Code | Dotcom-Monitor Tools Blog","description":"Each of the following tips have been proven by industry-leading programmers capable of delivering you smarter, cleaner CSS code files.","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:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/","og_locale":"en_US","og_type":"article","og_title":"Top Tips for Writing Cleaner CSS Code","og_description":"Each of the following tips have been proven by industry-leading programmers capable of delivering you smarter, cleaner CSS code files.","og_url":"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/","og_site_name":"Dotcom-Monitor Tools Blog","article_publisher":"https:\/\/www.facebook.com\/dotcommonitor","article_published_time":"2018-09-10T19:02:59+00:00","article_modified_time":"2021-11-17T07:53:50+00:00","og_image":[{"width":900,"height":400,"url":"https:\/\/www.dotcom-tools.com\/web-performance\/wp-content\/uploads\/2018\/09\/Tips-for-Clean-CSS-code.jpg","type":"image\/jpeg"}],"twitter_card":"summary","twitter_creator":"@dotcom_monitor","twitter_site":"@dotcom_monitor","twitter_misc":{"Written by":"Matt Schmitz","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.dotcom-tools.com\/web-performance\/#website","url":"https:\/\/www.dotcom-tools.com\/web-performance\/","name":"Dotcom-Monitor Tools Blog","description":"Let&#039;s Make the Web a Faster Place.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dotcom-tools.com\/web-performance\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/#primaryimage","url":"https:\/\/www.dotcom-tools.com\/web-performance\/wp-content\/uploads\/2018\/09\/Tips-for-Clean-CSS-code.jpg","contentUrl":"https:\/\/www.dotcom-tools.com\/web-performance\/wp-content\/uploads\/2018\/09\/Tips-for-Clean-CSS-code.jpg","width":900,"height":400,"caption":"Tips for Clean CSS code"},{"@type":"WebPage","@id":"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/#webpage","url":"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/","name":"Top Tips for Writing Cleaner CSS Code | Dotcom-Monitor Tools Blog","isPartOf":{"@id":"https:\/\/www.dotcom-tools.com\/web-performance\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/#primaryimage"},"datePublished":"2018-09-10T19:02:59+00:00","dateModified":"2021-11-17T07:53:50+00:00","author":{"@id":"https:\/\/www.dotcom-tools.com\/web-performance\/#\/schema\/person\/84f55a21a34f808cb7cc381f7f580ebb"},"description":"Each of the following tips have been proven by industry-leading programmers capable of delivering you smarter, cleaner CSS code files.","breadcrumb":{"@id":"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dotcom-tools.com\/web-performance\/top-tips-for-writing-cleaner-css-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.dotcom-tools.com\/web-performance\/"},{"@type":"ListItem","position":2,"name":"Top Tips for Writing Cleaner CSS Code"}]},{"@type":"Person","@id":"https:\/\/www.dotcom-tools.com\/web-performance\/#\/schema\/person\/84f55a21a34f808cb7cc381f7f580ebb","name":"Matt Schmitz","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dotcom-tools.com\/web-performance\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/78f5aac7d4727a530bbb530b52140067?s=96&d=retro&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/78f5aac7d4727a530bbb530b52140067?s=96&d=retro&r=pg","caption":"Matt Schmitz"},"description":"Matt Schmitz is a web performance engineer and director of Dotcom-Monitor\u2019s web performance division. Matt is a leading authority on page speed optimization and has been featured by a number of web performance blogs and media outlets. When he\u2019s not working to make the web a faster place, Matt\u2019s interests include gaming, cryptocurrency, and martial arts.","url":"https:\/\/www.dotcom-tools.com\/web-performance\/author\/schmitzm\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dotcom-tools.com\/web-performance\/wp-json\/wp\/v2\/posts\/16800"}],"collection":[{"href":"https:\/\/www.dotcom-tools.com\/web-performance\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dotcom-tools.com\/web-performance\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dotcom-tools.com\/web-performance\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dotcom-tools.com\/web-performance\/wp-json\/wp\/v2\/comments?post=16800"}],"version-history":[{"count":4,"href":"https:\/\/www.dotcom-tools.com\/web-performance\/wp-json\/wp\/v2\/posts\/16800\/revisions"}],"predecessor-version":[{"id":17720,"href":"https:\/\/www.dotcom-tools.com\/web-performance\/wp-json\/wp\/v2\/posts\/16800\/revisions\/17720"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dotcom-tools.com\/web-performance\/wp-json\/wp\/v2\/media\/16801"}],"wp:attachment":[{"href":"https:\/\/www.dotcom-tools.com\/web-performance\/wp-json\/wp\/v2\/media?parent=16800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dotcom-tools.com\/web-performance\/wp-json\/wp\/v2\/categories?post=16800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dotcom-tools.com\/web-performance\/wp-json\/wp\/v2\/tags?post=16800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}