Heapcoding

Which of the Following Ways Below is Correct to Write a CSS?

Published February 3, 2021

Which of the following ways below is correct to write a CSS?

Options
1. p { background-color: red; }
2. p {background-color red; }
3. p {background-color: red};
4. p background-color: red
Correct answer is option 1. p { background-color: red; }

There are many ways to writing CSS language. But you need to write with the correct syntax. So that your style could be applied correctly and you cannot miss any of the styles. Which couldn’t be applied by your syntax errors.

Here is the right syntax to writing CSS in your code.

p { background-color: red; }

In the above line you will see some code of CSS. Which is the background-color property which is applied to a paragraph.

The first letter “p” is the tag on which you are applying the style and then in curly braces you need to write your styling properties and their values.

The “background-color” is the property and “red” is the value of the property.

The rule to writing the property in CSS is that you need to write property like in our example “background-color” and separate by colon : and then write the value of the property, like “red” in our property value.

And don’t forget to add semicolon ; at the end of the property. Because it ends the property line. So that you could write the next property below or next to that property.