CSS Cheat Sheet A Basic Guide to CSS (original) (raw)

Last Updated : 19 Dec, 2025

CSS (Cascading Style Sheets) is a styling language used to control the presentation of documents written in HTML, XML, and similar markup languages. It defines how elements appear on screen or in other media, enhancing the overall look and user experience of a webpage.

Webpage-With---without-CSS

CSS Basics

Cascading Style Sheet(CSS) is used to set the style in web pages that contain HTML elements, here we will see in how many ways we can add CSS for our HTML, there three different ways to do so one by one we will see those procedure.

**External CSS: External CSS contains a separate CSS file with a .css extension which contains only style property with the help of tag attributes.

selector{
property1: value1;
property2: value2;
}

**Include external CSS file: The external CSS file is linked to the HTML document using a link tag.

**Internal CSS or Embedded: Internal CSS is embedded within the HTML file using a style HTML tag.

**Inline CSS: The inline CSS contains CSS properties in the body section specified within HTML tags.

**Clearfix: It clears floats to select or control margins and padding.

.clearfix::after {
content: "";
clear: both;
display: block;
}

Selectors

CSS selectors are used to find or select the HTML elements you want to style.

css_selectors

These are categorized as follows:

* Selectors

*(Universal) Selector here gives a pink background


This span is styled using type selector.

This div is styled using id selector

This div is styled using class selector

This div is styled using attribute selector

This div is styled using combinators

child selector


pseudo selector:

My color changes if you hover over me!

`

**Output:

Screenshot-2025-12-15-124502

Font Properties

CSS font properties are used to set the font's content of the HTML element as per requirement.

Font properties

Normal text aligned center sized 10 px

Geeks for Geeks

Italic text aligned left sized 15px

Geeks for geeks

Oblique text aligned right sized 20px, in small caps

Geeks for geeks

`

**Output:

Screenshot-2025-12-15-124709

Text-properties

CSS text formatting properties are used to format and style text by setting their color, alignment, spacing, etc. as per requirement.

Text formatting properties
Color property used here

Text align property used here

Text decoration property used here

Text transform property used here

Text indent property used here

Text line spacing property used here

Text line height property used here

Text shadow property used here

Text word spacing property used here

`

**Output:

Screenshot-2025-12-15-124827

Background properties

The CSS background properties are used to design the background and define the background effects for elements.

Background Properties
Background color property

Background Image property



Background repeat property: no-repeat



Background position property



Background origin property: The background-origin is a property used to set the origin of the image in the background.



Background-attachment property

The property background-attachment property in CSS is used to specify the kind of attachment of the background image It can be set to scroll or remain fixed.


`

Box Properties

The CSS box model is essentially a box that wraps around every HTML element consisting of the border, padding, margin, and content.

Screenshot-2024-12-10-105714

The CSS properties used to attain the box model are:

CSS Box Model
GeeksforGeeks
Linear Gradient

GeeksforGeeks
Radial Gradient

`

**Output:

Screenshot-2025-12-15-130051

Border Properties

The CSS border properties allow you to specify how the border of the box representing an element should look.

Border Properties
Demonstration of solid thick border of color blue


Demonstration of dotted 2px width border of color green

`

Classification Properties

The CSS classification properties allow you to specify how and where an element is displayed.

Classification properties
<p>attribute function</p>
<a href="https://www.geeksforgeeks.org/">GeeksforGeeks</a><br><br>
<p>Calc function</p>
<div class="geeks">
    <h3>The calc() Function</h3>
</div><br><br>

<p>URL function</p>
<div class="url" style="height:200px; width:100%">
    <h3>CSS url() function</h3>
</div><br>
<p> var function</p>
<div class="gfg1">demonstration of var function</div><br>

`

The CSS Media Query is used to make the web page more responsive according to the different screens or media types. Media queries include a block of CSS only if a certain expression is true.

**Syntax:

@media not | only mediatype and (expression) {
// Code content