CSS Syntax

CSS syntax consists of a set of rules that are applied to HTML elements. Each rule has two main parts: selectors and declarations.

Syntax:

selector { Property: value; }

Components of CSS Syntax:

  1. Selector: Targets the HTML element(s) to be styled. Examples include elements (h1, p), classes (.classname), and IDs (#idname).
  2. Declaration Block: Contains one or more declarations inside curly braces {}. Each declaration consists of:
  • Property: The aspect of the element to be styled (e.g., color, font-size).
  • Value: The value applied to the property (e.g., blue, 16px).


Example
/* Styling an h1 element */
h1 {
color: blue; /* Property: color, Value: blue */
font-size: 24px; /* Property: font-size, Value: 24px */
}

/* Styling a class (.container) */
.container {
width: 200px; /* Property: width, Value: 200px */
}

/* Styling an ID (#header) */
#header {
background-color: gray; /* Property: background-color, Value: gray */
padding: 10px; /* Property: padding, Value: 10px */
}

Try it yourself


Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.