CSS syntax

Defining a style in CSS that sets the appearance of an element on a web page is just a rule that tells the browser what to format and how it will be formatted, such as changing the color of the title text, highlighting the image a red frame, a fixed width for a menu of 200 pixels, etc.

CSS rules

CSS is a rule or set of rules that describe the formatting (change of appearance) of individual elements on a web page. The rule consists of two parts: the selector and the next declaration block. The image below shows the structure (syntax) of the rule:

CSS syntax

General formatting rules

The browser ignores most of the whitespace in the CSS code, so they can be used to your advantage, by giving your code a readable look. Whitespace symbols include: tab characters, line wrapping, and normal spaces, which can be used in any number. Whitespace characters can be placed between the selector and the declaration block, in the declaration block itself - between the curly bracket and the property, between the properties, the property and the value.

The example shows CSS code that uses whitespace characters:

p {
  color: blue;
  text-align: justify;

Whitespace characters are mostly used when a rule specifies many properties to make it easier to read and imagine what exactly this style does. The code of the previous example can be written in one line without using whitespace, but this code will be less convenient for reading and understanding:


This is the way to write rules when you use just one or two properties so that you do not break the code into multiple rows and thus not increase the size of the code.

Copying materials from this site is possible only with the permission of the site administration and
when you specify a direct active link to the source.
2011 - 2021 © puzzleweb.ru

puzinfo@puzzleweb.ru | ruen