What is
Code should be easy to read, easy to understand and easy to change. We achieve that by writing clean code. Here are some of the principles to follow.
When using CSS class names, use kebab-case. See this blog post for a bit more explanation on what kebab case mean, but in a nutshell, kebab case means all lower case with hyphens - between each word. You should also try to make the class name as descriptive as possible.
.blueBox {}
.x {}
.user-login-form {}
. calculator-result
โDon't repeat yourselfโ (often referred to as DRY) means abstracting your code to make it more reusable. For example, if you have a bunch of <p> tags in your HTML which you want to look the same, you should aim to write just 1 CSS selector which targets all of them instead of copying and pasting your CSS properties across a lot of selectors.
With CSS you should always aim to make your classes as generic and reusable as possible.
<div>
<h1>Hello world</h1>
<p class="paragraph-1">An important message</p>
<p class="paragraph-2">Another important message</p>
<p>I shouldn't be red because this isn't important</p>
</div>
.paragraph-1 {
color: red;
}
.paragraph-2 {
color: red;
}
<div>
<h1>Hello world</h1>
<p class="important-text">An important message</p>
<p class="important-text">Another important message</p>
<p>I shouldn't be red because this isn't important</p>
</div>
.important-text {
color: red;
}
When writing code, you might copy and paste examples from other files or solutions you've found online. This can often lead to your code having weird indentation and weird spacing between your blocks of code.
The rule to follow here is that if there's a new block, then you indent one more level. At Technigo, we use 2 spaces for indentation.
<div><h1>Hello world</h1>
<p class = "important-text">An important message
</p>
<p class="important-text"> Another important message</p>
<p>I shouldn't be red because this isn't important</p>
</div>
.important-text{
color:red;
background: pink;
}
.header { background: blue;}
<div>
<h1>Hello world</h1>
<p class="important-text">An important message</p>
<p class="important-text">Another important message</p>
<p>I shouldn't be red because this isn't important</p>
</div>
.important-text {
color: red;
background: pink;
}
.header {
background: blue;
}
We're a female-founded, remote-first community helping people get a career they love. 90% of those attending our boot camps are women.