C4f34e76 516f 40f8 82d6 2961fd41aa79

CSS Syntax

A CSS declaration always ends with a semicolon, and declaration blocks are surrounded by curly braces. The declaration block contains one or more declarations separated by semicolons. Each declaration includes a CSS property name and a value, separated by a colon.

1. Selector  –  A selector is an HTML tag at which a style will be applied. This could be any tag like <h1> or <p> etc.

2. Property  –  A property is a type of attribute of HTML tag. Put simply, all the HTML attributes are converted into CSS properties. They could be color, border etc.

3. Value  –  Values are assigned to properties. For example, color property can have value either green or #FFFFFF etc.

Example

h3 {
color: green;
letter-spacing: 2px;
text-align: center;
}

 

CSS Selector

CSS selectors are used to find or select HTML elements based on their element name, id, class, attribute, and more.

Element Selector

The element selector selects elements based on the element name.

Example

p {
         color: red;
         letter-spacing: 2px;
         text-align:center;
}

 

Id Selector

The id selector uses the id attribute of an HTML element to select a specific element. The id of an element should be unique within a page, so the id selector is used to select one unique element. To select an element with a specific id, write a hash (#) character,

Example

#google {
         color: red;
         letter-spacing: 2px;
         text-align:center;
}

 

Class Selector

The class selector selects elements with a specific class attribute.

To select elements with a specific class, write a period (.) character.

Example

.google {
         color: red;
         letter-spacing: 2px;
         text-align:center;
}


Scroll to Top