CSS is the language we use to style a Web page.
Cascading Style Sheets, fondly referred to as CSS, is a simply designed language intended to simplify the
process of making web pages presentable. CSS allows you to apply styles to web pages. More importantly, CSS
enables you to do this independently of the HTML that makes up each web page. It describes how a webpage
should look: it prescribes colours, fonts, spacing, and much more. In short, you can make your website look
however you want. CSS lets developers and designers define how it behaves, including how elements are
positioned in the browser.
While HTML uses tags, CSS uses rulesets. CSS is easy to learn and understand, but it provides powerful
control over the presentation of an HTML document.
CSS comprises style rules that are interpreted by the browser and then applied to the corresponding elements in your document. A style rule set consists of a selector and declaration block.
A CSS selector selects the HTML element(s) for styling purposes. CSS selectors select HTML elements according
to their id, class, type, attribute, etc.
CSS selectors: There are many basic different types of selectors.
The element selector selects HTML elements based on the element name (or tag) for example p, h1, div, span, etc.
style.css: The following code is used in the above Example. You can see the CSS rules applied to all p tags and h1 tags.
h1 {
color: red;
font-size: 3rem;
}
p {
color: white;
background-color: gray;
}
The id selector uses the id attribute of an HTML element to select a specific element.
Note: An id of the element is unique on a page to use the id selector.
style.css: The following code is used in the above Example using the id selector.
The class selector selects HTML elements with a specific class attribute.
style.css: The following code is used in the above Example using the class selector. To use a class selector
you must use ( . ) followed by class name in CSS. This rule will be applied to the HTML element with the
class attribute “paragraph-class“
The Universal selector (*) in CSS is used to select all the elements in an HTML document. It also includes
other elements which are inside under another element.
style.css: The following code is used in the above Example using the universal selector. This CSS rule will
be applied to each and every HTML element on the page:
This selector is used to style all comma-separated elements with the same style.
style.css: The following code is used in the above Example using the group selector. Suppose you want to
apply common styles to different selectors, instead of writing rules separately you can write them in groups
as shown below.