question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating freeCodeCamp's CSS Style guide

See original GitHub issue

I would like to propose freeCodeCamp’s CSS Style guide to improve overall maintainability of the codebase. As the FreeCodeCamp has a lot of contributors, and everyone writes the CSS in a different way. And it is hard to keep of track of different ways of writing CSS.

Initial Recommendations:

Comments

  • Add comments, when you are starting a new LESS file, so the developers know what are they working with, also add comments when you start new section which is related the code block, it helps with the readability, see EXAMPLES below (I have encountered these style of comments across the code base, therefore I would like to continue writing it, instead of proposing a new style)

  • Example 1 - when starting a new LESS file:

//
// Navigation
// --------------------
  • Example 2 - when adding a section, related to navigation
//
// Navigation - Mobile Styles
// ------------------------------

Spacings

  • Add spaces after a property, it will be much easier to read such a codebase, and maintain. See EXAMPLES below.

  • Example 1 - Correct Way

p {
  color: #fff;
}
  • Example 2 - Incorrect Way
  • What is wrong? No space after a colon
p {
  color:#fff;
}

Colors

  • Prefer lowercase, instead of uppercase. Now across the CSS, contributors are mixing both. Lower case is faster to write, easier to read. Again improves overall maintainability, if the CSS has consistent convention. Also if possible shorten the hex value. See EXAMPLES below.

  • Example 1 - Correct Way

p {
  color: #fff;
}
  • Example 2 - Incorrect Way
  • What is wrong? upper-cased hex value, not shortened
p {
  color: #FFFFFF;
}

RGBA or RGB colors

  • Add spaces after values, improves readability. See EXAMPLES below:

  • EXAMPLE 1 - Correct Way

p {
  color: rgba(123, 123, 0, 0.1);
}
  • EXAMPLE 2 - Incorrect Way
  • What is wrong? No spaces after values
p {
  color: rgba(123,123,0,0.1);
}

##No unit when declaring 0

  • In property such as box-shadow, if you set a 0 value, then you should avoid adding the unit. See EXAMPLE below.

  • EXAMPLE 1 - Correct Way

p {
  box-shadow: 1px 1px 0 rgb(0, 0, 0);
}
  • EXAMPLE 2 - Incorrect Way
  • What is wrong? Units after 0
p {
  box-shadow: 1px 1px 0px rgb(0, 0, 0);
}

Avoid floating numbers

  • If possible you should avoid floating numbers in CSS for different sizing, as it could render a bit differently. See link attached below.

Browser Rounding

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:49 (25 by maintainers)

github_iconTop GitHub Comments

6reactions
vkWebcommented, Jan 8, 2018

@raisedadead @tomasvn According to me the process of creating a CSS style guide and sticking to it will in long-term not yield useful results. React, Yarn, Babel and lots of other open source projects use Prettier and other similar extensions for their CSS Style formatting.

Instead of creating a style guide. We should tell our contributors to Install Prettier In their IDE/Code editor and we’ll be good to go. @raisedadead Thoughts on this?

2reactions
ojeytonwilliamscommented, Oct 15, 2020

I think prettier does a good job with formatting, so I’d rather keep that. If we use https://github.com/prettier/stylelint-prettier then prettier is used as a plugin of stylelint and we get the best of both worlds.

This mirrors the approach we already use for JavaScript linting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The CSS Handbook: A Handy Guide to CSS for Developers
This article will help you get up to speed with CSS and get an overview of the main modern features you can use...
Read more >
Style Guide - freeCodeCamp.org
#STYLE GUIDE · A collection of 3 posts · How to Create a Style Guide in Figma · Inline CSS Guide – How...
Read more >
freeCodeCamp - Style Guide
Learn to code and build projects for nonprofits. Build your full stack web development portfolio today.
Read more >
Learn CSS – Responsive Web Design Study Guide
In this article, I have created a study guide for the freeCodeCamp curriculum's entire Learn Basic CSS by Building a Cafe Menu practice...
Read more >
CSS - freeCodeCamp.org
Our mission: to help people learn to code for free. We accomplish this by creating thousands of videos, articles, and interactive coding lessons...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found