A CSS3 syntax is a collection of selectors and a declaration block. A selector is used to point to the HTML Element for applying CSS properties and the declaration block that may contain one or more declarations separated by semicolons. Each block contains CSS rules separated by a colon.
{
property1: value1;
property2: value2
}
CSS3 Selectors are used to select the HTML elements for styling.
<head>
<style>
h1{
color:red
}
.tdb-class{
color:blue
}
#tdb-id{
color:green
}
</style>
</head>
<body>
<h1>Element Selector
</h1>
<h1 class="tdb-class">Class Selector
</h1>
<h1 id="tdb-id">Id Selector
</h1>
</body>
Note: Always use a unique id because it will affect your web page performance.
When you want to use the same style on different elements without repeating the CSS properties in your style sheet then you can use a comma to separate multiple selectors..
Here is a simple example of multiple selectors
<style>
h1, h2{color:red}
</style>
So the red color applies to all h1 and h2 tags available on the web page. Click on the Try it Yourself button to Run the code
<head>
<style>
h1, h2{color:red
}
</style>
</head>
<body>
<h1>h1 tag
</h1>
<h2>h2 tag
</h2>
</body>
A CSS rule consists of a selector and declaration block {}
<style>
selector{
property: value;
property: value
}
</style>
This is the syntax we use for styling the HTML Elements.