css cheat sheet, css syntax reference, css selectors list, css flexbox guide, css grid layout, css colors and typography, css positioning examples, css border and background, css animation and transition, css box model
css cheat sheet, css syntax reference, css selectors list, css flexbox guide, css grid layout, css colors and typography, css positioning examples, css border and background, css animation and transition, css box model

CSS Cheat Sheet — Complete CSS3 Selectors, Properties, and Layout Examples

CSS Cheat Sheet — Complete CSS3 Syntax, Selectors & Layout Examples

Cascading Style Sheets (CSS) is the language used to style HTML — controlling layout, colors, typography, and overall design. This CSS Cheat Sheet provides all essential CSS properties, examples, and modern layout techniques like Flexbox and Grid for quick reference and learning.


What is CSS?

CSS (Cascading Style Sheets) defines how HTML elements are displayed on screen, paper, or other media. It separates content (HTML) from presentation (CSS), improving flexibility and maintainability.

Example:

<!DOCTYPE html>
<html>
<head>
<style>
h1 {
  color: blue;
  text-align: center;
}
p {
  font-size: 18px;
}
</style>
</head>
<body>
<h1>Hello CSS!</h1>
<p>This paragraph is styled using CSS.</p>
</body>
</html>

CSS Syntax

CSS consists of a selector and a declaration block.

selector {
  property: value;
}

Example:

p {
  color: red;
  font-size: 16px;
}

CSS Selectors

Selectors target HTML elements for styling.

Selector TypeExampleDescription
Element SelectorpSelects all <p> tags
Class Selector.boxSelects elements with class “box”
ID Selector#headerSelects element with id “header”
Universal Selector*Selects all elements
Group Selectorh1, h2, h3Groups multiple selectors
Descendant Selectordiv pSelects <p> inside <div>
Child Selectordiv > pSelects direct child elements
Attribute Selectorinput[type="text"]Selects elements with specific attribute
Pseudo-Classa:hoverStyles on hover
Pseudo-Elementp::first-lineStyles first line of paragraph

CSS Colors and Backgrounds

PropertyExampleDescription
colorcolor: blue;Text color
background-colorbackground-color: #f0f0f0;Background color
background-imagebackground-image: url("bg.jpg");Sets background image
background-sizebackground-size: cover;Adjusts image size
opacityopacity: 0.8;Sets transparency

Example:

body {
  background: linear-gradient(to right, #00c6ff, #0072ff);
  color: white;
}

CSS Box Model

Every element in CSS is a box made up of content, padding, border, and margin.

PropertyExampleDescription
width, heightwidth: 100px;Element dimensions
paddingpadding: 10px;Inner spacing
borderborder: 1px solid #000;Border around element
marginmargin: 15px;Outer spacing
box-sizingbox-sizing: border-box;Includes padding and border in total width

Example:

div {
  width: 200px;
  padding: 10px;
  border: 2px solid gray;
  margin: 15px;
  box-sizing: border-box;
}

CSS Typography

PropertyExampleDescription
font-familyfont-family: Arial, sans-serif;Sets font
font-sizefont-size: 18px;Sets size
font-weightfont-weight: bold;Bold text
text-aligntext-align: center;Aligns text
line-heightline-height: 1.5;Sets line spacing
text-transformtext-transform: uppercase;Changes text case
letter-spacingletter-spacing: 2px;Space between letters
css cheat sheet, css syntax reference, css selectors list, css flexbox guide, css grid layout, css colors and typography, css positioning examples, css border and background, css animation and transition, css box model

CSS Borders, Margin, and Padding

PropertyExampleDescription
borderborder: 1px solid black;Adds border
border-radiusborder-radius: 10px;Rounds corners
marginmargin: 20px;Outer spacing
paddingpadding: 15px;Inner spacing

CSS Display and Positioning

PropertyExampleDescription
displaydisplay: block;Defines element display
positionposition: absolute;Positions element
top, left, right, bottomtop: 10px;Set position offsets
z-indexz-index: 10;Layer order
floatfloat: right;Floating element
clearclear: both;Control float behavior

Example:

.box {
  position: relative;
  top: 20px;
  left: 30px;
}

CSS Flexbox Layout

Flexbox simplifies alignment, spacing, and layout control.

Example:

.container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
PropertyDescription
display: flexEnables flexbox
flex-directionDefines row or column layout
justify-contentHorizontal alignment
align-itemsVertical alignment
flex-wrapWrap items
align-contentAlign multiple lines

CSS Grid Layout

CSS Grid allows two-dimensional layouts.

Example:

.grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
PropertyDescription
display: gridEnables grid
grid-template-columnsDefines columns
grid-template-rowsDefines rows
gapSpace between grid items
justify-itemsHorizontal alignment
align-itemsVertical alignment

CSS Animation and Transition

PropertyExampleDescription
transitiontransition: 0.3s ease;Smooth change
animation-nameanimation-name: fade;Animation name
animation-durationanimation-duration: 2s;Animation time

Example:

@keyframes fade {
  from {opacity: 0;}
  to {opacity: 1;}
}
.box {
  animation: fade 2s ease-in-out;
}

CSS Units and Measurements

UnitDescriptionExample
pxPixelswidth: 200px;
%Percentagewidth: 50%;
emRelative to parent font sizemargin: 2em;
remRelative to root font sizefont-size: 1.5rem;
vh, vwViewport height/widthheight: 100vh;

Internal Resources


FAQ – CSS Cheat Sheet

Q1: What is CSS used for?
CSS styles HTML elements, controlling layout, colors, and typography for beautiful web design.

Q2: What is the difference between inline, internal, and external CSS?

  • Inline CSS: inside HTML tags
  • Internal CSS: inside <style> in <head>
  • External CSS: linked .css file

Q3: What are Flexbox and Grid used for?
Flexbox handles one-dimensional layouts, while Grid is for complex two-dimensional layouts.

Q4: How can I center an element in CSS?
Using Flexbox:

display: flex;
justify-content: center;
align-items: center;

Q5: How to make a responsive layout?
Use media queries:

@media (max-width: 600px) {
  body { font-size: 14px; }
}
Related Article
CSS Tutorial

CSS is the language we use to add style to an HTML document. CSS tells how HTML elements should look Read more

Color Picker

Color Picker tool Color Picker is a tool that helps designers and artists to choose the right color for their Read more

 Most Common CSS Interview Questions and Answer

CSS questions with examples cover almost all of the basic and advanced CSS categories. CSS is one of the most Read more

CSS Introduction

CSS: The Art of Styling Web Pages Cascading Style Sheets (CSS) is a powerful language that allows you to control Read more

Creating a Curved Bottom Shape for a Div Using CSS

Creating a Curved Bottom Shape for a Div Using CSS Adding a curved bottom shape to a div element can Read more

Why is Marquee in HTML and CSS Context Named That Way?

In the world of web development, the term "marquee" refers to a text element that scrolls continuously across the screen. Read more

Machine Learning Cheatsheet (Unsupervised & Reinforcement Learning)

Machine Learning (ML) is a crucial part of artificial intelligence, enabling systems to automatically learn from data.This Machine Learning Cheatsheet Read more

HTML Cheat Sheet — Reference Guide to HTML Tags, Attributes, and Examples

HTML cheat sheet, HTML tags reference, HTML attributes list, HTML examples for beginners, semantic HTML guide, HTML forms tutorial, HTML Read more

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments