• Tutorials Logic, IN
  • +91 8092939553
  • info@tutorialslogic.com

CSS Syntax and Selectors

Syntax

A CSS rule consists of selector and a declaration block, which are interpreted by the browser and applied to the target elements in the HTML document.

										    
											selector { property-1: value; property-2: value;.......property-n: value }
											
										
										    
											h1 { color: blue; text-align: center; }
											
										

Selectors

Selectors are one of the most important concept in CSS. Selectors are used to find or select or target HTML elements to apply CSS styles. There are various ways to define a selector, which include following-

The universal Selector:- The universal selector is used to select or target each and every element in a HTML document together. It is written as * i.e. asterisk or star symbol.

										    
											* { margin: 0; padding: 0; }
											
										

The element Selector:- The element selector is used to select a element based on the element name.

										    
											h1 { text-align: center; color: green; }
											
										

The class Selector:- The class selector is used to select a element based on the class attribute of that element.

										    
											.class_name { text-align: center; color: green; }
											
										

The id Selector:- The class selector is used to select a element based on the id attribute of that element.

										    
											#id_name { text-align: center; color: green; }