css
  1. css-syntax

CSS Syntax

  • CSS (Cascading Style Sheets) is a language used to style a web page.
  • CSS syntax consists of a selector and a declaration block.
  • The selector specifies which HTML element the style should be applied to.
  • The declaration block contains one or more declarations, separated by semicolons.
  • Each declaration consists of a property and a value, separated by a colon.

CSS Selector

The CSS selector is used to select the HTML element that you want to style. There are several types of selectors, including element selectors, class selectors, and ID selectors.

Here are some examples of CSS selectors:

  1. Element Selector: p - selects all <p> elements on the page.
  2. Class Selector: .my-class - selects all elements with the class my-class.
  3. ID Selector: #my-id - selects the element with the ID my-id.

CSS Declaration Block******** The CSS declaration block contains one or more declarations, separated by semicolons.

Each declaration consists of a property and a value, separated by a colon.

Here is an example of a CSS declaration block:

p {
  color: blue;
  font-size: 16px;
}

In this example, the selector is p, which selects all <p> elements on the page.

The declaration block contains two declarations: color and font-size.

The color property sets the text color to blue, and the font-size property sets the font size to 16 pixels.

Published on: