{"id":15196,"date":"2012-10-12T21:01:39","date_gmt":"2012-10-12T13:01:39","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=15196"},"modified":"2023-07-16T19:58:01","modified_gmt":"2023-07-16T11:58:01","slug":"css-to-less","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/css-to-less\/","title":{"rendered":"How to Convert Old CSS to LESS"},"content":{"rendered":"<p>We have covered much of the basics for LESS in our <a href=\"https:\/\/www.hongkiat.com\/blog\/tag\/less\/\">previous posts<\/a>. If you have been following our LESS series, we believe that at this point you already have a good idea about how to use the <strong><a href=\"https:\/\/www.hongkiat.com\/blog\/less-css-tutorial-design-slick-menu-nav-bar\/\">Variables<\/a><\/strong><a href=\"https:\/\/www.hongkiat.com\/blog\/less-css-tutorial-design-slick-menu-nav-bar\/\">, <strong>Mixins<\/strong> and <strong>Operation<\/strong><\/a> in <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/lesscss.org\/\">LESS<\/a>.<\/p>\n<p>We have also mentioned how to convert LESS into <a href=\"https:\/\/www.hongkiat.com\/blog\/css-back-to-basics-terminology-explained\/\">regular CSS<\/a>, with an app or with a compiler. But, how do we do the opposite; to convert CSS into LESS? Well, this tip is for you.<\/p>\n<h2>Using a Tool<\/h2>\n<p>With increasing popularity of <strong>CSS preprocessor<\/strong>, some new tools and apps that essentially aim to makea web designer\u2019s or developer\u2019s life easier, such as this tool: <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/beautifytools.com\/css-to-less-converter.php\">CSS2Less<\/a>.<\/p>\n<p>This tool allows us to convert regular CSS into LESS. So, let\u2019s give it a try. I have the following CSS rules from my old file to be converted.<\/p>\n<pre>nav {\r\n  height: 40px;\r\n  width: 100%;\r\n  background: #000;\r\n  border-bottom: 2px solid #fff;\r\n}\r\n\r\nnav ul {\r\n  padding: 0;\r\n  margin: 0 auto;\r\n}\r\n\r\nnav li {\r\n  display: inline;\r\n  float: left;\r\n}\r\n\r\nnav a {\r\n  color: #fff;\r\n  display: inline-block;\r\n  width: 100px;\r\n  text-shadow: 1px 1px 0px #000;\r\n}\r\n\r\nnav li a {\r\n  border-right: 1px solid #fff;\r\n  box-sizing: border-box;\r\n}\r\n\r\nnav li:last-child a {\r\n  border-right: 0;\r\n}\r\n\r\nnav a:hover,\r\nnav a:active {\r\n  background-color: #fff;\r\n}\r\n<\/pre>\n<p>Here is the result.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/css-to-less\/css-less-result.jpg\" width=\"500\" height=\"300\"><\/figure>\n<pre>nav a:hover,\r\nnav a:active {\r\n  background-color: #fff;\r\n}\r\n\r\nnav {\r\n  height: 40px;\r\n  width: 100%;\r\n  background: #000;\r\n  border-bottom: 2px solid #fff;\r\n}\r\n\r\nnav a {\r\n  color: #fff;\r\n  display: inline-block;\r\n  width: 100px;\r\n  text-shadow: 1px 1px 0px #000;\r\n}\r\n\r\nul {\r\n  padding: 0;\r\n  margin: 0 auto;\r\n}\r\n\r\nli:last-child a {\r\n  border-right: 0;\r\n}\r\n\r\nli {\r\n  display: inline;\r\n  float: left;\r\n}\r\n\r\nli a {\r\n  border-right: 1px solid #fff;\r\n  box-sizing: border-box;\r\n}\r\n<\/pre>\n<p>As we can see above, our old CSS is now nested like in LESS.<\/p>\n<h2>Limitation<\/h2>\n<p>However, we can also see some limitations in the results of the conversion. In the old CSS, we have several same colors, such as in these two declarations <code>border-bottom: 2px solid #fff;<\/code> and <code>border-right: 1px solid #fff;<\/code> we have both borders in white. In LESS we can actually store this constant value in a <strong>Variable<\/strong>.<\/p>\n<p>It also does not nest and separate the <a href=\"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/\"><em>pseudo-*<\/em><\/a> with an ampersand (&) symbol, such as in the following rules <code>li:last-child<\/code> and <code>nav a:hover, nav a:active<\/code>. They just remain as they are, where we can actually simplify the rulesets this way;<\/p>\n<pre>li {\r\n  &:first-child {\r\n    \r\n  }\r\n  a {\r\n    &:hover {\r\n      \r\n    }\r\n    &:active {\r\n      \r\n    }\r\n  }\r\n}\r\n<\/pre>\n<h2>Conclusion<\/h2>\n<p>Despite the limitations it currently still has, this tool can quite helpful in saving our time for nesting CSS rulesets. We only need to do the rest manually; possibly until the the limitations above are <strong>resolved<\/strong>.<\/p>","protected":false},"excerpt":{"rendered":"<p>We have covered much of the basics for LESS in our previous posts. If you have been following our LESS series, we believe that at this point you already have a good idea about how to use the Variables, Mixins and Operation in LESS. We have also mentioned how to convert LESS into regular CSS,&hellip;<\/p>\n","protected":false},"author":113,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3392,352],"tags":[507,1980],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.6) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Convert Old CSS to LESS - Hongkiat<\/title>\n<meta name=\"description\" content=\"We have covered much of the basics for LESS in our previous posts. If you have been following our LESS series, we believe that at this point you already\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/css-to-less\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Convert Old CSS to LESS\" \/>\n<meta property=\"og:description\" content=\"We have covered much of the basics for LESS in our previous posts. If you have been following our LESS series, we believe that at this point you already\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/css-to-less\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2012-10-12T13:01:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-16T11:58:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/assets.hongkiat.com\/uploads\/css-to-less\/css-less-result.jpg\" \/>\n<meta name=\"author\" content=\"Thoriq Firdaus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@tfirdaus\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Thoriq Firdaus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-to-less\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-to-less\\\/\"},\"author\":{\"name\":\"Thoriq Firdaus\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e7948c7a175d211496331e4b6ce55807\"},\"headline\":\"How to Convert Old CSS to LESS\",\"datePublished\":\"2012-10-12T13:01:39+00:00\",\"dateModified\":\"2023-07-16T11:58:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-to-less\\\/\"},\"wordCount\":289,\"commentCount\":8,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-to-less\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/css-to-less\\\/css-less-result.jpg\",\"keywords\":[\"CSS\",\"Less\"],\"articleSection\":[\"Coding\",\"Web Design\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-to-less\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-to-less\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-to-less\\\/\",\"name\":\"How to Convert Old CSS to LESS - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-to-less\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-to-less\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/css-to-less\\\/css-less-result.jpg\",\"datePublished\":\"2012-10-12T13:01:39+00:00\",\"dateModified\":\"2023-07-16T11:58:01+00:00\",\"description\":\"We have covered much of the basics for LESS in our previous posts. If you have been following our LESS series, we believe that at this point you already\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-to-less\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-to-less\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-to-less\\\/#primaryimage\",\"url\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/css-to-less\\\/css-less-result.jpg\",\"contentUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/css-to-less\\\/css-less-result.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-to-less\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Convert Old CSS to LESS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e7948c7a175d211496331e4b6ce55807\",\"name\":\"Thoriq Firdaus\",\"description\":\"Thoriq is a writer for Hongkiat.com with a passion for web design and development. He is the author of Responsive Web Design by Examples, where he covered his best approaches in developing responsive websites quickly with a framework.\",\"sameAs\":[\"https:\\\/\\\/thoriq.com\",\"https:\\\/\\\/x.com\\\/tfirdaus\"],\"jobTitle\":\"Web Developer\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/thoriq\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Convert Old CSS to LESS - Hongkiat","description":"We have covered much of the basics for LESS in our previous posts. If you have been following our LESS series, we believe that at this point you already","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.hongkiat.com\/blog\/css-to-less\/","og_locale":"en_US","og_type":"article","og_title":"How to Convert Old CSS to LESS","og_description":"We have covered much of the basics for LESS in our previous posts. If you have been following our LESS series, we believe that at this point you already","og_url":"https:\/\/www.hongkiat.com\/blog\/css-to-less\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2012-10-12T13:01:39+00:00","article_modified_time":"2023-07-16T11:58:01+00:00","og_image":[{"url":"https:\/\/assets.hongkiat.com\/uploads\/css-to-less\/css-less-result.jpg","type":"","width":"","height":""}],"author":"Thoriq Firdaus","twitter_card":"summary_large_image","twitter_creator":"@tfirdaus","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Thoriq Firdaus","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/css-to-less\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-to-less\/"},"author":{"name":"Thoriq Firdaus","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e7948c7a175d211496331e4b6ce55807"},"headline":"How to Convert Old CSS to LESS","datePublished":"2012-10-12T13:01:39+00:00","dateModified":"2023-07-16T11:58:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-to-less\/"},"wordCount":289,"commentCount":8,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-to-less\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/css-to-less\/css-less-result.jpg","keywords":["CSS","Less"],"articleSection":["Coding","Web Design"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/css-to-less\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/css-to-less\/","url":"https:\/\/www.hongkiat.com\/blog\/css-to-less\/","name":"How to Convert Old CSS to LESS - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-to-less\/#primaryimage"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-to-less\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/css-to-less\/css-less-result.jpg","datePublished":"2012-10-12T13:01:39+00:00","dateModified":"2023-07-16T11:58:01+00:00","description":"We have covered much of the basics for LESS in our previous posts. If you have been following our LESS series, we believe that at this point you already","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-to-less\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/css-to-less\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/css-to-less\/#primaryimage","url":"https:\/\/assets.hongkiat.com\/uploads\/css-to-less\/css-less-result.jpg","contentUrl":"https:\/\/assets.hongkiat.com\/uploads\/css-to-less\/css-less-result.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/css-to-less\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Convert Old CSS to LESS"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e7948c7a175d211496331e4b6ce55807","name":"Thoriq Firdaus","description":"Thoriq is a writer for Hongkiat.com with a passion for web design and development. He is the author of Responsive Web Design by Examples, where he covered his best approaches in developing responsive websites quickly with a framework.","sameAs":["https:\/\/thoriq.com","https:\/\/x.com\/tfirdaus"],"jobTitle":"Web Developer","url":"https:\/\/www.hongkiat.com\/blog\/author\/thoriq\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-3X6","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/15196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/113"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=15196"}],"version-history":[{"count":3,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/15196\/revisions"}],"predecessor-version":[{"id":68223,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/15196\/revisions\/68223"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=15196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=15196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=15196"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=15196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}