1. Home
  2. /
  3. CSS Tutorial
  4. /
  5. Which is the Correct CSS Syntax?

Which is the Correct CSS Syntax?

If you want to use CSS on a web page, then you need to know complete information about the Syntax of CSS. Like what is it, what is the method of use, with what elements it is used, etc?

If you do not know anything about CSS then read our previous article “What is CSS”. In fact, CSS is a StyleSheets language that allows you to easily design a document made of HTML or XML markup. First of all, let me give you a brief definition of syntax.

What is Syntax in CSS?

The syntax is a rule of CSS style that defines the structure of a language. Without rules, it is impossible to write functional code. So programming code is written according to the syntax which makes it easy to write programs. Having understood what the syntax is, then let’s understand the syntax of CSS very well. and how to use it.

What is Syntax in CSS?
What is Syntax in CSS?

We use CSS selector, declaration, property name, and value to style HTML elements, and colon and semicolon are used to separate CSS properties.

The syntax of CSS is something like this:

p { color: red; text-align: center; }
  • The CSS Selector indicates the HTML element you want to style.
  • A declaration block can contain one or more declarations and a semicolon (;) is used to separate it.
  • Each declaration consists of a CSS property name and its value, separated by a colon (:).

Note: You can use multiple CSS selectors, declarations, and properties if you want.

Example of CSS Syntax

In this CSS syntax example, all <p> and <h1> elements will be center-aligned, with paragraph text colored purple and h1 red:

Correct CSS Syntax

/* USING HTML TAG */ 

p{
  color:red;
  Font-size: 18px;
}


/* USING HTML ATTRIBUTE ID */

#id{
  color:red;
  Font-size: 18px;
}


/* USING HTML CLASS */

.class{
  color:red;
  Font-size: 18px;
}

How to use CSS in HTML?

In an HTML document, you have three ways to apply CSS:

  • Inline CSS.
  • Internal or Embedded CSS.
  • External CSS.

With all these three types, you can easily use CSS and give a good design to the web page.If you want to learn complete CSS then you can learn from here “Complete CSS Tutorial”. If you want to learn HTML, then you can learn from here “Complete HTML Tutorial in Hindi”.

Conclusion-

Teach in this article that we need Syntax to use CSS. Without this, it is difficult to CSS style an HTML document. Therefore, CSS code is written according to the syntax, which makes it easier to write programs. I hope this article “Syntax of CSS in Hindi – What is the Syntax of CSS and How to Use CSS” has helped you to understand the CSS syntax.

If you understand CSS syntax then answer this question:

Which is the correct CSS syntax?

{body:color=white;}

{body;backgroud-color:white;}

body:backgroud color=white;

body { background-color: white;

Also Read:

Leave a Reply

Your email address will not be published.